# patelhitarth08/preppanda-next architecture

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

- Interactive diagram: https://gitdiagram.com/patelhitarth08/preppanda-next
- Repository: https://github.com/patelhitarth08/preppanda-next

## Overview

##### Project type and purpose
- This is a full‑stack Next.js web application for creating, administering, taking, and monitoring assessments (quizzes/tests) within user groups.
- It provides user authentication, group management, custom/given assessments, real‑time monitoring, and statistics dashboards.

##### File structure
- Top‑level folders:
– pages/ – Next.js pages (both UI routes and API routes under pages/api)
– components/ – React UI components (Assessment, Group, Monitor, Charts, Profile, Panda, etc.)
– models/ – Data models (assessment, question, group, user, and associated stats)
– utils/ – Helper functions (DB connection, SHA key generator)
– public/ – Static assets (fonts, images, JSON data)
– styles/ – Global CSS (Tailwind config, PostCSS)
- API routes follow RESTful patterns: /api/assessment, /api/question, /api/group, /api/stats, /api/user.
- Config/build: next.config.js, tsconfig.json, tailwind.config.ts, postcss.config.js, package.json.

##### Cross‑reference the README
- Confirms a Create‑Next‑App scaffold with Next.js pages and API routes.

a. Main components:
– Client/browser (React UI in pages/*.tsx plus components/)
– Next.js Server (server‑side Next.js engine and serverless functions for API routes)
– Authentication layer (NextAuth via pages/api/auth/[...nextauth].ts)
– Database (MongoDB or similar, connected via utils/connectDB.ts)
– Data models (collections for user, group, assessment, question, stats)
– External services (OAuth providers, if any; hosting on Vercel)
– Static assets hosting (public/ folder served by Next.js)

b. Relationships and data flows:
– User → Browser UI → Next.js page/API route
– API route → utils/connectDB → Database → models → returns JSON
– UI submits forms (create/join group, create assessment, answer questions) → API → DB
– Monitoring UI polls/subscribes to timer/events (via API)
– Stats UI queries aggregated stats endpoints under /api/stats
– Authentication flow: Browser ↔ NextAuth serverless endpoint ↔ external OAuth/DB

c. Architectural patterns/design principles:
– Serverless functions (Next.js API routes) encapsulating back‑end logic
– MVC‑ish separation: pages/views call service layer (API routes) which use models for DB
– Component‑based UI (React functional components + Tailwind CSS)
– RESTful endpoints for CRUD operations on assessments, questions, groups, stats
– Reusable utility modules for DB connection and security (generateSHAKey)

d. Key technologies/frameworks/libraries:
– Next.js (React framework with SSR/SSG and API routes)
– React + TypeScript for UI
– Tailwind CSS for styling
– next-auth for authentication
– Chart.js (via BarChart, DoughnutChart components)
– Mongoose or native MongoDB driver (implied by connectDB and models)
– Vercel (deployment platform)

##### Detailed capture of essential elements
- Break the backend into sub‑components:
– Auth API
– Assessment API
– Question API
– Group API
– Stats API
– Utility modules (DB connector, SHA generator)
- Models layer as part of the DB access subsystem.
- Config files and static assets as ancillary elements (bottom or side).
- Endpoint and major UI page is reflected to show full coverage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (Browser UI)"
        pages["pages/*.tsx"]:::frontend
        components["components/"]:::frontend
    end

    subgraph "Backend (Next.js Serverless/API)"
        authAPI["Auth API\npages/api/auth/[...nextauth].ts"]:::backend
        assessAPI["Assessment API\npages/api/assessment"]:::backend
        questionAPI["Question API\npages/api/question"]:::backend
        groupAPI["Group API\npages/api/group"]:::backend
        statsAPI["Stats API\npages/api/stats"]:::backend
        userAPI["User API\npages/api/user/[userId].ts"]:::backend
        utilsConnect["DB Connection\nutils/connectDB.ts"]:::backend
        utilsSHA["SHA Generator\nutils/generateSHAKey.ts"]:::backend
        models["Data Models\nmodels/"]:::backend
    end

    DB["MongoDB Database"]:::db
    External["OAuth Providers"]:::external
    Vercel["Vercel Hosting"]:::external
    Public["public/ (Static Assets)"]:::external
    Config["Global Config & Styles"]:::external

    pages -->|uses API| authAPI
    pages -->|uses API| assessAPI
    pages -->|uses API| questionAPI
    pages -->|uses API| groupAPI
    pages -->|uses API| statsAPI
    pages -->|uses API| userAPI
    components -->|renders UI| pages

    authAPI -->|connects via| utilsConnect
    assessAPI -->|connects via| utilsConnect
    questionAPI -->|connects via| utilsConnect
    groupAPI -->|connects via| utilsConnect
    statsAPI -->|connects via| utilsConnect
    userAPI -->|connects via| utilsConnect

    utilsConnect -->|reads/writes| DB
    models -->|schema definitions| DB

    authAPI <-->|auth handshake| External
    pages -->|serves static| Public

    pages -->|deployed on| Vercel
    authAPI -->|deployed on| Vercel
    assessAPI -->|deployed on| Vercel
    questionAPI -->|deployed on| Vercel
    groupAPI -->|deployed on| Vercel
    statsAPI -->|deployed on| Vercel
    userAPI -->|deployed on| Vercel

    Config -->|applies styles| pages
    Config -->|applies settings| authAPI

    click pages "https://github.com/patelhitarth08/preppanda-next/tree/main/pages/"
    click components "https://github.com/patelhitarth08/preppanda-next/tree/main/components/"
    click authAPI "https://github.com/patelhitarth08/preppanda-next/blob/main/pages/api/auth/[...nextauth].ts"
    click assessAPI "https://github.com/patelhitarth08/preppanda-next/tree/main/pages/api/assessment"
    click questionAPI "https://github.com/patelhitarth08/preppanda-next/tree/main/pages/api/question"
    click groupAPI "https://github.com/patelhitarth08/preppanda-next/tree/main/pages/api/group"
    click statsAPI "https://github.com/patelhitarth08/preppanda-next/tree/main/pages/api/stats"
    click userAPI "https://github.com/patelhitarth08/preppanda-next/blob/main/pages/api/user/[userId].ts"
    click utilsConnect "https://github.com/patelhitarth08/preppanda-next/blob/main/utils/connectDB.ts"
    click utilsSHA "https://github.com/patelhitarth08/preppanda-next/blob/main/utils/generateSHAKey.ts"
    click models "https://github.com/patelhitarth08/preppanda-next/tree/main/models/"
    click Public "https://github.com/patelhitarth08/preppanda-next/tree/main/public/"
    click Config "https://github.com/patelhitarth08/preppanda-next/blob/main/next.config.js"

    classDef frontend fill:#D0E8FF,stroke:#003366
    classDef backend fill:#D4F5D4,stroke:#006600
    classDef db fill:#FFE0B2,stroke:#E65100
    classDef external fill:#E0E0E0,stroke:#424242
```
