# pgap22/splitq-nextjs architecture

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

- Interactive diagram: https://gitdiagram.com/pgap22/splitq-nextjs
- Repository: https://github.com/pgap22/splitq-nextjs

## Overview

##### Main Components
- Frontend (Presentation Layer):
– Next.js application structure under the “app” directory. Note the clear separation into protected areas (with subpaths like /admin, /seller, /mod, /home) and authentication pages.
- API and Business Logic (Backend Layer):
– The “actions” directory contains many JavaScript files implementing different endpoints or business actions (for example, user creation, authentication, cart management, splitpay operations, etc.). These are the backend controllers managing business logic.
– The “lib” folder offers support utilities (email templates, Cloudinary integrations, socket.io, and helper functions) that are used across actions and other parts of the application.
– The “middleware.js” file and auth-related configuration files (such as “auth.config.js”, “auth.routes.js”) that enforce authentication and authorization flows.
- Database Layer:
– The “prisma” directory with its migrations and schema.prisma shows that Prisma ORM is used. This layer represents all persistent data storage including users, products, tickets, balances, and logs.
– The “db” directory contains code to set up the Prisma client.
- External Services / Infrastructure:
– Docker: Files like Dockerfile, docker-compose.yml, and .dockerignore indicate containerization for deployment.
– External integrations such as Cloudinary (in “lib/cloudinary.js”, “lib/signatureCloudinary.js”), email services (“lib/email.js”, “lib/emailAPI.js”, and email templates), and real-time notifications using socket.io (“lib/socketio.js”).
– Version control details (Git configuration files) which can be shown as supporting components.
- Supporting Artifacts:
– Configuration files (e.g., next.config.mjs, tailwind.config.js, .env.example) are essential for deployment and environment customization.
– Additional resources like Figma and Trello links (from the README) that support design and project planning.

##### Relationships and Flow
– From “actions” (the API endpoints), indicate how requests are processed using helper modules from the “lib” folder and business rules encoded therein.
– Represent Middleware/Auth flows that enforce security on protected routes and API endpoints (using middleware.js and auth configuration files).

