# nguyenhuykhai/configurate-nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/nguyenhuykhai/configurate-nextjs
- Repository: https://github.com/nguyenhuykhai/configurate-nextjs

## Overview

##### Project Type and Purpose
- This is a Next.js web application bootstrapped using create-next-app. It’s a full-stack application that employs Next.js’s new app directory structure and integrates server-side features (API endpoints) along with client-side components.
- The project uses a modern domain-driven design (DDD) approach for its authentication and home features, separating concerns into features (with domain, application, and infrastructure layers) and consolidating shared components under src/components.

##### Main Components
a. Frontend (User Interface):
- Next.js Pages/Layouts: Represented by the src/app (with subdirectories for homepage, auth, dashboard, etc.) and src/presentation components.
- UI Components: Under src/components and src/components/ui for common elements (Header, Footer, Avatar, Button, Input, etc.)
- Routing: Built-in Next.js routing based on file locations (like page.tsx files) in the src/app directory.

b. API/Backend Layer:
- API Endpoints: Located under src/pages/api (for authentication endpoints at /api/auth/login and /api/auth/signup).
- Server Side Rendering and Data Fetching: Handled within the Next.js app directory as well as within API routes.

c. Business Logic/Domain Layer:
- Features Module: For example, the auth feature is organized under src/features/auth with clear subdirectories for application use-cases (login, sign-up), domain models, errors, and repositories.
- Domain Layer: Enforces business rules and models interactions (e.g., user session, cookie management).

d. Infrastructure Layer:
- Database Integration: Via prisma (with migrations and schema) located in the prisma folder and corresponding database connection in src/infrastructure/database.
- Dependency Injection: In src/infrastructure/di, ensuring proper decoupling of components.
- External Services & Logging: Found under src/infrastructure/external and src/infrastructure/logging.

e. Shared Resources and Libraries:
- Shared utilities and constants: Under src/lib, src/shared, and configuration files.
- Third-Party Tools: The configuration for tailwind, postcss, prettier, and ESLint indicates the support for styling and code quality.

##### Relationships and Interactions
- The Frontend (client-side) communicates with the API endpoints (under src/pages/api) when a user authenticates or interacts with the app.
- The API layer invokes the business logic/use-cases from the features module, ensuring a clean separation between presentation and domain.
- The Domain Layer in features/auth interacts with the repositories implemented in the infrastructure layer for data persistence (using Prisma).
- Dependency Injection in src/infrastructure/di manages how various components (like repositories and external services) are wired together.
- External services and logging get triggered within the appropriate layers to facilitate monitoring and integration with third-party tools.

