# chris-15/cod-stats-dashboard architecture

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

- Interactive diagram: https://gitdiagram.com/chris-15/cod-stats-dashboard
- Repository: https://github.com/chris-15/cod-stats-dashboard

## Overview

##### Main Components

- Frontend (UI Layer):
- The entire “app” directory represents the Next.js routing structure. It contains pages for various functionalities like sign-in, adding/editing stats, dashboards (with sub-folders for different games like bo6 and mw3), and more.
- The “components” folder includes UI components (charts, tables, navigation bars, buttons, modals, etc.) that are used throughout the application.
- The “hooks” directory provides custom React hooks to manage specific UI behavior, such as responsive design (use-mobile) and retrieving map statistics (useMapStats).

- API / Backend (Business Logic & Integration Layer):
- Additionally, there’s a “server” directory with additional query logic (e.g., “server/queries.ts”) that might support data retrieval or custom business rules.

- Data Access / Database Layer:
- The project leverages Prisma (with a dedicated “prisma” folder containing the schema) together with a dedicated utility file in “lib/prismadb” to communicate with the database. Given the MongoDB badge in the README, the database is likely hosted on MongoDB.
- Other utility functions, such as those in “lib/stat-utils.ts” and “lib/utils.ts”, provide additional business logic and data manipulation.

##### Relationships and Interactions

- User Interaction: Users interact with the frontend (React pages, components) to view and manage their match statistics.
- Authentication Flow: The sign-in page under “app/sign-in” interacts with API endpoints (in “app/api/auth”) to handle authentication using NextAuth. This integrates with both the frontend and the database (via Prisma) for user data management.
- Data Flow for Statistics: When users add or edit match statistics (seen in “app/add-stats” and “app/edit-stats”), the frontend communicates with API routes under “app/api/matches”. These endpoints then use the business logic (hooks, lib functions) and access the database through Prisma.
- UI Components: The various components (charts, tables, cards) assemble data fetched from API endpoints, applying design principles of modularity and reusability.

##### Architectural Patterns and Principles

- Next.js App Directory: Emphasizes file-based routing for both pages and API endpoints.
- Component-Based UI: Organized under the “components” folder, following modern React best practices.
- Route-Driven UI for dashboards: Notice the dynamic routing (with folders and files using square brackets like “[id]” and “[gameMode]”) which supports personalized dashboard views.
- Separation of Concerns: Clear split between the presentation layer (UI), the API/backend (Next.js API routes and server queries), and the data access layer (Prisma-based integration with MongoDB).
- Modular Services: The use of NextAuth for authentication and Prisma for database interactions signal a modular design where each service is encapsulated in its right context.