##### Architectural Patterns and Design Principles
– The project enforces a clear separation between the frontend and backend logic (typical in full-stack Next.js apps).
– It may follow an MVC or similar modular approach – with “actions” serving as controllers, “lib” providing models and utility functions, and Prisma providing data models.
– The directory structure indicates component reuse and a pattern for organizing routes (using Next.js nested routing).
– Use of Docker highlights containerization best practices for deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE_Main["Next.js App (Main)"]:::frontend
        subgraph "Protected Pages"
            FE_Admin["/admin Page"]:::frontend
            FE_Seller["/seller Page"]:::frontend
            FE_Mod["/mod Page"]:::frontend
            FE_Home["/home Page"]:::frontend
        end
        subgraph "Authentication Pages"
            FE_AuthPages["Auth UI Pages"]:::frontend
            FE_APIAuth["API Auth Endpoints"]:::frontend
        end
        FE_UIComponents["UI Components"]:::frontend
        FE_Containers["UI Containers"]:::frontend
    end

    %% API & Business Logic Layer
    subgraph "API & Business Logic"
        subgraph "API Endpoints"
            API_Actions["API Endpoints (Actions)"]:::backend
        end
        subgraph "Middleware & Auth"
            API_Middleware["middleware.js"]:::backend
            API_AuthConfig["auth.config.js"]:::backend
            API_AuthRoutes["auth.routes.js"]:::backend
        end
        API_Utility["Utility & Services (Lib)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        DB_Prismadb["Prisma ORM Database"]:::db
        DB_Client["Prisma Client Setup (DB)"]:::db
    end

    %% External Infrastructure & Configuration
    subgraph "External Infrastructure & Configuration"
        subgraph "Containerization"
            EXT_Dockerfile["Dockerfile"]:::infra
            EXT_DockerCompose["docker-compose.yml"]:::infra
            EXT_Dockerignore[".dockerignore"]:::infra
        end
        subgraph "Configuration Files"
            CONF_NextConfig["next.config.mjs"]:::config
            CONF_Tailwind["tailwind.config.js"]:::config
            CONF_Env[".env.example"]:::config
        end
    end

    %% Connections from Frontend to API
    FE_Main -->|"triggers"| API_Actions
    FE_Admin -->|"triggers"| API_Actions
    FE_Seller -->|"triggers"| API_Actions
    FE_Mod -->|"triggers"| API_Actions
    FE_Home -->|"triggers"| API_Actions
    FE_AuthPages -->|"calls"| API_Actions
    FE_APIAuth -->|"calls"| API_Actions
    FE_UIComponents -->|"interacts"| API_Actions
    FE_Containers -->|"interacts"| API_Actions

    %% Connections within API Layer
    API_Actions -->|"securedBy"| API_Middleware
    API_Actions -->|"utilizes"| API_Utility
    API_Actions -->|"CRUD"| DB_Prismadb
    API_Actions -->|"CRUD"| DB_Client

    %% Style Definitions
    classDef frontend fill:#f9e79f,stroke:#d35400,stroke-width:2px;
    classDef backend fill:#aed6f1,stroke:#2874a6,stroke-width:2px;
    classDef db fill:#abebc6,stroke:#1e8449,stroke-width:2px;
    classDef infra fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
    classDef config fill:#fad7a0,stroke:#b9770e,stroke-width:2px;

    %% Click Events for Frontend Layer
    click FE_Main "https://github.com/pgap22/splitq-nextjs/tree/master/app"
    click FE_Admin "https://github.com/pgap22/splitq-nextjs/tree/master/app/(protected)/admin"
    click FE_Seller "https://github.com/pgap22/splitq-nextjs/tree/master/app/(protected)/seller"
    click FE_Mod "https://github.com/pgap22/splitq-nextjs/tree/master/app/(protected)/mod"
    click FE_Home "https://github.com/pgap22/splitq-nextjs/tree/master/app/(protected)/home"
    click FE_AuthPages "https://github.com/pgap22/splitq-nextjs/tree/master/app/auth"
    click FE_APIAuth "https://github.com/pgap22/splitq-nextjs/tree/master/app/api/auth"
    click FE_UIComponents "https://github.com/pgap22/splitq-nextjs/tree/master/components"
    click FE_Containers "https://github.com/pgap22/splitq-nextjs/tree/master/containers"

    %% Click Events for API & Business Logic Layer
    click API_Actions "https://github.com/pgap22/splitq-nextjs/tree/master/actions"
    click API_Middleware "https://github.com/pgap22/splitq-nextjs/blob/master/middleware.js"
    click API_AuthConfig "https://github.com/pgap22/splitq-nextjs/blob/master/auth.config.js"
    click API_AuthRoutes "https://github.com/pgap22/splitq-nextjs/blob/master/auth.routes.js"
    click API_Utility "https://github.com/pgap22/splitq-nextjs/tree/master/lib"

    %% Click Events for Database Layer
    click DB_Prismadb "https://github.com/pgap22/splitq-nextjs/tree/master/prisma"
    click DB_Client "https://github.com/pgap22/splitq-nextjs/tree/master/db"

    %% Click Events for External Infrastructure & Configuration
    click EXT_Dockerfile "https://github.com/pgap22/splitq-nextjs/tree/master/Dockerfile"
    click EXT_DockerCompose "https://github.com/pgap22/splitq-nextjs/blob/master/docker-compose.yml"
    click EXT_Dockerignore "https://github.com/pgap22/splitq-nextjs/blob/master/.dockerignore"
    click CONF_NextConfig "https://github.com/pgap22/splitq-nextjs/blob/master/next.config.mjs"
    click CONF_Tailwind "https://github.com/pgap22/splitq-nextjs/blob/master/tailwind.config.js"
    click CONF_Env "https://github.com/pgap22/splitq-nextjs/blob/master/.env.example"
```
