# nahiddhasan/school-app architecture

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

- Interactive diagram: https://gitdiagram.com/nahiddhasan/school-app
- Repository: https://github.com/nahiddhasan/school-app

## Overview

##### Project Type and Purpose
- This is a full-stack Next.js (React) application with:
- A public-facing “school-front” website for notices & general info
- An authenticated “dashboard” area for student admission, result import, reports, settings, etc.
- A headless API layer (Next.js API routes)
- Persistent storage via Prisma and a relational database
- Authentication/session management via NextAuth

##### Top-Level Components
A. Client (Browser) – React pages & components
B. Next.js Server
1. Page Rendering (SSR/SSG)
2. API Layer (src/app/api/[...nextauth], any other API routes)
3. Middleware
4. Data-access & Business Logic (src/lib, Prisma client)
C. Database – e.g. PostgreSQL (Prisma schema + migrations)
D. Authentication Service – NextAuth (JWT/Session store)
E. File Storage – public/upload (PDFs, CSVs)
F. External Infrastructure – Docker Compose (for local dev), Vercel (for prod)

##### Relationships & Data Flows
- Browser ↔ Next.js Pages
- User requests pages (public or dashboard) → Next.js handles SSR/SSG or serves client bundle
- Client components fetch data via built-in React server components or call API routes
- Browser → API Routes
- Dashboard UI calls Next.js API endpoints (e.g. for student import, result import, CRUD operations)
- Next.js Server → Database
- Business logic in src/lib uses Prisma Client to read/write data
- Prisma migrations define schema under prisma/
- Next.js Server → NextAuth
- Calls NextAuth route under src/app/api/[...nextauth]
- Session data stored in DB or via JWT, injected via SessionProvider
- Next.js Server → File Storage
- Student/Result import uploads CSV into public/assets or public/upload
- PDF exports saved to public/upload for retrieval
- Local Developer Machine ↔ Docker Compose (PostgreSQL container)

##### Architectural Patterns & Design Principles
- Separation of concerns:
- UI layer (React components & pages in src/app & src/components)
- API layer (Next.js API routes + src/lib/actions)
- Data layer (Prisma ORM + schema + migrations)
- Server Components vs. Client Components in Next.js 13 app router
- Protected routes: middleware enforces auth before reaching dashboard pages
- Use of providers (SessionProvider, ThemeProvider) to supply context
- Standard CRUD and bulk-import patterns (Forms, DataTables, file uploads)

