# haider786x/sih architecture

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

- Interactive diagram: https://gitdiagram.com/haider786x/sih
- Repository: https://github.com/haider786x/sih

## Overview

##### Project Type & Purpose
- This is a full-stack web application:
– Frontend: React SPA built with Vite & Tailwind
– Backend: Node.js + Express API
– Purpose: allow users to register/login, create and take quizzes, serve quotes.

##### High-Level Architecture Components
A. Client (Browser)
– React (frontend/src)
– Components (Login, Register, Dashboard, Quiz, etc.)
– AuthContext for state management
– api.js service to call backend endpoints
B. API Server
– app.js configuration with Express routes
– Middleware layer (auth.js) for JWT or session validation
– Models (User, Quiz, Quote)
C. Database
– External database (e.g., MongoDB, PostgreSQL – configured via Backend/.env)
D. (Optional) External Services
– Third-party analytics or logging

##### Interaction & Data Flow
- Browser sends HTTP(S) requests (via api.js) → Express routes
- auth.js middleware validates tokens or sessions
- Request handlers use Mongoose/ORM on models to read/write DB
- JSON responses flow back to React, updating UI via Context or component state

##### Architectural Patterns
- MVC-like separation on backend (routes → controllers → models)
- Component-based UI on frontend
- Context API for cross-component state (authentication)
- Single-Page App talking to RESTful API

[User’s Browser] → [API Server] → [Database]
– UI Components (Login, Quiz, Dashboard, etc.)
– AuthContext & Services (api.js)
– Express App (app.js)
– Middleware Layer (middleware/auth.js)
– Model Layer (User, Quiz, Quote)

##### Relationships & Flow
– From UI Components → api.js → Express endpoints (/login, /quiz, /quotes)
– From Express → Middleware → Controller logic → Models → Database

##### Final Checklist
[ ] All main components identified and labeled
[ ] Sub-component breakdown for key layers (UI, Auth, Models)
[ ] Notes on any external services or future extensions

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Layer
    subgraph "User's Browser"
        direction TB
        Login["Login"]:::frontend
        Register["Register"]:::frontend
        Dashboard["Dashboard"]:::frontend
        QuizComp["Quiz"]:::frontend
        CreateQuiz["CreateQuiz"]:::frontend
        Profile["Profile"]:::frontend
        StudentProgress["StudentProgress"]:::frontend
        LoginType["LoginType"]:::frontend
        AuthContext["AuthContext"]:::frontend
        APIService["api.js (Service)"]:::frontend
        AppEntry["App.jsx"]:::frontend
        ViteConfig["vite.config.js"]:::frontend
        TailwindConfig["tailwind.config.js"]:::frontend
        HTMLTemplate["index.html"]:::frontend
    end

    %% Backend Layer
    subgraph "API Server"
        direction TB
        ExpressApp["Express App (app.js)"]:::backend
        AuthMiddleware["Auth Middleware (auth.js)"]:::middleware
        subgraph "Models"
            direction TB
            UserModel["User Model"]:::model
            QuizModel["Quiz Model"]:::model
            QuoteModel["Quote Model"]:::model
        end
        EnvConfig[".env (Config)"]:::backend
    end

    %% Database Layer
    subgraph "Database"
        MongoDB["MongoDB"]:::database
    end

    %% Data Flow Arrows
    Login -->|HTTP requests| APIService
    Register -->|HTTP requests| APIService
    Dashboard -->|HTTP requests| APIService
    QuizComp -->|HTTP requests| APIService
    CreateQuiz -->|HTTP requests| APIService
    Profile -->|HTTP requests| APIService
    StudentProgress -->|HTTP requests| APIService
    LoginType -->|HTTP requests| APIService
    AuthContext -->|uses| APIService

    APIService -->|REST API calls| ExpressApp
    ExpressApp -->|auth checks| AuthMiddleware
    AuthMiddleware -->|validates| ExpressApp

    ExpressApp -->|CRUD operations| UserModel
    ExpressApp -->|CRUD operations| QuizModel
    ExpressApp -->|CRUD operations| QuoteModel

    UserModel -->|read/write| MongoDB
    QuizModel -->|read/write| MongoDB
    QuoteModel -->|read/write| MongoDB

    MongoDB -->|responses| UserModel
    MongoDB -->|responses| QuizModel
    MongoDB -->|responses| QuoteModel

    UserModel -->|data| ExpressApp
    QuizModel -->|data| ExpressApp
    QuoteModel -->|data| ExpressApp

    ExpressApp -->|JSON responses| APIService
    APIService -->|updates UI| Dashboard
    APIService -->|updates UI| QuizComp
    APIService -->|updates UI| Profile
    APIService -->|updates UI| StudentProgress
    APIService -->|updates UI| Login
    APIService -->|updates UI| Register

    %% Click Events
    click Login "https://github.com/haider786x/sih/blob/main/frontend/src/components/Login.jsx"
    click Register "https://github.com/haider786x/sih/blob/main/frontend/src/components/Register.jsx"
    click Dashboard "https://github.com/haider786x/sih/blob/main/frontend/src/components/Dashboard.jsx"
    click QuizComp "https://github.com/haider786x/sih/blob/main/frontend/src/components/Quiz.jsx"
    click CreateQuiz "https://github.com/haider786x/sih/blob/main/frontend/src/components/CreateQuiz.jsx"
    click Profile "https://github.com/haider786x/sih/blob/main/frontend/src/components/Profile.jsx"
    click StudentProgress "https://github.com/haider786x/sih/blob/main/frontend/src/components/StudentProgress.jsx"
    click LoginType "https://github.com/haider786x/sih/blob/main/frontend/src/components/LoginType.jsx"
    click AuthContext "https://github.com/haider786x/sih/blob/main/frontend/src/contexts/AuthContext.jsx"
    click APIService "https://github.com/haider786x/sih/blob/main/frontend/src/services/api.js"
    click AppEntry "https://github.com/haider786x/sih/blob/main/frontend/src/App.jsx"
    click ViteConfig "https://github.com/haider786x/sih/blob/main/frontend/vite.config.js"
    click TailwindConfig "https://github.com/haider786x/sih/blob/main/frontend/tailwind.config.js"
    click HTMLTemplate "https://github.com/haider786x/sih/blob/main/frontend/index.html"
    click ExpressApp "https://github.com/haider786x/sih/blob/main/Backend/app.js"
    click AuthMiddleware "https://github.com/haider786x/sih/blob/main/Backend/middleware/auth.js"
    click UserModel "https://github.com/haider786x/sih/blob/main/Backend/models/User.js"
    click QuizModel "https://github.com/haider786x/sih/blob/main/Backend/models/Quiz.js"
    click QuoteModel "https://github.com/haider786x/sih/blob/main/Backend/models/Quote.js"
    click EnvConfig "https://github.com/haider786x/sih/blob/main/Backend/.env"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef model fill:#FDFD96,stroke:#333,stroke-width:1px
    classDef middleware fill:#FFB6C1,stroke:#333,stroke-width:1px
    classDef database fill:#A9A9A9,stroke:#333,stroke-width:1px
```
