# elliott-chong/quizmify architecture

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

- Interactive diagram: https://gitdiagram.com/elliott-chong/quizmify
- Repository: https://github.com/elliott-chong/quizmify

## Overview

##### Main System Components

a) Frontend Layer:
- Next.js Application (App Router architecture)
- UI Components (/src/components)
- Client-side State Management
- Theme System

b) Backend Layer:
- Next.js API Routes (/src/app/api)
- Authentication System (NextAuth.js)
- Database Layer (Prisma ORM)
- GPT Integration (/src/lib/gpt.ts)

**┌─ Client Layer ─────────────────────┐**
- Pages (Dashboard, Quiz, History) │
- UI Components                    │
- Form Schemas                     │
- ┘

**┌─ API Routes ──────────────────┐**
- Auth Routes                 │
- Game Routes                 │
- Question Routes             │
- ┘

**┌─ Services ───────────────┐**
- Database (Prisma)      │
- GPT Integration        │
- Authentication         │
- ┘

##### Component Relationships

- User authentication flow
- Quiz creation and submission
- Question generation via GPT
- Data persistence flow

##### Specific Implementation Details

- Next.js 13+ App Router architecture
- Prisma as ORM
- NextAuth.js for authentication
- Tailwind CSS for styling
- GPT integration for question generation

##### Key Features to Highlight

Application features:
- Multiple quiz types (MCQ, Open-ended)
- Real-time scoring
- History tracking
- Statistics and analytics
- User authentication

##### Data Flow Patterns

Primary data flows:
##### Quiz Taking → Scoring → Statistics

**[User Interface Layer]**
- ↕
**[Next.js App Router]**
- ↕
**[API Routes Layer]**
- ↕
**[Service Layer (Auth, GPT, DB)]**

Important Considerations:

##### Demonstrate GPT service integration

This system design should effectively communicate the application's architecture while maintaining the appropriate level of detail for a principal software engineer to understand the complete system flow.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[UI Components]
        Dashboard[Dashboard]
        Quiz[Quiz Interface]
        Stats[Statistics View]
        Forms[Form Components]
    end

    subgraph APILayer
        Auth[Authentication API]
        GameAPI[Game API]
        QuestionsAPI[Questions API]
        AnswerAPI[Answer Check API]
    end

    subgraph Services
        DB[(Database)]
        GPT[GPT Service]
        AuthService[Auth Service]
    end

    %% Client Layer Details
    UI --> Dashboard
    UI --> Quiz
    UI --> Stats
    UI --> Forms

    %% API Layer Connections
    Dashboard --> GameAPI
    Quiz --> QuestionsAPI
    Quiz --> AnswerAPI
    Stats --> GameAPI
    Forms --> GameAPI

    %% Service Layer Connections
    GameAPI --> DB
    QuestionsAPI --> GPT
    QuestionsAPI --> DB
    AnswerAPI --> DB
    Auth --> AuthService
    AuthService --> DB

    %% Component Mappings with Click Events
    click Auth "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/api/auth/[...nextauth]/route.ts"
    click AuthService "https://github.com/Elliott-Chong/quizmify/blob/main/src/lib/nextauth.ts"
    click DB "https://github.com/Elliott-Chong/quizmify/blob/main/src/lib/db.ts"
    click GPT "https://github.com/Elliott-Chong/quizmify/blob/main/src/lib/gpt.ts"
    click UI "https://github.com/Elliott-Chong/quizmify/tree/main/src/components/ui"
    click Quiz "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/play/mcq/[gameId]/page.tsx"
    click Forms "https://github.com/Elliott-Chong/quizmify/blob/main/src/components/forms/QuizCreation.tsx"
    click Dashboard "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/dashboard/page.tsx"
    click Stats "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/statistics/[gameId]/page.tsx"
    click GameAPI "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/api/game/route.ts"
    click QuestionsAPI "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/api/questions/route.ts"
    click AnswerAPI "https://github.com/Elliott-Chong/quizmify/blob/main/src/app/api/checkAnswer/route.ts"

    %% Styling
    classDef client fill:#a8dadc,stroke:#457b9d
    classDef api fill:#457b9d,stroke:#1d3557
    classDef service fill:#e63946,stroke:#1d3557
    classDef database fill:#f1faee,stroke:#1d3557

    class UI,Dashboard,Quiz,Stats,Forms client
    class Auth,GameAPI,QuestionsAPI,AnswerAPI api
    class GPT,AuthService service
    class DB database

    %% Legend
    subgraph Legend
        Client_L[Client Components]:::client
        API_L[API Layer]:::api
        Service_L[Services]:::service
        DB_L[(Database)]:::database
    end
```
