# aashvikothari/quizportal architecture

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

- Interactive diagram: https://gitdiagram.com/aashvikothari/quizportal
- Repository: https://github.com/aashvikothari/quizportal

## Overview

##### Main Components
- Frontend Client: A React/Redux-based application with components, pages (for both Users and Admins), and UI themes (using Ant Design). Highlight the directory structure that shows screens for login, registration, exam writing (with timer), results viewing, and profile management.
- Backend Server: An Express/Node.js application responsible for business logic and API endpoints. It contains controllers (exam, report, user), models (exam, question, report, user), routes, and middlewares (e.g., JWT-based authentication).
- Database: A MongoDB database managed via Mongoose. It handles complex queries, schema validations, and storage for users, exams, questions, reports, and results.
- External Services (if applicable): Although not explicitly mentioned, consider any additional integrations like email services (for notifications) or third-party analytics if they are planned.

##### Relationships and Data Flow
- The Authentication Middleware plays a critical role by securing endpoints; thus, indicate its presence between the client’s request and the controller logic.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The project clearly separates UI (frontend) from API and business logic (backend), which in turn is modular with controllers, models, and routes.
- Security: JWT Authentication along with password hashing, which should be highlighted as an essential cross-cutting concern in the architecture.
- Real-Time/Live Data: Consider indicating the real-time updates and timer functionalities in the exam module (perhaps using state management on the client side via Redux).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Block
    subgraph "Frontend (React + Redux + Ant Design)"
        %% User Pages Subgraph
        subgraph "User Pages"
            Login["Login Page"]:::frontend
            Register["Register Page"]:::frontend
            Exam["Exam Writing & Timer"]:::frontend
            ExamInst["Exam Instructions"]:::frontend
            Results["Results Viewing"]:::frontend
            Profile["Profile Management"]:::frontend
        end
        %% Admin Pages Subgraph
        subgraph "Admin Pages"
            ExamMgmt["Exam Management"]:::frontend
            AddEditExam["Add/Edit Exam"]:::frontend
            AddEditQ["Add/Edit Question"]:::frontend
            ReportMgmt["Report Management"]:::frontend
        end
        Redux["Redux Store"]:::frontend
        Apicalls["API Calls"]:::frontend
    end

    %% Backend Block
    subgraph "Backend (Node.js + Express)"
        Server["Server Entry (server.js)"]:::backend
        subgraph "Routes"
            ExamRoutes["Exam Routes"]:::backend
            ReportRoutes["Report Routes"]:::backend
            UserRoutes["User Routes"]:::backend
        end
        subgraph "Controllers"
            ExamControllers["Exam Controllers"]:::backend
            ReportController["Report Controller"]:::backend
            UserControllers["User Controllers"]:::backend
        end
        Middleware["JWT Auth Middleware"]:::backend
        subgraph "Models"
            ExamModel["Exam Model"]:::backend
            QuestionModel["Question Model"]:::backend
            ReportModel["Report Model"]:::backend
            UserModel["User Model"]:::backend
        end
        DBConfig["DB Config"]:::backend
    end

    %% Database Block
    Database["Database (MongoDB)"]:::database

    %% Connections between Frontend and Backend
    Apicalls -->|"RESTAPICalls"| ExamRoutes
    Apicalls -->|"RESTAPICalls"| ReportRoutes
    Apicalls -->|"RESTAPICalls"| UserRoutes
    Redux --> Apicalls

    %% Connections within Backend
    Server --> ExamRoutes
    Server --> ReportRoutes
    Server --> UserRoutes

    ExamRoutes --> ExamControllers
    ReportRoutes --> ReportController
    UserRoutes --> UserControllers

    %% Middleware involvement before controllers (illustrative)
    ExamRoutes --> Middleware
    ReportRoutes --> Middleware
    UserRoutes --> Middleware
    Middleware --> ExamControllers
    Middleware --> ReportController
    Middleware --> UserControllers

    %% Controllers to Models
    ExamControllers --> ExamModel
    ExamControllers --> QuestionModel
    ReportController --> ReportModel
    UserControllers --> UserModel

    %% Models interaction with Database
    ExamModel -->|"CRUD"| Database
    QuestionModel -->|"CRUD"| Database
    ReportModel -->|"CRUD"| Database
    UserModel -->|"CRUD"| Database

    %% Backend DBConfig to Database
    DBConfig --> Database

    %% Admin Pages additional linking
    ExamMgmt --> AddEditExam
    ExamMgmt --> AddEditQ

    %% Click Events for Frontend Components
    click Login "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/common/Login/index.js"
    click Register "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/common/Register/index.js"
    click Exam "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/user/WriteExam/index.js"
    click ExamInst "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/user/WriteExam/Instructions.js"
    click Results "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/user/Reports/index.js"
    click Profile "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/user/Profile/index.js"
    click ExamMgmt "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/admin/Exams/index.js"
    click AddEditExam "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/admin/Exams/AddEditExam.js"
    click AddEditQ "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/admin/Exams/AddEditQuestion.js"
    click ReportMgmt "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/pages/admin/Reports/index.js"
    click Redux "https://github.com/aashvikothari/quizportal/blob/master/frontend/src/redux/store.js"
    click Apicalls "https://github.com/aashvikothari/quizportal/tree/master/frontend/src/apicalls"

    %% Click Events for Backend Components
    click Server "https://github.com/aashvikothari/quizportal/blob/master/backend/server.js"
    click ExamRoutes "https://github.com/aashvikothari/quizportal/blob/master/backend/routes/examRoutes.js"
    click ReportRoutes "https://github.com/aashvikothari/quizportal/blob/master/backend/routes/reportRoutes.js"
    click UserRoutes "https://github.com/aashvikothari/quizportal/blob/master/backend/routes/userRoutes.js"
    click ExamControllers "https://github.com/aashvikothari/quizportal/blob/master/backend/controllers/examControllers.js"
    click ReportController "https://github.com/aashvikothari/quizportal/blob/master/backend/controllers/reportController.js"
    click UserControllers "https://github.com/aashvikothari/quizportal/blob/master/backend/controllers/userControllers.js"
    click ExamModel "https://github.com/aashvikothari/quizportal/blob/master/backend/models/examModel.js"
    click QuestionModel "https://github.com/aashvikothari/quizportal/blob/master/backend/models/questionModel.js"
    click ReportModel "https://github.com/aashvikothari/quizportal/blob/master/backend/models/reportModel.js"
    click UserModel "https://github.com/aashvikothari/quizportal/blob/master/backend/models/userModel.js"
    click Middleware "https://github.com/aashvikothari/quizportal/blob/master/backend/middlewares/authMiddleware.js"
    click DBConfig "https://github.com/aashvikothari/quizportal/blob/master/backend/config/dbConfig.js"

    %% Styles
    classDef frontend fill:#dae8fc,stroke:#6c8ebf,stroke-width:2px;
    classDef backend fill:#f8cecc,stroke:#b85450,stroke-width:2px;
    classDef database fill:#d5e8d4,stroke:#82b366,stroke-width:2px;
```
