# vibhorsharma0053/virus architecture

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

- Interactive diagram: https://gitdiagram.com/vibhorsharma0053/virus
- Repository: https://github.com/vibhorsharma0053/virus

## Overview

##### Project type and purpose
- This is a full‑stack web application (“Virus”) built during a hackathon.
- Purpose: Allow administrators/teachers to post assignments, students to fetch and submit assignments, and view results. It supports offline data with PouchDB on the client.

##### File structure
- client/ – React + Vite frontend
- src/components, src/pages for UI
- src/pouchdb for offline storage logic
- axios for HTTP, react-router-dom for routing, tailwindcss for styling
- server/ – Node.js + Express backend
- routes/, controllers/, models/ (MVC pattern)
- middleware/ for auth or request preprocessing
- db.js connects to MongoDB (via Mongoose)
- Deployment/config files: .env (DB URI, secrets), package.json in each folder

##### README for additional insights
- Lists API endpoints (auth, assignment, result)
- Specifies external dependencies (MongoDB, PouchDB, Axios)

##### Main components
a. Frontend (React App)
- UI pages: Login/SignUp, StudentDashboard, TeacherDashboard, Assignment pages
- Offline store: PouchDB
- HTTP client: Axios
b. Backend (Express Server)
- Routing layer (authRoutes, assignmentRoutes, resultRoutes)
- Controllers (authController, assignmentController, resultController)
- Models (userModel, assignmentModel, resultModel)
- Middleware (auth guard, error handler)
c. Database
- MongoDB (hosted externally or locally)
d. External / Cross‑cutting
- Environment config (.env)
- Static file serving for client (if served by server in production)

