# dt418/nghien-phim architecture

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

- Interactive diagram: https://gitdiagram.com/dt418/nghien-phim
- Repository: https://github.com/dt418/nghien-phim

## Overview

##### Main components
- Client/Browser: Represents the end-user using the application.
- Next.js Server Application: This central component handles both page rendering and API endpoints. It incorporates:
- Page Components: In folders like src/app/[...slug], src/app/phim, src/app/danh-sach, etc., these define the routing and UI pages.
- API Routes: Found in src/app/api (e.g., increment, set-search) which serve as backend endpoints for dynamic data.
- Layout and Error Handling: Includes layouts (e.g., layout.tsx), loading states, and not-found pages.
- UI Component Library: A collection of reusable UI parts (e.g., buttons, dialogs, navigation menus) located in src/components/ui and related folders.
- Data and Utility Layer: Logic for API configuration, fetching, error handling, and other utilities found under src/lib (such as src/lib/api and src/lib/utils).
- Configuration & Theming: Includes theme providers (src/providers/theme.tsx) and configuration files (e.g., tailwind.config.ts, next.config.ts) that affect both the appearance and behavior of the app.
- External Services & Deployment Pipelines: Deployment configurations (Dockerfile, docker-compose.yml), CI/CD configurations (in .github/workflows), and testing frameworks (vitest and tests directory) to ensure quality and scalable deployment.

##### Relationships and interactions
- The Client (browser) communicates with the Next.js Server through HTTP requests.
- When a user navigates, the server dynamically renders pages and may use server-side logic to call API routes for data.
- UI components are assembled within these pages, while API calls from the client often route through the Next.js API endpoints.
- The data fetching and utilities (in src/lib) provide abstraction layers for consuming back-end data and handling business logic.
- Deployment and containerization (Dockerfile, docker-compose.yml, GitHub workflows) support building, testing, and distributing the app.
- Testing components (in tests) validate functionality at both unit and integration levels.

##### Architectural patterns and design principles
- Utilization of the App Router from Next.js: The project leverages Next.js’ file-based routing to define pages, layouts, and nested routes.
- Separation of Concerns: Distinct folders for API logic, UI components, and business logic promote modularity.
- Configuration and Deployment as Code: Docker and CI configurations highlight a modern, DevOps-oriented approach to deployment.

##### Relevant technologies and frameworks
- Next.js and React for building the user interface.
- Server-side rendering with dynamic and static generation patterns.
- CSS and Tailwind CSS for styling (as indicated by tailwind.config.ts and related postcss configurations).
- API design using Next.js API routes.
- Testing infrastructure with Vitest and a custom test setup.
- Deployment tools like Docker, GitHub workflows, and scripts (build-image.sh, build-image.ps1).

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Client/Browser"]:::client

    subgraph "Next.js Server Application"
        B1["Pages & Routing"]:::server
        B2["API Endpoints"]:::server
        B3["Layouts & Error Handling"]:::server
    end

    C["UI Component Library"]:::ui
    D["Data & Utility Layer"]:::data
    E["Configuration & Theming"]:::config
    F["External Services & Deployment"]:::deploy
    G["Testing"]:::testing

    A -->|"HTTP_request"| B1
    A -->|"HTTP_request"| B2
    A -->|"HTTP_request"| B3

    B1 -->|"renders"| C
    B1 -->|"data_fetch"| D
    B2 -->|"data_processing"| D

    E -->|"configures"| B1
    E -->|"configures"| B2
    E -->|"configures"| B3

    F -->|"deploys"| B1
    F -->|"deploys"| B2
    F -->|"deploys"| B3

    G -->|"tests"| B1
    G -->|"tests"| B2
    G -->|"tests"| B3
    G -->|"CI/CD"| F

    %% Click Events
    click B1 "https://github.com/dt418/nghien-phim/blob/main/src/app/[...slug]/page.tsx"
    click B2 "https://github.com/dt418/nghien-phim/blob/main/src/app/api/increment/route.ts"
    click B3 "https://github.com/dt418/nghien-phim/blob/main/src/app/layout.tsx"
    click C "https://github.com/dt418/nghien-phim/tree/main/src/components/ui"
    click D "https://github.com/dt418/nghien-phim/tree/main/src/lib"
    click E "https://github.com/dt418/nghien-phim/blob/main/src/providers/theme.tsx"
    click F "https://github.com/dt418/nghien-phim/tree/main/Dockerfile"
    click G "https://github.com/dt418/nghien-phim/tree/main/tests"

    %% Styles
    classDef client fill:#d1e7dd,stroke:#0f5132,stroke-width:2px
    classDef server fill:#cff4fc,stroke:#055160,stroke-width:2px
    classDef ui fill:#fff3cd,stroke:#856404,stroke-width:2px
    classDef data fill:#fde2e4,stroke:#d6336c,stroke-width:2px
    classDef config fill:#e2e3e5,stroke:#6c757d,stroke-width:2px
    classDef deploy fill:#d1d1e1,stroke:#858585,stroke-width:2px
    classDef testing fill:#f8d7da,stroke:#842029,stroke-width:2px
```