##### Diagramming Conventions
- Rectangles for components (UI, API, DB)
- Annotations: note key technologies (Next.js 13, React, Prisma, NextAuth, Tailwind CSS) next to each relevant component

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client (Browser)"
        direction TB
        Browser("Browser"):::frontend
        UI["UI Components\n(src/app/(school-front),\nsrc/app/(dashboard),\nsrc/app/result,\nsrc/components)"]:::frontend
        click UI "https://github.com/nahiddhasan/school-app/tree/main/src/app/(school-front)"
        click UI "https://github.com/nahiddhasan/school-app/tree/main/src/app/(dashboard)"
        click UI "https://github.com/nahiddhasan/school-app/tree/main/src/app/result"
        click UI "https://github.com/nahiddhasan/school-app/tree/main/src/components"
    end

    %% Next.js Server Layer
    subgraph "Next.js Server"
        direction TB

        subgraph "Page Rendering"
            direction TB
            Layout("App Layout & Globals\nsrc/app/layout.tsx\nsrc/app/globals.css"):::server
            click Layout "https://github.com/nahiddhasan/school-app/blob/main/src/app/layout.tsx"
            click Layout "https://github.com/nahiddhasan/school-app/blob/main/src/app/globals.css"
            SFPages("School-Front Pages"):::server
            click SFPages "https://github.com/nahiddhasan/school-app/blob/main/src/app/(school-front)/layout.tsx"
            click SFPages "https://github.com/nahiddhasan/school-app/blob/main/src/app/(school-front)/page.tsx"
            click SFPages "https://github.com/nahiddhasan/school-app/blob/main/src/app/(school-front)/notice/[slug]/page.tsx"
            DBDashboard("Dashboard Pages"):::server
            click DBDashboard "https://github.com/nahiddhasan/school-app/blob/main/src/app/(dashboard)/dashboard/page.tsx"
        end

        subgraph "API Layer"
            direction TB
            AuthRoute("NextAuth Route"):::server
            click AuthRoute "https://github.com/nahiddhasan/school-app/blob/main/src/app/api/[...nextauth]/route.ts"
            Actions("Business Logic Actions\n(src/lib/actions.ts,\npromoteStudent.action.ts,\nresult.action.ts)"):::server
            click Actions "https://github.com/nahiddhasan/school-app/blob/main/src/lib/actions.ts"
            click Actions "https://github.com/nahiddhasan/school-app/blob/main/src/lib/actions/promoteStudent.action.ts"
            click Actions "https://github.com/nahiddhasan/school-app/blob/main/src/lib/result.action.ts"
            FetchHelpers("Data Fetch Helpers"):::server
            click FetchHelpers "https://github.com/nahiddhasan/school-app/blob/main/src/lib/protectedDataFetch/*.data.ts"
        end

        subgraph "Middleware & Auth"
            direction TB
            Middleware("middleware.ts"):::server
            click Middleware "https://github.com/nahiddhasan/school-app/blob/main/src/middleware.ts"
            AuthConfig("auth.config.ts"):::server
            click AuthConfig "https://github.com/nahiddhasan/school-app/blob/main/src/auth.config.ts"
            AuthHelper("auth.ts"):::server
            click AuthHelper "https://github.com/nahiddhasan/school-app/blob/main/src/auth.ts"
            SessionProv("SessionProvider.tsx"):::server
            click SessionProv "https://github.com/nahiddhasan/school-app/blob/main/src/providers/SessionProvider.tsx"
        end

        subgraph "Data & Business Logic"
            direction TB
            PrismaClient("Prisma Client\n(src/app/generated/prisma/client.js)"):::server
            click PrismaClient "https://github.com/nahiddhasan/school-app/blob/main/src/app/generated/prisma/client.js"
            Connect("connect.ts"):::server
            click Connect "https://github.com/nahiddhasan/school-app/blob/main/src/lib/connect.ts"
            Zod("zodSchema.ts"):::server
            click Zod "https://github.com/nahiddhasan/school-app/blob/main/src/lib/zodSchema.ts"
        end
    end

    %% Persistence Layer
    subgraph "Persistence"
        direction TB
        Postgres("PostgreSQL DB\n(prisma/schema.prisma)"):::db
        click Postgres "https://github.com/nahiddhasan/school-app/blob/main/prisma/schema.prisma"
        Migrations("Prisma Migrations"):::db
        click Migrations "https://github.com/nahiddhasan/school-app/tree/main/prisma/migrations/**"
        FileStorage("File Storage\n(public/upload)"):::storage
        click FileStorage "https://github.com/nahiddhasan/school-app/tree/main/public/upload"
        Assets("Static Assets\n(public/assets)"):::storage
        click Assets "https://github.com/nahiddhasan/school-app/blob/main/public/assets/import_student.csv"
        click Assets "https://github.com/nahiddhasan/school-app/blob/main/public/assets/import_result.csv"
    end

    %% Infrastructure Layer
    subgraph "Dev & Prod Infra"
        direction TB
        Docker("Docker Compose"):::infra
        click Docker "https://github.com/nahiddhasan/school-app/blob/main/src/docker/docker-compose.yml"
        Vercel("Vercel Deployment"):::infra
    end

    %% Data Flows
    Browser --> UI
    UI --> Layout
    Browser --> SFPages
    Browser --> DBDashboard
    Browser --> AuthRoute
    UI --> Actions
    AuthRoute -->|session| Postgres
    Actions --> PrismaClient
    PrismaClient -->|read/write| Postgres
    Actions --> FileStorage
    FetchHelpers --> PrismaClient
    Middleware --> DBDashboard
    SessionProv --> DBDashboard
    Layout --> SessionProv

    %% Dev/Prod Connections
    Docker -.-> Postgres
    Docker -.-> PrismaClient
    Vercel -.-> PrismaClient
    Vercel -.-> Postgres

    %% Styles
    classDef frontend fill:#E3F2FD,stroke:#64B5F6,color:#0D47A1,stroke-width:1px;
    classDef server fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20,stroke-width:1px;
    classDef db fill:#FFF3E0,stroke:#FFA726,color:#E65100,stroke-width:1px;
    classDef storage fill:#FFF3E0,stroke:#FFB74D,color:#E65100,stroke-width:1px;
    classDef infra fill:#ECEFF1,stroke:#78909C,color:#263238,stroke-width:1px;
```