##### Relationships and data flows
1. User (Teacher/Student) interacts with React UI in browser
2. React App reads/writes local PouchDB for offline mode
3. On network availability, Axios issues HTTP requests to Express API at /api/*
4. Express middleware authenticates the request
5. Express routes delegate to Controllers
6. Controllers use Models to query/update MongoDB
7. Responses flow back via JSON to React, which updates UI & PouchDB

##### Architectural patterns and design principles
- MVC pattern on the backend (routes → controllers → models)
- Separation of concerns: UI vs. data store vs. API
- Offline‑first capabilities with PouchDB sync
- RESTful API design
- Environment‐based configuration

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Browser Layer
    subgraph "Browser" 
        style Browser fill:#E0F7FA,stroke:#006064
        subgraph "React App (Vite, Tailwind, Router, Axios)" 
            style ReactApp fill:#B3E5FC,stroke:#0277BD
            Login["Login Page"] 
            SignUp["SignUp Page"] 
            Home["Home Page"] 
            Account["Account Page"] 
            ThankYou["Thank You Page"] 
            subgraph "Student Pages"
                StudentDashboard["Student Dashboard"] 
                StudentTest["Student Test Page"] 
            end
            subgraph "Teacher Pages"
                TeacherDashboard["Teacher Dashboard"] 
            end
            subgraph "Components"
                CreateAssignment["Create Assignment Form"] 
                NavBar["Navigation Bar"] 
            end
            PouchDB["Local Store: PouchDB"] 
            Axios["HTTP Client: Axios"] 
        end
    end

    %% Server Layer
    subgraph "Server (Node.js/Express)" 
        style Server fill:#E8F5E9,stroke:#2E7D32
        EnvConfig["Environment Config (.env)"] 
        ServerEntry["Backend Entry Point"] 
        subgraph "Routing Layer" 
            AuthRoutes["Auth Routes"] 
            AssignmentRoutes["Assignment Routes"] 
        end
        subgraph "Controllers"
            AuthController["Auth Controller"] 
            AssignmentController["Assignment Controller"] 
            ResultController["Result Controller"] 
        end
        subgraph "Models"
            UserModel["User Model"] 
            AssignmentModel["Assignment Model"] 
            ResultModel["Result Model"] 
        end
        Middleware["Middleware (Auth Guard / Error Handler)"] 
        Utils["Backend Utilities"] 
    end

    %% Database
    MongoDB["MongoDB Database"] 

    %% Connections
    Login -->|"/api/auth/login"| AuthRoutes
    SignUp -->|"/api/auth/signup"| AuthRoutes
    Home -->|GET /api/assignment/getAll| AssignmentRoutes
    CreateAssignment -->|POST /api/assignment/create| AssignmentRoutes
    StudentDashboard -->|GET /api/result/getByStudent| ResultController
    StudentTest -->|POST /api/result/submit| ResultController
    TeacherDashboard -->|GET /api/assignment/getAll| AssignmentRoutes

    ReactApp -->|Reads/Writes| PouchDB
    ReactApp -->|HTTP Requests| Axios
    Axios -->|calls| AuthRoutes
    Axios -->|calls| AssignmentRoutes
    Axios -->|calls| ResultController

    AuthRoutes -->|delegates| AuthController
    AssignmentRoutes -->|delegates| AssignmentController
    AssignmentRoutes -->|delegates| ResultController
    AuthController -->|uses| UserModel
    AssignmentController -->|uses| AssignmentModel
    ResultController -->|uses| ResultModel
    AssignmentController -->|DB Ops| MongoDB
    AuthController -->|DB Ops| MongoDB
    ResultController -->|DB Ops| MongoDB

    ServerEntry --> EnvConfig
    ServerEntry --> AuthRoutes
    ServerEntry --> AssignmentRoutes
    ServerEntry --> ResultController
    ServerEntry --> Middleware
    ServerEntry --> Utils
    UserModel --> MongoDB
    AssignmentModel --> MongoDB
    ResultModel --> MongoDB

    %% Click Events
    click Login "https://github.com/vibhorsharma0053/virus/blob/main/client/src/pages/Login.jsx"
    click SignUp "https://github.com/vibhorsharma0053/virus/blob/main/client/src/pages/SignUp.jsx"
    click Home "https://github.com/vibhorsharma0053/virus/blob/main/client/src/pages/Home.jsx"
    click Account "https://github.com/vibhorsharma0053/virus/blob/main/client/src/pages/Account.jsx"
    click ThankYou "https://github.com/vibhorsharma0053/virus/blob/main/client/src/pages/ThankYou.jsx"
    click StudentDashboard "https://github.com/vibhorsharma0053/virus/blob/main/client/src/student/StudentDashboard.jsx"
    click StudentTest "https://github.com/vibhorsharma0053/virus/blob/main/client/src/student/StudentTest.jsx"
    click TeacherDashboard "https://github.com/vibhorsharma0053/virus/blob/main/client/src/teacher/TeacherDashboard.jsx"
    click CreateAssignment "https://github.com/vibhorsharma0053/virus/blob/main/client/src/components/createAssignment.jsx"
    click NavBar "https://github.com/vibhorsharma0053/virus/blob/main/client/src/components/navbar.jsx"
    click PouchDB "https://github.com/vibhorsharma0053/virus/tree/main/client/src/pouchdb"
    click Axios "https://github.com/vibhorsharma0053/virus/blob/main/client/src/utils/1.jsx"
    click ReactApp "https://github.com/vibhorsharma0053/virus/tree/main/client/src"
    click ServerEntry "https://github.com/vibhorsharma0053/virus/blob/main/server/server.js"
    click EnvConfig "https://github.com/vibhorsharma0053/virus/blob/main/server/.env"
    click AuthRoutes "https://github.com/vibhorsharma0053/virus/blob/main/server/routes/authRoutes.js"
    click AssignmentRoutes "https://github.com/vibhorsharma0053/virus/blob/main/server/routes/assignmentRoutes.js"
    click AuthController "https://github.com/vibhorsharma0053/virus/blob/main/server/controllers/authController.js"
    click AssignmentController "https://github.com/vibhorsharma0053/virus/blob/main/server/controllers/assignmentContoller.js"
    click ResultController "https://github.com/vibhorsharma0053/virus/blob/main/server/controllers/resultController.js"
    click UserModel "https://github.com/vibhorsharma0053/virus/blob/main/server/models/userModel.js"
    click AssignmentModel "https://github.com/vibhorsharma0053/virus/blob/main/server/models/assignmentModel.js"
    click ResultModel "https://github.com/vibhorsharma0053/virus/blob/main/server/models/resultModel.js"
    click Middleware "https://github.com/vibhorsharma0053/virus/blob/main/server/middleware/1.js"
    click Utils "https://github.com/vibhorsharma0053/virus/blob/main/server/utils/1.js"
    click Server "https://github.com/vibhorsharma0053/virus/blob/main/server/package.json"
    click README "https://github.com/vibhorsharma0053/virus/blob/main/README.md"

    %% Styles
    classDef frontend fill:#B3E5FC,stroke:#0277BD,color:#000
    classDef backend fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef database fill:#FFE0B2,stroke:#EF6C00,color:#000
    class Login,SignUp,Home,Account,ThankYou,StudentDashboard,StudentTest,TeacherDashboard,CreateAssignment,NavBar,PouchDB,Axios frontend
    class AuthRoutes,AssignmentRoutes,AuthController,AssignmentController,ResultController,UserModel,AssignmentModel,ResultModel,Middleware,Utils,ServerEntry,EnvConfig backend
    class MongoDB database
```
