# avidhanorkar/code_sprinters architecture

> Architecture diagram of the GitHub repository avidhanorkar/code_sprinters, 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/avidhanorkar/code_sprinters
- Repository: https://github.com/avidhanorkar/code_sprinters

## Overview

##### Main Components
- Frontend Application: Built with React; includes pages, shared UI components, context providers (for auth), and routing. It’s responsible for the user interface, offline support (using service workers), and calls to APIs.
- Backend Server/API: An Express.js server that handles API endpoints for authentication (both admin and user), course content (CRUD), quizzes, certificate generation, leaderboards, admin operations, and chatbot integration.
- Database: MongoDB (accessed via Mongoose models – User, Admin, Quiz, Course) that stores user data, courses, quizzes, results, and leaderboard-related data.
- External Services & Integrations:
- AI Chatbot: Integration with the Gemini AI API for personalized Q&A.
- Video Service: YouTube links for hosting videos.
- Certificate Generation: Libraries like pdfkit and node-html-pdf.
- Cloudinary: For media asset management (as seen in the cloudinaryConfig.js).
- Community Tools: Socket.io integration and Discourse for discussion forums.
- Offline Syncing: PouchDB and Workbox (Service Workers) for offline capabilities.

##### Relationships & Interactions
- The Frontend interacts with the Backend via RESTful API calls (authentication, courses, quizzes, certificates, leaderboard data).
- The Backend uses middleware (JWT-based auth, role checks) to secure routes and responds with data from the MongoDB database.
- The Backend communicates with external services for additional functionalities such as AI assistance, video delivery, certificate generation, and community features.
- Offline support is implemented in the Frontend (using service workers and possibly PouchDB) to allow download of lessons and later synchronization.
- Data flows from user actions (e.g., signing up, enrolling in courses, taking quizzes) through the API layer where requests are processed by controllers and potentially trigger interactions with external services.

##### Architectural Patterns & Design Principles
- Separation of Concerns: The project clearly segregates frontend UI logic, backend business logic (controllers, route handlers), and data models.
- Modular Design: Both the frontend and backend are organized in modular directories (components, pages, models, controllers, etc.) making it easier to identify independent subsystems.
- Microservices/Decoupled Integrations: Although it’s a monorepo, external integrations (chatbot, video, certificate generation) are abstracted in dedicated modules.
- Secure API Communication: JWT-based authentication coupled with middleware ensures fine-grained control over access (role-based security).

##### Technologies and Frameworks
- Frontend: React, Vite, TailwindCSS.
- Backend: Express.js, Node.js, Passport.js, JWT, bcrypt.
- Database: MongoDB with Mongoose.
- Third-Party/External: Gemini AI API, YouTube, Cloudinary, pdfkit, node-html-pdf, PouchDB/Workbox, Socket.io, and Discourse.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Flow
    U["User Browser"]:::frontend

    %% Frontend Layer
    subgraph "Frontend Layer"
        F["Frontend (React/Vite/TailwindCSS & Offline Support)"]:::frontend
        FS["Service Worker & PouchDB Offline Sync"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        B["Backend API (Express.js/Node.js)"]:::backend
        JWT["JWT Auth Middleware"]:::middleware
        CHAT["Chatbot Routes (Gemini AI)"]:::backend
        CERT["Certificate Routes (Certificate Generation)"]:::backend
        CLOUD["Cloudinary Integration"]:::backend
    end

    %% Database and Models
    D["MongoDB Database"]:::database
    MODELS["Mongoose Models & Config"]:::database

    %% External Services
    subgraph "External Integrations"
        AI["Gemini AI API"]:::external
        YT["YouTube (Video Service)"]:::external
        PDF["Certificate Generation Lib (pdfkit/node-html-pdf)"]:::external
        COMM["Community Tools (Socket.io, Discourse)"]:::external
    end

    %% Relationships
    U -->|"accesses"| F
    F -->|"calls APIs"| B
    F -->|"sync offline data"| FS
    FS -->|"sync when online"| B

    B -->|"validates token"| JWT
    B -->|"handles chatbot queries"| CHAT
    CHAT -->|"requests responses from"| AI
    B -->|"handles certificate requests"| CERT
    CERT -->|"generates using"| PDF
    B -->|"manages media"| CLOUD
    B -->|"fetches/stores data"| D
    B -->|"queries using"| MODELS
    B -->|"fetches video content"| YT
    B -->|"engages community"| COMM

    %% Click Events
    click F "https://github.com/avidhanorkar/code_sprinters/tree/main/frontend/"
    click MODELS "https://github.com/avidhanorkar/code_sprinters/tree/main/backend/models"
    click B "https://github.com/avidhanorkar/code_sprinters/blob/main/backend/server.js"
    click JWT "https://github.com/avidhanorkar/code_sprinters/blob/main/backend/middleware/authMiddleware.js"
    click CHAT "https://github.com/avidhanorkar/code_sprinters/blob/main/backend/routes/chatbotRoutes.js"
    click CERT "https://github.com/avidhanorkar/code_sprinters/blob/main/backend/routes/certificateRoutes.js"
    click CLOUD "https://github.com/avidhanorkar/code_sprinters/blob/main/backend/config/cloudinaryConfig.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef external fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef middleware fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
```
