# gaurang1404/campuschat architecture

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

- Interactive diagram: https://gitdiagram.com/gaurang1404/campuschat
- Repository: https://github.com/gaurang1404/campuschat

## Overview

##### Project Type and Purpose
- CampusCHAT is a full-stack College ERP software that manages entities such as departments, courses, faculty, students, and attendance. The project targets a multi-role usage scenario (admin, faculty, student) while streamlining academic processes like attendance tracking and performance monitoring.
- The README describes key features such as a dashboard for each role, data visualizations, and calendar UIs, while the file tree clearly separates the frontend and backend components.

##### Analyzing the File Structure
- There are two top-level directories: “backend” and “frontend.”
- The “backend” directory contains configuration (db.js), controllers (admin, attendance, course, etc.), middlewares (auth, rate limiting), models (MongoDB models for various entities), routes (mapping endpoints to controllers), and a service for OpenAI integration.
- The “frontend” directory is organized like a typical React project using Vite. It is split into role-specific subcomponents (admin, faculty, student, home) and shared UI components. In addition, it includes Redux for state management and Tailwind CSS for styling.
- This structure suggests a layered architecture in the backend and a component-based architecture in the frontend, representing a clean separation of concerns.

##### Main Components and Their Relationships
a. Backend Components:
- API Server: Built on Node.js with Express.js which handles incoming HTTP requests.
- Controllers and Routes: Each business domain (attendance, students, courses, etc.) has corresponding controllers and routes.
- Models: Define data schemas for MongoDB, representing key entities (admin, attendance, course, etc.).
- Middleware: Handle authentication (auth.middleware.js), rate limiting, and other cross-cutting concerns.
- Services: Integration services such as openaiService.js for additional external functionality.
- Database: MongoDB as the persistent data store.
b. Frontend Components:
- Role-specific Dashboards: Separate interfaces for Admin, Faculty, and Student roles.
- Shared UI Components: Common elements (NavBar, forms, tables, dialogs) that promote consistency.
- State Management: Redux to handle the application’s global state.
- Design and Styling: Vite + React, Tailwind CSS, and libraries like Framer Motion and ShadCN UI for animation and UI components.

##### Relationships and Data Flow
- The user interacts with the frontend, which communicates with the backend via API calls (using REST endpoints defined in the routes).
- The backend handles these requests by invoking the appropriate controllers, which then interact with the MongoDB database using models.
- Middleware components process requests for authentication and rate limiting before they reach controllers.
- For additional functionalities (e.g., OpenAI integration), the backend directs certain requests to external services via the openaiService.
- Responses are sent back through the API to the frontend, which updates the UI state through Redux and renders the updated views.

##### Architectural Patterns and Design Principles
- Layered/MVC: The backend follows an MVC-like structure where routes serve as the entry point, controllers contain business logic, and models interface with the database.
- Component-based Design: The frontend leverages React components to isolate functionality, enabling reusability and maintainability.
- Separation of Concerns: Clear divide between client-side (user interface) and server-side (business logic and persistence).

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Backend"
        A["Express API Server"]:::backend
        B["Routes"]:::route
        C["Middlewares"]:::middleware
        D["Controllers"]:::controller
        E["Models/MongoDB"]:::model
        F["External Service (OpenAI)"]:::external
        G["Database Config"]:::external
    end

    subgraph "Frontend"
        H["Admin Dashboard"]:::frontend
        I["Faculty Dashboard"]:::frontend
        J["Student Dashboard"]:::frontend
        K["Shared UI Components"]:::frontend
        L["Redux Store"]:::redux
    end

    A -->|"HTTP_Request"| B
    B -->|"Authenticate"| C
    C -->|"Process"| D
    D -->|"DB_Operations"| E
    D -->|"External_Call"| F
    E -->|"Configured_By"| G

    H -->|"API_call"| A
    I -->|"API_call"| A
    J -->|"API_call"| A

    H -->|"Updates_State"| L
    I -->|"Updates_State"| L
    J -->|"Updates_State"| L

    H --- K
    I --- K
    J --- K

    %% Click Events for Backend Components
    click A "https://github.com/gaurang1404/campuschat/blob/main/backend/index.js"
    click B "https://github.com/gaurang1404/campuschat/tree/main/backend/src/routes"
    click C "https://github.com/gaurang1404/campuschat/tree/main/backend/src/middlewares"
    click D "https://github.com/gaurang1404/campuschat/tree/main/backend/src/controllers"
    click E "https://github.com/gaurang1404/campuschat/tree/main/backend/src/models"
    click F "https://github.com/gaurang1404/campuschat/blob/main/backend/src/services/openaiService.js"
    click G "https://github.com/gaurang1404/campuschat/blob/main/backend/src/config/db.js"

    %% Click Events for Frontend Components
    click H "https://github.com/gaurang1404/campuschat/blob/main/frontend/src/components/admin/AdminDashboard.jsx"
    click I "https://github.com/gaurang1404/campuschat/blob/main/frontend/src/components/faculty/FacultyDashboard.jsx"
    click J "https://github.com/gaurang1404/campuschat/blob/main/frontend/src/components/student/StudentDashboard.jsx"
    click K "https://github.com/gaurang1404/campuschat/tree/main/frontend/src/components/shared"
    click L "https://github.com/gaurang1404/campuschat/tree/main/frontend/src/redux"

classDef backend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
classDef controller fill:#85C1E9,stroke:#1B4F72,stroke-width:2px;
classDef middleware fill:#A9CCE3,stroke:#2471A3,stroke-width:2px;
classDef route fill:#D4E6F1,stroke:#1B4F72,stroke-width:2px;
classDef model fill:#ABEBC6,stroke:#1E8449,stroke-width:2px;
classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
classDef frontend fill:#FAD7A0,stroke:#D35400,stroke-width:2px;
classDef redux fill:#F5B7B1,stroke:#943126,stroke-width:2px;
```
