# nicholaslhq/attendance-app architecture

> Architecture diagram of the GitHub repository nicholaslhq/attendance-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nicholaslhq/attendance-app
- Repository: https://github.com/nicholaslhq/attendance-app

## Overview

##### Main Components

a. Client-Side (Frontend):
- Pages (Dashboard, Attendance, Class, Session, Student, User, Insights)
- Components (shared UI elements)
- Context Providers (Global Context, Theme Provider)
- Client-side routing

b. Server-Side (Backend):
- Next.js API Routes structure
- Authentication system (NextAuth.js)
- Database connection layer

c. Database:
- MongoDB instance with Prisma ORM
- Database collections based on the schema

##### Component Relationships

- Client-to-Server: API calls between frontend and backend
- Server-to-Database: Prisma ORM interactions
- Authentication flow: NextAuth.js integration
- State management: Global context provider flow

##### Specific Implementation Details

a. Frontend Architecture:
- Pages Layer
- Dashboard
- Attendance
- Class Management
- Session Management
- Student Management
- User Management
- Insights
- Components Layer
- UI Components
- Modal Components
- Table Components
- Layout Components
- State Management
- Global Context
- Theme Context

b. API Architecture:
- Authentication
- NextAuth Integration
- Core APIs
- Attendance Management
- Class Management
- Session Management
- Student Management
- User Management
- Insights
- Database Layer
- Prisma ORM

##### Important Architectural Patterns to Highlight

- API Route Pattern: Show the dynamic routing structure (/api/[resource]/[id])
- Component Hierarchy: Demonstrate the relationship between pages and reusable components
- Authentication Flow: Illustrate how NextAuth.js integrates with the system
- Data Flow: Show how data moves from database through API to frontend

##### Technical Stack Indicators

- Next.js
- React
- MongoDB
- Prisma
- NextAuth.js
- Tailwind CSS

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Frontend
        Pages["Pages Layer"]
        Components["Components Layer"]
        State["State Management"]

        subgraph Pages
            Dashboard["Dashboard"]:::page
            Attendance["Attendance"]:::page
            Class["Class Management"]:::page
            Session["Session Management"]:::page
            Student["Student Management"]:::page
            User["User Management"]:::page
            Insights["Insights"]:::page
        end

        subgraph Components
            UI["UI Components"]:::component
            Modal["Modal Components"]:::component
            Table["Table Components"]:::component
            Layout["Layout Components"]:::component
            Error["Error Handling"]:::component
            Loading["Loading States"]:::component
        end

        subgraph State
            GlobalContext["Global Context"]:::state
            ThemeContext["Theme Context"]:::state
            ContextProvider["Context Provider"]:::state
        end
    end

    subgraph API
        Auth["Authentication"]:::api
        CoreAPI["Core APIs"]:::api

        subgraph CoreAPI
            AttendanceAPI["Attendance API"]:::api
            ClassAPI["Class API"]:::api
            SessionAPI["Session API"]:::api
            StudentAPI["Student API"]:::api
            UserAPI["User API"]:::api
            InsightsAPI["Insights API"]:::api
        end
    end

    subgraph Database
        MongoDB[(MongoDB)]:::db
        PrismaORM["Prisma ORM"]:::db
        DBConnection["Database Connection"]:::db
    end

    %% Relationships
    Pages --> Components
    Components --> State
    Pages --> CoreAPI
    Auth --> MongoDB
    CoreAPI --> PrismaORM
    PrismaORM --> MongoDB
    DBConnection --> MongoDB

    %% Click Events
    click Dashboard "https://github.com/nicholaslhq/attendance-app/blob/main/app/page.tsx"
    click Attendance "https://github.com/nicholaslhq/attendance-app/blob/main/app/attendance/page.tsx"
    click Class "https://github.com/nicholaslhq/attendance-app/blob/main/app/class/page.tsx"
    click Session "https://github.com/nicholaslhq/attendance-app/blob/main/app/session/page.tsx"
    click Student "https://github.com/nicholaslhq/attendance-app/blob/main/app/student/page.tsx"
    click User "https://github.com/nicholaslhq/attendance-app/blob/main/app/user/page.tsx"
    click Insights "https://github.com/nicholaslhq/attendance-app/blob/main/app/insight/page.tsx"
    click UI "https://github.com/nicholaslhq/attendance-app/blob/main/app/components/button/Button.tsx"
    click Modal "https://github.com/nicholaslhq/attendance-app/tree/main/app/components/modal/"
    click Table "https://github.com/nicholaslhq/attendance-app/tree/main/app/components/table/"
    click Layout "https://github.com/nicholaslhq/attendance-app/blob/main/app/components/sidebar/Sidebar.tsx"
    click GlobalContext "https://github.com/nicholaslhq/attendance-app/blob/main/app/context/GlobalContextProvider.js"
    click ThemeContext "https://github.com/nicholaslhq/attendance-app/blob/main/app/context/themes.js"
    click ContextProvider "https://github.com/nicholaslhq/attendance-app/blob/main/app/providers/ContextProvider.tsx"
    click Auth "https://github.com/nicholaslhq/attendance-app/blob/main/app/api/auth/[...nextauth]/route.ts"
    click AttendanceAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/attendance/"
    click ClassAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/class/"
    click SessionAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/session/"
    click StudentAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/student/"
    click UserAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/user/"
    click InsightsAPI "https://github.com/nicholaslhq/attendance-app/tree/main/app/api/insight/"
    click PrismaORM "https://github.com/nicholaslhq/attendance-app/blob/main/prisma/schema.prisma"
    click DBConnection "https://github.com/nicholaslhq/attendance-app/blob/main/app/utils/connect.ts"
    click Error "https://github.com/nicholaslhq/attendance-app/blob/main/app/components/error/NoPermissionError.tsx"
    click Loading "https://github.com/nicholaslhq/attendance-app/blob/main/app/components/loader/Loader.tsx"

    %% Styling
    classDef page fill:#e1f5fe,stroke:#01579b
    classDef component fill:#e8f5e9,stroke:#2e7d32
    classDef state fill:#fff3e0,stroke:#ef6c00
    classDef api fill:#f3e5f5,stroke:#7b1fa2
    classDef db fill:#fce4ec,stroke:#c2185b

    %% Legend
    subgraph Legend
        L1["Frontend Pages"]:::page
        L2["UI Components"]:::component
        L3["State Management"]:::state
        L4["API Layer"]:::api
        L5["Database Layer"]:::db
    end
```