##### Architectural and Design Patterns Highlighted
- Domain-Driven Design (DDD): Clear separation of application, domain logic, and infrastructure, especially evident in the auth feature separation.
- Layered/MVC Structure: Distinct layers for presentation (Next.js pages and UI components), business logic (features), and data access (prisma and infrastructure).
- Modular Structure: Features and components are broken out into their own modules to improve maintainability and testability.
- Server-Side Rendering & API Integration: Using Next.js's architecture to handle both client-side and backend responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Browser"):::browser

    subgraph "Frontend Layer"
        subgraph "Next.js Pages & Layouts"
            p1("page.tsx"):::frontend
            p2("layout.tsx"):::frontend
            p3("globals.css"):::frontend
            p4("Auth Sign-In Page"):::frontend
            p5("Auth Sign-Up Page"):::frontend
            p6("Dashboard Page"):::frontend
        end
        subgraph "UI Components"
            u1("Common Components (Header,Footer)"):::frontend
            u2("UI Elements (avatar,button,card,input,label)"):::frontend
            u3("Theme Provider"):::frontend
        end
    end

    subgraph "API/Backend Layer"
        subgraph "API Endpoints"
            api1("Login API"):::api
            api2("Signup API"):::api
        end
    end

    subgraph "Business Logic / Domain Layer - Auth Feature"
        subgraph "Auth Use Cases & Domain"
            d1("Auth Application Use Cases"):::domain
            d2("Auth Domain Models & Errors"):::domain
            d3("User Repository Interface"):::domain
        end
    end

    subgraph "Infrastructure Layer"
        inf1("Database Integration (Prisma)"):::infrastructure
        inf2("Database Connection"):::infrastructure
        inf3("Dependency Injection"):::infrastructure
        inf4("External Services"):::infrastructure
        inf5("Logging"):::infrastructure
        inf6("Auth Repository Implementation"):::infrastructure
    end

    subgraph "Shared Resources"
        s1("Shared Utilities"):::shared
        s2("Shared Constants & Validation"):::shared
    end

    subgraph "Presentation Layer"
        pres1("Home Page Presentation"):::presentation
        pres2("Auth Presentation (SignIn,SignUp,LoginForm)"):::presentation
        pres3("Other Presentation Components"):::presentation
    end

    %% Connections
    A --> p1
    A --> u1

    p4 -->|"calls"| api1
    p5 -->|"calls"| api2

    api1 -->|"invokes"| d1
    api2 -->|"invokes"| d1

    d1 -->|"uses"| d2
    d1 -->|"calls"| d3
    d3 -->|"implemented-by"| inf6
    inf6 -->|"uses"| inf2
    inf1 -->|"provides"| inf2

    inf3 -->|"injects"| d1
    inf3 -->|"injects"| inf6

    inf4 -->|"supports"| d1
    inf5 -->|"monitors"| d1

    p1 -->|"renders"| pres1
    p4 -->|"renders"| pres2
    p5 -->|"renders"| pres2
    u1 -->|"composes"| pres3

    s1 -->|"shared"| p1
    s2 -->|"shared"| d1

    %% Click Events for Frontend Pages & Layouts
    click p1 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/(root)/page.tsx"
    click p2 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/layout.tsx"
    click p3 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/globals.css"
    click p4 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/(root)/auth/sign-in/page.tsx"
    click p5 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/(root)/auth/sign-up/page.tsx"
    click p6 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/app/(root)/dashboard/page.tsx"

    %% Click Events for UI Components
    click u1 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/components/common"
    click u2 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/components/ui"
    click u3 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/components/theme-provider.tsx"

    %% Click Events for API Endpoints
    click api1 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/pages/api/auth/login.ts"
    click api2 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/pages/api/auth/signup.ts"

    %% Click Events for Business Logic / Domain Layer
    click d1 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/features/auth/application"
    click d2 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/features/auth/domain/entities"
    click d3 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/features/auth/domain/repositories/userRepository.interface.ts"

    %% Click Events for Infrastructure Layer
    click inf1 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/prisma"
    click inf2 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/infrastructure/database"
    click inf3 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/infrastructure/di"
    click inf4 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/infrastructure/external"
    click inf5 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/infrastructure/logging"
    click inf6 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/features/auth/infrastructure/repositories/userRepository.ts"

    %% Click Events for Shared Resources
    click s1 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/lib/utils.ts"
    click s2 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/shared"

    %% Click Events for Presentation Layer
    click pres1 "https://github.com/nguyenhuykhai/configurate-nextjs/blob/main/src/features/home/presentation/HomePage.tsx"
    click pres2 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/features/auth/presentation"
    click pres3 "https://github.com/nguyenhuykhai/configurate-nextjs/tree/main/src/presentation/components"

    %% Styles
    classDef browser fill:#F5DEB3,stroke:#000,stroke-width:2px
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px
    classDef api fill:#90EE90,stroke:#000,stroke-width:2px
    classDef domain fill:#FFFACD,stroke:#000,stroke-width:2px
    classDef infrastructure fill:#D3D3D3,stroke:#000,stroke-width:2px
    classDef shared fill:#FFB6C1,stroke:#000,stroke-width:2px
    classDef presentation fill:#DDA0DD,stroke:#000,stroke-width:2px"
```
