# kc1t/desafio-verzel architecture

> Architecture diagram of the GitHub repository kc1t/desafio-verzel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kc1t/desafio-verzel
- Repository: https://github.com/kc1t/desafio-verzel

## Overview

##### Main Components
- Frontend Application: Represent the “screenli-cli” portion built with Next.js. Indicate pages such as login, registration, lists (create, view, and update), and movie details. Also include the use of components (e.g., Navbar, Footer, various UI components) and hooks for state management.
- Backend API: Represent the “screenli-api” portion implemented in Node.js. Break it down into sub-components as follows:
– Server Initialization: The entry point (server.ts and app.ts) where the server is configured.
– Configuration Layer: Show how configuration files (apiConfig.ts, db.ts) manage connections and environment settings.
– Controllers: Identify controllers like authController, listController, and movieController, handling the request logic.
– Routes: Represent the API routes grouped by functionality (authRoutes, listRoutes, movieRoutes).
– Services: Illustrate service modules (authService, listService, movieService) encapsulating business logic.
– Models: Mark the models (User, listModel, etc.) that define the data schema interacting with MongoDB.
- Database: Include MongoDB (via MongoDB Atlas) which interacts with the API for persisting user data, movie lists, and other dynamic content.
- External API Integration: Since the project relies on The Movie Database (TMDb) for movie data, denote the integration as an external service with directional data flow from the backend to TMDb.

##### Relationships and Interactions
- Within the backend, illustrate the interaction flow:
– API Routes receive HTTP requests and forward them to the appropriate Controllers.
– Controllers call Services, which may interact with Models (and, consequently, the Database) or external APIs.
– Middleware (specifically for authentication) intercepts requests to protect secure endpoints.

##### Architectural Patterns and Design Principles
- Modularization: The separation of concerns is evident – controllers, services, routes, and models are each isolated in separate directories.
- MVC-like Pattern: Although not a strict MVC implementation, the structure loosely mirrors an MVC pattern where controllers handle requests, services manage business logic, and models represent data.
- Client-Server: Emphasize the clear demarcation between the frontend client (Next.js) and the backend server (Node.js).

##### Relevant Technologies
- Frontend: Next.js, React, TailwindCSS, TypeScript.
- Backend: Node.js, TypeScript, MongoDB.
- Third-Party API: TMDb for movie data.
- Deployment/Hosting: The frontend is hosted on Vercel and the backend on Render.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Application
    subgraph "Frontend Application"
        F1["Next.js Frontend"]:::frontend
        F2["Login Page"]:::frontend
        F3["Register Page"]:::frontend
        F4["Lists Page"]:::frontend
        F5["Create List Page"]:::frontend
        F6["Movie Details Page"]:::frontend
        F7["Navbar Component"]:::frontend
        F8["Footer Component"]:::frontend
        F9["UI Components"]:::frontend
        F10["State Management Hook"]:::frontend
    end

    %% Backend API
    subgraph "Backend API"
        B1["API Server"]:::backend
        subgraph "Server Initialization"
            B1A["server.ts"]:::backend
            B1B["app.ts"]:::backend
        end
        subgraph "Configuration Layer"
            B2A["API Configuration"]:::config
            B2B["DB Connection"]:::config
        end
        subgraph "Controllers"
            B3A["Auth Controller"]:::backend
            B3B["List Controller"]:::backend
            B3C["Movie Controller"]:::backend
        end
        subgraph "Routes"
            B4A["Auth Routes"]:::backend
            B4B["List Routes"]:::backend
            B4C["Movie Routes"]:::backend
        end
        subgraph "Middleware"
            B5["Auth Middleware"]:::backend
        end
        subgraph "Services"
            B6A["Auth Service"]:::backend
            B6B["List Service"]:::backend
            B6C["Movie Service"]:::backend
        end
        subgraph "Models"
            B7A["User Model"]:::backend
            B7B["List Model"]:::backend
        end
    end

    %% Database and External API
    D1["MongoDB Atlas"]:::database
    E1["TMDb API"]:::external

    %% Relationships between Frontend and Backend
    F1 -->|"API_calls"| B1

    %% Backend internal flows
    B4A -->|"calls"| B3A
    B4B -->|"calls"| B3B
    B4C -->|"calls"| B3C

    B3A -->|"uses"| B6A
    B3B -->|"uses"| B6B
    B3C -->|"uses"| B6C

    B6A -->|"db_operation"| B7A
    B6B -->|"db_operation"| B7B
    B6C -->|"db_operation"| B7B

    B6C -->|"fetch_data"| E1

    B7A -->|"CRUD"| D1
    B7B -->|"CRUD"| D1

    %% Middleware integration with Routes
    B5 ---|"auth_validates"| B4A
    B5 ---|"auth_validates"| B4B
    B5 ---|"auth_validates"| B4C

    %% Class definitions for coloring
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef config fill:#e6e6fa,stroke:#000,stroke-width:1px;
    classDef database fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:1px;

    %% Click Events for Frontend Application
    click F2 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/app/login/page.tsx"
    click F3 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/app/register/page.tsx"
    click F4 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/app/lists/page.tsx"
    click F5 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/app/lists/create/page.tsx"
    click F6 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/app/movies/[id]/page.tsx"
    click F7 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/components/Navbar.tsx"
    click F8 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/components/Footer.tsx"
    click F9 "https://github.com/kc1t/desafio-verzel/tree/main/screenli-cli/src/components/ui"
    click F10 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-cli/src/hooks/use-toast.ts"

    %% Click Events for Backend API
    click B1A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/server.ts"
    click B1B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/app.ts"
    click B2A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/config/apiConfig.ts"
    click B2B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/config/db.ts"
    click B3A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/controllers/authController.ts"
    click B3B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/controllers/listController.ts"
    click B3C "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/controllers/movieController.ts"
    click B4A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/routes/authRoutes.ts"
    click B4B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/routes/listRoutes.ts"
    click B4C "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/routes/movieRoutes.ts"
    click B5 "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/middlewares/authMiddleware.ts"
    click B6A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/services/authService.ts"
    click B6B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/services/listService.ts"
    click B6C "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/services/movieService.ts"
    click B7A "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/models/User.ts"
    click B7B "https://github.com/kc1t/desafio-verzel/blob/main/screenli-api/src/models/listModel.ts"
```
