# pdqdat/awad-project architecture

> Architecture diagram of the GitHub repository pdqdat/awad-project, 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/pdqdat/awad-project
- Repository: https://github.com/pdqdat/awad-project

## Overview

##### Main Components

a. Frontend:
- Built with Next.js and React.
- Uses Tailwind CSS for styling and Radix UI components.
- Contains directories such as /app (with public, auth, and private routes), /components, /config, /context, /hooks, etc.
- Manages user interactions on pages like search, movie details, trending movies, chat with AI, and profile management.
- Integrates with Clerk for authentication via both manual and social login.
- Communicates with the backend through API calls (using NEXT_PUBLIC_BACKEND_URL).

b. Backend:
- An Express.js-based server.
- Has a well-organized structure with directories like /api, /controllers, /models, /routes, and /config.
- Contains controllers for movie functionalities (e.g., movie listing, trending movies, reviews, ratings), user management, navigation and webhooks.
- Integrates with MongoDB via configuration found in /backend/config/db.js.
- Exposes RESTful endpoints managed by routes.
- Uses configuration files (e.g., package.json) and deployment settings (like vercel.json) to support modern deployment practices.

c. Database:
- MongoDB is used as the data store.
- The models in the backend (such as Cast, Genres, MovieList, Movies, etc.) show the schema definitions representing movies, ratings, reviews, and user data.

d. External Services and Services Integration:
- Clerk for user authentication.
- TMDB API (and TMDB access token) to fetch movie data.
- Gemini API integrated via API keys.
- Vercel is used for deployment (as indicated in vercel.json and GitHub workflows in the .github directory).

##### Relationships and Interactions

- Frontend interacts with the backend by making API calls to fetch movie data, perform search queries, submit ratings and reviews, and manage user profiles.
- Backend controllers receive these requests, perform business logic (such as fetching data from or updating data in MongoDB), and return responses.
- The backend communicates with external services (TMDB, Gemini) as needed to enrich movie data.
- User authentication and session management are handled with Clerk, with the frontend utilizing environment configuration to communicate with Clerk, while the backend listens to webhook events from Clerk (as seen in the webhook controller and route).

##### Architectural Patterns and Design Principles

- Clear separation of concerns: the division between frontend (user interface) and backend (data processing, API handling) is evident.
- MVC-like structure at the backend: models, views (or rather responses), and controllers are separated.
- RESTful API design in the backend through well-defined routes and controllers.
- Modular design on the frontend with a detailed folder structure to support various pages and components.
- Use of environment configurations for sensitive keys and deployments ensures secure and flexible deployments.

##### Essential Architectural Elements

- Provide a detailed overview without overcomplicating: clearly describe each component, their interactions, and how data flows through the system.
- Process flow from beginning (user action on the frontend) to backend processing, database operations, and responses back to the user.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        F1["Frontend (Next.js/React)"]:::frontend
        subgraph "Routes"
            F2["Public Routes"]:::frontend
            F3["Authentication Routes"]:::frontend
            F4["Private User Pages"]:::frontend
        end
        subgraph "UI & State"
            F5a["UI Components"]:::frontend
            F5b["Context Providers"]:::frontend
            F5c["Hooks"]:::frontend
        end
        subgraph "Configuration"
            F6a["Configuration"]:::frontend
            F6b["Environment (.env)"]:::frontend
        end
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B1["Backend (Express.js)"]:::backend
        subgraph "Services"
            B2["API Endpoints"]:::backend
            B3["Controllers"]:::backend
            B4["Models"]:::backend
            B5["DB Config"]:::backend
        end
    end

    %% External and Infrastructure Components
    DB["Database (MongoDB)"]:::database
    EX1["Clerk (Auth)"]:::external
    EX2["TMDB API"]:::external
    EX3["Gemini API"]:::external

    subgraph "Deployment"
        D1["Vercel Config"]:::deployment
        D2["CI/CD Workflows"]:::deployment
    end

    %% Relationships
    F1 -->|"APIcalls"| B1
    F1 -->|"UsesClerk"| EX1

    B2 -->|"routesTo"| B3
    B3 -->|"logic"| B4
    B3 -->|"enrichMovies"| EX2
    B3 -->|"enrichMovies"| EX3
    B3 <==>|"webhook"| EX1
    B5 -->|"DBconnection"| DB

    B1 -->|"deployedVia"| D1
    B1 -->|"managedBy"| D2

    %% Styling Classes
    classDef frontend fill:#a3c4f3,stroke:#333,stroke-width:2px;
    classDef backend fill:#c3f3c4,stroke:#333,stroke-width:2px;
    classDef database fill:#f9e79f,stroke:#333,stroke-width:2px;
    classDef external fill:#f7c6c7,stroke:#333,stroke-width:2px;
    classDef deployment fill:#d2b4de,stroke:#333,stroke-width:2px;

    %% Click Events for Frontend
    click F1 "https://github.com/pdqdat/awad-project/tree/master/frontend/app"
    click F2 "https://github.com/pdqdat/awad-project/tree/master/frontend/app/(public)"
    click F3 "https://github.com/pdqdat/awad-project/tree/master/frontend/app/(auth)"
    click F4 "https://github.com/pdqdat/awad-project/tree/master/frontend/app/(private)"
    click F5a "https://github.com/pdqdat/awad-project/tree/master/frontend/components"
    click F5b "https://github.com/pdqdat/awad-project/tree/master/frontend/context"
    click F5c "https://github.com/pdqdat/awad-project/tree/master/frontend/hooks"
    click F6a "https://github.com/pdqdat/awad-project/tree/master/frontend/config"
    click F6b "https://github.com/pdqdat/awad-project/blob/master/frontend/.env.development"

    %% Click Events for Backend
    click B1 "https://github.com/pdqdat/awad-project/tree/master/backend"
    click B2 "https://github.com/pdqdat/awad-project/tree/master/backend/routes"
    click B3 "https://github.com/pdqdat/awad-project/tree/master/backend/controllers"
    click B4 "https://github.com/pdqdat/awad-project/tree/master/backend/models"
    click B5 "https://github.com/pdqdat/awad-project/blob/master/backend/config/db.js"

    %% Click Events for Deployment
    click D1 "https://github.com/pdqdat/awad-project/blob/master/backend/vercel.json"
    click D2 "https://github.com/pdqdat/awad-project/blob/master/.github/workflows/deploy.yml"
```
