# busdtswim/brandeisswim architecture

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

- Interactive diagram: https://gitdiagram.com/busdtswim/brandeisswim
- Repository: https://github.com/busdtswim/brandeisswim

## Overview

- Frontend/UI Layer:
- Next.js “app” folder that is subdivided into different routes/pages (e.g., public pages, admin, customer, login, register, etc.).
- Modular components in src/components (such as AdminDashboard, CustomerDashboard, AddInstructors, ContentEditor, and so on).
- Shared assets like fonts, global styles (src/app/globals.css, src/style), and page layouts.

- API / Backend Layer:
- API routes under src/app/api which define endpoints for authentication (login, logout, register, reset-password, etc.), administrative actions (lesson creation, content management, stats, etc.), customer functionalities (schedule and profile management), and additional services like contact forms.
- Authentication subdirectories (like auth, auth/admin, auth/customer, auth/lessons, etc.), indicating that the API layer is organized by role (admin versus customer) and by function (content, schedule, lesson register).

- Database Layer:
- Prisma integration (prisma/schema.prisma) which serves as the data model and interacts with the underlying database.

- Middleware & Utility Layers:
- Middleware (src/middleware.js) that likely handles request-level processing (e.g., authentication, logging, error handling).
- Utility libraries (src/lib and src/utils) that encapsulate common functions such as date, time, and formatting utilities.

##### Relationships and Data Flow
- The backend layer processes these requests, applies necessary business logic, and accesses the database (via Prisma).
- Middleware intercepts and processes requests if needed before they hit the API route handlers.
- For instance, an admin user managing lessons: The Admin Dashboard (component) interacts with the API endpoints under “auth/admin/lessons” to create, update, or delete lessons.
- A customer user booking a lesson: The UI triggers API calls (under “auth/customer/schedule”) which in turn query/update the database.

##### Important Architectural Patterns and Design Principles
- Next.js Routes and File-based Routing: Emphasize how the project utilizes Next.js’ file structure for routing based on directory organization.
- Separation of Concerns: Illustrate how the system separates frontend (UI and components), backend (API routes), and data persistence (Prisma-based DB layer).
- Role-Based Access: Note the distinction between admin and customer endpoints, indicating a layered security or permissions model.
- Modularization: The component breakdown (e.g., separate components for AdminSideBar, Header, Footer) shows a clean, maintainable separation in the UI, while logical grouping in the API endpoints mirrors business domains.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface"
        U["Client (User)"]:::frontend
        FS1["Next.js Pages & Routes"]:::frontend
        FS2["Global Styles (globals.css)"]:::frontend
        FS3["Style Assets (src/style)"]:::frontend
        subgraph "Layouts"
            L1["Main Layout"]:::frontend
            L2["Admin Layout"]:::frontend
            L3["Customer Layout"]:::frontend
        end
        subgraph "UI Components"
            UI1["AdminDashboard"]:::frontend
            UI2["CustomerDashboard"]:::frontend
            UI3["AddInstructors"]:::frontend
            UI4["ContentEditor"]:::frontend
        end
    end

    %% API / Backend Layer
    subgraph "API / Backend Layer"
        A1["API Routes Entry"]:::backend
        A2["Auth Endpoints"]:::backend
        A3["Admin API Endpoints"]:::backend
        A4["Customer API Endpoints"]:::backend
        A5["Lesson Registration"]:::backend
        A6["Lesson Management"]:::backend
        A7["Additional Auth APIs"]:::backend
        A8["Content API"]:::backend
    end

    %% Middleware & Utility Layers
    subgraph "Middleware & Utilities"
        MW["Middleware"]:::middleware
        UT["Lib Utils"]:::middleware
        UT1["Date Utils"]:::middleware
        UT2["Format Utils"]:::middleware
        UT3["Time Utils"]:::middleware
        UT4["Timezone Utils"]:::middleware
    end

    %% Database Layer
    subgraph "Database Layer"
        DB["Prisma Schema"]:::database
    end

    %% Relationships and Data Flow
    U -->|"uses"| FS1
    FS1 -->|"HTTP_Request"| A1
    FS1 -->|"Auth_Request"| A2
    UI1 -->|"ManageLessons"| A3
    UI2 -->|"ManageSchedule"| A4
    A1 -->|"Intercepts"| MW
    MW --> A2
    MW --> A3
    MW --> A4
    A1 -->|"DB_Access"| DB
    A2 -->|"DB_Access"| DB
    A3 -->|"DB_Access"| DB
    A4 -->|"DB_Access"| DB
    A5 -->|"DB_Access"| DB
    A6 -->|"DB_Access"| DB
    A7 -->|"DB_Access"| DB
    A8 -->|"DB_Access"| DB
    A1 -->|"Utilizes"| UT
    UT -->|"Includes"| UT1
    UT -->|"Includes"| UT2
    UT -->|"Includes"| UT3
    UT -->|"Includes"| UT4

    %% Click Events for Frontend/UI Layer
    click FS1 "https://github.com/busdtswim/brandeisswim/tree/main/src/app"
    click FS2 "https://github.com/busdtswim/brandeisswim/blob/main/src/app/globals.css"
    click FS3 "https://github.com/busdtswim/brandeisswim/tree/main/src/style"
    click L1 "https://github.com/busdtswim/brandeisswim/blob/main/src/app/layout.js"
    click L2 "https://github.com/busdtswim/brandeisswim/blob/main/src/app/admin/layout.js"
    click L3 "https://github.com/busdtswim/brandeisswim/blob/main/src/app/customer/layout.js"
    click UI1 "https://github.com/busdtswim/brandeisswim/blob/main/src/components/AdminDashboard.js"
    click UI2 "https://github.com/busdtswim/brandeisswim/blob/main/src/components/CustomerDashboard.js"
    click UI3 "https://github.com/busdtswim/brandeisswim/blob/main/src/components/AddInstructors.js"
    click UI4 "https://github.com/busdtswim/brandeisswim/blob/main/src/components/ContentEditor.js"

    %% Click Events for API / Backend Layer
    click A1 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api"
    click A2 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth"
    click A3 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth/admin"
    click A4 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth/customer"
    click A5 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth/lesson-register"
    click A6 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth/lessons"
    click A7 "https://github.com/busdtswim/brandeisswim/tree/main/src/app/api/auth/contact"
    click A8 "https://github.com/busdtswim/brandeisswim/blob/main/src/app/api/content/route.js"

    %% Click Events for Middleware & Utility Layers
    click MW "https://github.com/busdtswim/brandeisswim/blob/main/src/middleware.js"
    click UT "https://github.com/busdtswim/brandeisswim/blob/main/src/lib/utils.js"
    click UT1 "https://github.com/busdtswim/brandeisswim/blob/main/src/utils/dateUtils.js"
    click UT2 "https://github.com/busdtswim/brandeisswim/blob/main/src/utils/formatUtils.js"
    click UT3 "https://github.com/busdtswim/brandeisswim/blob/main/src/utils/timeUtils.js"
    click UT4 "https://github.com/busdtswim/brandeisswim/blob/main/src/utils/timezoneUtils.js"

    %% Click Event for Database Layer
    click DB "https://github.com/busdtswim/brandeisswim/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef middleware fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
