Skip to content

About

Technical challenge to Globo company.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

15 Commits

Folders and files

Repository files navigation

Globo Test - Video Feedback Platform

A GraphQL-based backend API for managing videos and user feedback, built with Node.js, TypeScript, and MongoDB.

πŸš€ Features

  • Video Management: Create and fetch videos with metadata
  • Feedback System: Users can rate and comment on videos
  • GraphQL API: Modern, type-safe API with Apollo Server
  • MongoDB Integration: Scalable document-based data storage
  • Docker Support: Containerized deployment with Docker Compose
  • TypeScript: Full type safety and modern JavaScript features

πŸ—οΈ Architecture & Technical Decisions

Project Structure

src/
β”œβ”€β”€ app.ts                          # Express app configuration
β”œβ”€β”€ server.ts                       # Server entry point
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ database/mongo/             # MongoDB configuration
β”‚   β”‚   β”œβ”€β”€ index.ts               # Database connection
β”‚   β”‚   └── schema/                # Mongoose schemas
β”‚   β”‚       β”œβ”€β”€ feedback.ts
β”‚   β”‚       └── video.ts
β”‚   β”œβ”€β”€ env/                       # Environment configuration
β”‚   β”‚   └── index.ts
β”‚   β”œβ”€β”€ graphql/                   # GraphQL configuration
β”‚   β”‚   β”œβ”€β”€ index.ts              # Apollo Server setup
β”‚   β”‚   β”œβ”€β”€ schema-loader.ts      # Schema loading
β”‚   β”‚   β”œβ”€β”€ query.graphql         # Query definitions
β”‚   β”‚   β”œβ”€β”€ mutation.graphql      # Mutation definitions
β”‚   β”‚   β”œβ”€β”€ video.graphql         # Video type definitions
β”‚   β”‚   └── feedback.graphql      # Feedback type definitions
β”‚   └── repositories/              # Data access layer
β”‚       β”œβ”€β”€ feedback.interface.ts
β”‚       β”œβ”€β”€ feedback.repository.ts
β”‚       β”œβ”€β”€ videos.interface.ts
β”‚       └── videos.repository.ts
β”œβ”€β”€ dto/                          # Data Transfer Objects
β”‚   β”œβ”€β”€ create-feedback.dto.ts
β”‚   β”œβ”€β”€ fetch-videos.dto.ts
β”‚   └── fetch-feedback-by-video-id.dto.ts
β”œβ”€β”€ models/                       # Mongoose models
β”‚   β”œβ”€β”€ feedback.ts
β”‚   └── video.ts
β”œβ”€β”€ resolvers/                    # GraphQL resolvers
β”‚   β”œβ”€β”€ create-feedback.resolver.ts
β”‚   └── fetch-videos.resolver.ts
└── services/                     # Business logic layer
    β”œβ”€β”€ create-feedback.service.ts
    β”œβ”€β”€ fetch-videos.service.ts
    └── fetch-feedback-by-video-id.service.ts

Architectural Decisions

Layered Architecture

  • Why: Clear separation of concerns for maintainability and testability
  • Implementation: Three distinct layers - Presentation (resolvers), Business Logic (services), Data Access (repositories)
  • Benefits: Easy to test individual layers, swap implementations, and scale

Schema-First GraphQL Approach

  • Why: Define API contract first, then implement resolvers
  • Implementation: Separate .graphql files for types, queries, and mutations
  • Benefits: Self-documenting API, better client-server contract, easier frontend development

Repository Pattern

  • Why: Abstracts data access logic from business logic
  • Implementation: Interface + implementation for each entity
  • Benefits: Easy to swap data sources, testable, follows SOLID principles

Service Layer Architecture

  • Why: Encapsulates business logic separately from data access
  • Implementation: Services orchestrate repositories and transform data using DTOs
  • Benefits: Reusable business logic, easier unit testing, single responsibility

DTO (Data Transfer Object) Pattern

  • Why: Type-safe data contracts between layers
  • Implementation: Separate DTOs for requests/responses, transforming DB models to API responses
  • Benefits: Prevents data leakage, ensures API stability, clear data contracts

Technology Choices & Reasoning

Node.js 22

  • Why: Latest LTS with improved V8 performance and ES modules support
  • Benefits: Better memory management, faster startup, modern JavaScript features
  • Decision: Chosen for performance and ecosystem maturity

