# rajverma04/ai_personalized_learning architecture

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

- Interactive diagram: https://gitdiagram.com/rajverma04/ai_personalized_learning
- Repository: https://github.com/rajverma04/ai_personalized_learning

## Overview

##### Project Type and Primary Purpose
- This is a full-stack interactive learning platform. It features multiple study modes (flashcards, MCQs, case studies, summarization, etc.) and integrates AI capabilities via the Google Gemini API.
- The application is split into two primary services: a Node.js based backend (handling routes, API endpoints, controllers, static files, and templates) and a Python-based AI service (running Flask in the ai_service directory).

##### File Structure
- Top-level Directories and Files:
- ai_service/: Contains the Flask application (app.py) and its Python dependency file (requirements.txt). This component likely handles AI-specific functionalities like text summarization and possibly processing voice input.
- backend/: Contains all Node.js code with sub-directories for controllers (business logic for AI operations), models (database interactions), routes (API endpoints), static assets (CSS, JS, images), templates (HTML files for the UI), and uploads (likely handling user-uploaded content).
- Other files like .gitignore, netlify.toml, and readme.md are for configuration and project documentation.
- Architectural Implications:
- The frontend is embedded within the backend (using templates and static directories) and is served to clients.
- The backend (Node.js) acts as an API server and includes controllers and models – suggestive of an MVC pattern.
- The ai_service (Python/Flask) likely functions as a microservice offering AI/processing capabilities that the backend calls via APIs.

##### Core Components & Their Relationships
- Frontend/UI Layer:
- Built with HTML/CSS/JavaScript and served through the backend’s templates and static directories.
- Responsible for presenting learning modes and interacting with users.
- Backend Service (Node.js):
- Routes: api.js (defines API endpoints) which connect the frontend with the business logic.
- Controllers & Models: Handle logic and database interactions respectively.
- Server Entry Point: server.js (starts the Node.js server).
- Data Flow: Receives user interactions and requests data from both local models and through calls to external services.
- AI Service (Flask):
- API Endpoint: app.py (entry point for AI-related requests).
- Dependencies: Python modules that facilitate integration with the Gemini API and other AI functionalities.
- Data Flow: Receives requests (likely from the backend) for AI tasks such as summarization or Q&A responses.
- External Services:
- Google Gemini API: Used for AI capabilities; configured via environment variables in the .env file.

##### Architectural Patterns and Design Principles
- Separation of Concerns:
- The system is clearly divided between user interface (frontend), business logic & API (backend), and specialized AI processing (ai_service).
- Microservices or Service-oriented Architecture:
- The ai_service (Flask) is a standalone service that can be scaled independently or integrated as an API consumed by the backend.
- MVC-Like Structure in Backend:
- Controllers, Models, and Routes in the backend enforce a separation between presentation, business logic, and data management.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        U("User") 
    end

    subgraph "Frontend/UI Layer"
        T("Templates (HTML)"):::frontend
        S("Static Assets (CSS/JS)"):::frontend
    end

    subgraph "Backend Service (Node.js)"
        NS("Server (server.js)"):::backend
        C("Controllers"):::backend
        R("Routes (api.js)"):::backend
        M("Models (Database)"):::backend
    end

    subgraph "AI Service (Flask)"
        FA("Flask API (app.py)"):::ai
        D("Dependencies (requirements.txt)"):::ai
    end

    G("Google Gemini API"):::external

    U -->|"requests"| T
    U -->|"requests"| S
    T -->|"renders"| NS
    S -->|"loads"| NS
    NS -->|"handles"| C
    NS -->|"handles"| R
    C -->|"queries"| M
    NS -->|"calls"| FA
    FA -->|"integrates"| G

    click T "https://github.com/rajverma04/ai_personalized_learning/tree/main/backend/templates"
    click S "https://github.com/rajverma04/ai_personalized_learning/tree/main/backend/static"
    click NS "https://github.com/rajverma04/ai_personalized_learning/blob/main/backend/server.js"
    click C "https://github.com/rajverma04/ai_personalized_learning/tree/main/backend/controllers"
    click R "https://github.com/rajverma04/ai_personalized_learning/tree/main/backend/routes"
    click M "https://github.com/rajverma04/ai_personalized_learning/tree/main/backend/models"
    click FA "https://github.com/rajverma04/ai_personalized_learning/blob/main/ai_service/app.py"
    click D "https://github.com/rajverma04/ai_personalized_learning/blob/main/ai_service/requirements.txt"

    classDef frontend fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef ai fill:#ccccff,stroke:#0000ff,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#e6e600,stroke-width:2px;
```
