# thevish04/caprep architecture

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

- Interactive diagram: https://gitdiagram.com/thevish04/caprep
- Repository: https://github.com/thevish04/caprep

## Overview

##### Main Components as Shown in the Project
- Frontend – Located in the “frontend” directory. It is a React-based single page application that manages user interfaces, routing (react-router-dom), state and rendering of components (e.g., Login, Register, AdminPanel, LandingPage, etc.), and utilities like API calling (apiUtils) and PDF generation.
- Backend – Located in the “backend” directory. It implements an Express server with various modularized components:
- Server Setup (server.js)
- Configuration (config/database.js) to connect (likely via Sequelize) to the database
- Models (UserModel.js and QuestionModel.js) representing the data entities
- Routes for handling different endpoints (authentication on auth.js, payment processing on payment.js, question data on questions.js)
- Middleware (authMiddleware.js) to handle request authentication and perhaps authorization
- Services (otpService.js and razorpayService.js) that encapsulate the business logic for OTP generation and payment processing.
- A "database" directory which may contain static data (e.g., verified_emails.json) or configuration related to SQLite3

- Within the Backend, illustrate internal interactions:
- The Express server (backend/server.js) uses middleware (authMiddleware) to protect routes.
- The routes call upon services (otpService, razorpayService) and interact with the data models (UserModel, QuestionModel).
- The database layer (config/database.js with Sequelize and SQLite3) connects to and manipulates database records, and may also leverage local JSON data (verified_emails.json) for verification or caching.
- On the Frontend side, show how high-level components are organized into pages (LandingPage, About, Contact, etc.) and reusable components (Navbar, DonationButton, etc.). Also include utility modules such as apiUtils for backend communication and pdfGenerator for creating PDFs, which might be used across several components.

##### Architectural Patterns and Design Principles
- Separation of concerns: The project cleanly separates frontend and backend.
- MVC-like structure in the backend: Models, routes (controllers), and services encapsulate distinct responsibilities.
- Modular design: Components in the frontend are organized by functionality (pages, components, assets, utils). Similarly, backend services and routes modularize business logic and API endpoints.
- RESTful API communication: The frontend communicates with the backend RESTfully, which is suggested by the dedicated routes for authentication, payments, and content (questions).

##### Additional Suggestions
- In the backend, mention that authentication is secured using bcrypt and JWT (as indicated in package.json) and that data validation is managed by Joi.
- Every component (frontend, backend, database, and external services) is clear with labels to not leave any ambiguity. It’s better to “over-separate” the components where it helps in understanding the dependencies and data flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend (React/Vite)"
        F1("Frontend App"):::frontend
        F2("Pages"):::frontend
        F3("Components"):::frontend
        F4("Utilities"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend (Express/Node.js)"
        B1("Server Setup"):::backend
        B2("Database Config"):::config
        B3("User Model"):::model
        B4("Question Model"):::model
        B5("Auth Route"):::route
        B6("Payment Route"):::route
        B7("Questions Route"):::route
        B8("Auth Middleware"):::middleware
        B9("OTP Service"):::service
        B10("Razorpay Service"):::service
        B11("Static Data(Verified Emails)"):::db
        B12("Database(SQLite3)"):::db
    end

    %% Frontend to Backend Communication
    F4 -->|"REST_API"| B1

    %% Backend Internal Connections
    B1 -->|"routes"| B5
    B1 -->|"routes"| B6
    B1 -->|"routes"| B7

    %% Middleware usage by Routes
    B5 -->|"use"| B8
    B6 -->|"use"| B8
    B7 -->|"use"| B8

    %% Routes interacting with Models and Services
    B5 -->|"calls"| B9
    B5 -->|"queries"| B3
    B6 -->|"calls"| B10
    B7 -->|"queries"| B4

    %% Models use database configuration and connection
    B3 -->|"config"| B2
    B4 -->|"config"| B2
    B2 -->|"connects"| B12

    %% Route using static data
    B5 -->|"verifies"| B11

    %% Click Events
    click F1 "https://github.com/thevish04/caprep/tree/master/frontend/"
    click F2 "https://github.com/thevish04/caprep/tree/master/frontend/src/pages"
    click F3 "https://github.com/thevish04/caprep/tree/master/frontend/src/components"
    click F4 "https://github.com/thevish04/caprep/tree/master/frontend/src/utils"
    click B1 "https://github.com/thevish04/caprep/blob/master/backend/server.js"
    click B2 "https://github.com/thevish04/caprep/blob/master/backend/config/database.js"
    click B3 "https://github.com/thevish04/caprep/blob/master/backend/models/UserModel.js"
    click B4 "https://github.com/thevish04/caprep/blob/master/backend/models/QuestionModel.js"
    click B5 "https://github.com/thevish04/caprep/blob/master/backend/routes/auth.js"
    click B6 "https://github.com/thevish04/caprep/blob/master/backend/routes/payment.js"
    click B7 "https://github.com/thevish04/caprep/blob/master/backend/routes/questions.js"
    click B8 "https://github.com/thevish04/caprep/blob/master/backend/middleware/authMiddleware.js"
    click B9 "https://github.com/thevish04/caprep/blob/master/backend/services/otpService.js"
    click B10 "https://github.com/thevish04/caprep/blob/master/backend/services/razorpayService.js"
    click B11 "https://github.com/thevish04/caprep/blob/master/backend/database/verified_emails.json"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1565C0,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef config fill:#B2EBF2,stroke:#0097A7,stroke-width:2px;
    classDef model fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef route fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef middleware fill:#CFD8DC,stroke:#546E7A,stroke-width:2px;
    classDef service fill:#E1BEE7,stroke:#6A1B9A,stroke-width:2px;
    classDef db fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