##### Element Recommendations
- Clear and descriptive labels for each component and layer.
- Annotations to highlight dynamic routing and the use of modern practices like file-based routing and component reuse.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        User("User"):::external
    end

    subgraph "UI Layer"
        SignIn("Sign-In Page"):::ui
        AddStats("Add Stats Page"):::ui
        EditStats("Edit Stats Page"):::ui
        Dashboard("Dashboard Page"):::ui
        Navbar("Navbar Component"):::ui
        KdBarChart("KdBarChart Component"):::ui
        UseMobile("useMobile Hook"):::ui
        UseMapStats("useMapStats Hook"):::ui
    end

    subgraph "API Layer"
        AuthAPI("Auth API Endpoint"):::api
        MatchesAPI("Matches API Endpoint"):::api
    end

    subgraph "Business Logic"
        ServerQueries("Server Queries"):::business
    end

    subgraph "Data Access Layer"
        PrismaSchema("Prisma Schema"):::data
        PrismaClient("Prisma Client"):::data
        subgraph "Utility Functions (Lib)"
            StatUtils("Stat Utils"):::data
            Utils("General Utils"):::data
            AuthUtils("Auth Utils"):::data
            MapSets("MapSets Utils"):::data
        end
        Database("MongoDB Database"):::database
    end

    %% User to UI interactions
    User -->|"interacts"| SignIn
    User -->|"interacts"| AddStats
    User -->|"interacts"| EditStats
    User -->|"interacts"| Dashboard

    %% UI internal relations
    SignIn -->|"renders"| Navbar
    AddStats -->|"renders"| Navbar
    EditStats -->|"renders"| Navbar
    Dashboard -->|"renders"| Navbar

    SignIn -->|"uses"| UseMobile
    AddStats -->|"uses"| UseMobile
    EditStats -->|"uses"| UseMobile
    Dashboard -->|"uses"| UseMobile

    SignIn -->|"displays"| KdBarChart
    Dashboard -->|"displays"| KdBarChart

    SignIn -->|"calls"| AuthAPI
    AddStats -->|"calls"| MatchesAPI
    EditStats -->|"calls"| MatchesAPI
    Dashboard -->|"calls"| MatchesAPI

    %% API to Business Logic
    AuthAPI -->|"processes"| ServerQueries
    MatchesAPI -->|"processes"| ServerQueries

    %% Business Logic to Data Access
    ServerQueries -->|"queries via"| PrismaClient

    %% Data Access internal flows
    PrismaClient -->|"uses ORM"| PrismaSchema
    PrismaClient -->|"queries"| Database

    %% Business Logic uses utility functions
    ServerQueries -->|"utilizes"| StatUtils
    ServerQueries -->|"utilizes"| Utils
    ServerQueries -->|"utilizes"| AuthUtils
    ServerQueries -->|"utilizes"| MapSets

    %% Click Events for UI Layer
    click SignIn "https://github.com/chris-15/cod-stats-dashboard/blob/main/app/sign-in/page.tsx"
    click AddStats "https://github.com/chris-15/cod-stats-dashboard/blob/main/app/add-stats/page.tsx"
    click EditStats "https://github.com/chris-15/cod-stats-dashboard/blob/main/app/edit-stats/[id]/page.tsx"
    click Dashboard "https://github.com/chris-15/cod-stats-dashboard/tree/main/app/dashboard"
    click Navbar "https://github.com/chris-15/cod-stats-dashboard/blob/main/components/Navbar.tsx"
    click KdBarChart "https://github.com/chris-15/cod-stats-dashboard/blob/main/components/KdBarChart.tsx"
    click UseMobile "https://github.com/chris-15/cod-stats-dashboard/blob/main/hooks/use-mobile.tsx"
    click UseMapStats "https://github.com/chris-15/cod-stats-dashboard/blob/main/hooks/useMapStats.tsx"

    %% Click Events for API Layer
    click AuthAPI "https://github.com/chris-15/cod-stats-dashboard/blob/main/app/api/auth/[...nextauth]/route.ts"
    click MatchesAPI "https://github.com/chris-15/cod-stats-dashboard/blob/main/app/api/matches/[id]/route.ts"

    %% Click Events for Business Logic
    click ServerQueries "https://github.com/chris-15/cod-stats-dashboard/blob/main/server/queries.ts"

    %% Click Events for Data Access Layer
    click PrismaSchema "https://github.com/chris-15/cod-stats-dashboard/blob/main/prisma/schema.prisma"
    click PrismaClient "https://github.com/chris-15/cod-stats-dashboard/blob/main/lib/prismadb.ts"
    click StatUtils "https://github.com/chris-15/cod-stats-dashboard/blob/main/lib/stat-utils.ts"
    click Utils "https://github.com/chris-15/cod-stats-dashboard/blob/main/lib/utils.ts"
    click AuthUtils "https://github.com/chris-15/cod-stats-dashboard/blob/main/lib/auth.ts"
    click MapSets "https://github.com/chris-15/cod-stats-dashboard/blob/main/lib/mapSets.ts"

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#1F8AC0,stroke-width:2px;
    classDef api fill:#F7D6AE,stroke:#D17F50,stroke-width:2px;
    classDef business fill:#C9F7AE,stroke:#6DA050,stroke-width:2px;
    classDef data fill:#E2AEF7,stroke:#A050C0,stroke-width:2px;
    classDef database fill:#F7AEC1,stroke:#C05F80,stroke-width:2px;
    classDef external fill:#FFF79A,stroke:#FFC107,stroke-width:2px;
```