TypeScript

  • Why: Type safety and better developer experience
  • Configuration: Strict mode with path mapping (~/* aliases)
  • Benefits: Catch errors at compile time, better IntelliSense, self-documenting code

GraphQL over REST

  • Why: Single endpoint, type-safe queries, efficient data fetching
  • Implementation: Apollo Server with schema-first approach
  • Benefits: Clients request only needed data, reduces over-fetching, built-in documentation

MongoDB with Mongoose

  • Why: Document-based storage fits GraphQL's flexible nature
  • Implementation: Mongoose ODM for type safety and validation
  • Benefits: Schema evolution, horizontal scaling, native JSON support

Express.js

  • Why: Minimal, unopinionated framework
  • Benefits: Lightweight, flexible, large ecosystem
  • Decision: Simple setup for GraphQL integration

Zod for Validation

  • Why: Runtime type validation and schema parsing
  • Benefits: Type-safe validation, better error messages, schema inference
  • Decision: Chosen over Joi for TypeScript integration

Biome over ESLint + Prettier

  • Why: Single tool for linting and formatting
  • Benefits: Faster execution, simpler configuration, unified rules
  • Decision: Modern alternative with better performance

Docker & Docker Compose

  • Why: Consistent development and deployment environment
  • Benefits: Easy setup, reproducible builds, production parity
  • Decision: Standard containerization approach

πŸ› οΈ Tech Stack

  • Runtime: Node.js 22
  • Language: TypeScript
  • Framework: Express.js
  • API: GraphQL with Apollo Server
  • Database: MongoDB with Mongoose ODM
  • Validation: Zod
  • Linting: Biome
  • Containerization: Docker & Docker Compose

πŸ“‹ Prerequisites

  • Node.js 22+
  • MongoDB (or Docker)
  • npm or yarn

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/dev-mariana/globo-test
cd globo-test

2. Install Dependencies

npm install

3. Environment Setup

Create a .env file in the root directory:

NODE_ENV=
MONGODB_URI=
PORT=

4. Start MongoDB (Docker)

docker-compose up -d

5. Run the Application

Development Mode

npm run dev

Production Mode

npm run build
npm start

The server will start on http://localhost:8080

πŸ“š API Documentation

GraphQL Playground

Visit http://localhost:8080/graphql to access the GraphQL Playground for interactive API exploration.

Available Operations

Queries

# Fetch all videos
query GetVideos {
  videos {
    id
    title
    url
    feedbacks {
      id
    }
  }
}

# Fetch feedback for a specific video
query GetFeedbackByVideo($videoId: ID!) {
  feedbackByVideo(videoId: $videoId) {
    id
    rating
    comment
    user
    video {
      id
    }
  }
}

Mutations

# Create feedback for a video
mutation CreateFeedback($input: FeedbackInput!) {
  createFeedback(input: $input) {
    id
    rating
    comment
    user
    video {
      id
    }
  }
}

Data Types

Video

  • id: ID! - Unique identifier
  • title: String! - Video title
  • url: String! - Video URL
  • feedbacks: [Feedback!] - Associated feedback

Feedback

  • id: ID! - Unique identifier
  • rating: Int! - Rating (1-5)
  • comment: String! - User comment
  • user: String! - Username
  • video: Video! - Associated video

πŸ§ͺ Development

Available Scripts

  • npm run dev - Start development server with hot reload
  • npm run build - Build for production
  • npm start - Start production server
  • npm run lint - Run Biome linter

Code Quality

This project uses Biome for linting and formatting:

npm run lint

πŸ”§ Configuration

Environment Variables

Variable Description Default
NODE_ENV Environment mode development
MONGODB_URI MongoDB connection string Required
PORT Server port 3000

Database Schema

Videos Collection

{
  _id: ObjectId,
  title: string,
  url: string,
  feedbacks: ObjectId[]
}

Feedback Collection

{
  _id: ObjectId,
  rating: number,
  comment: string,
  user: string,
  video: ObjectId
}

πŸ“ License

MIT

πŸ‘¨β€πŸ’» Author

Mariana Bastos


πŸš€ Quick Start Example

# 1. Start the database
docker-compose up -d

# 2. Install dependencies
npm install

# 3. Start the server
npm run dev

# 4. Open GraphQL Playground
open http://localhost:8080/graphql

The API will be ready to accept GraphQL queries and mutations!

About

Technical challenge to Globo company.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages