# aniruddhabagal/mentormind architecture

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

## Overview

##### Main Components
- Backend Service (FastAPI):
- Entry point (main.py) initializing the FastAPI application.
- Configuration (config.py) for environment variables and API keys.
- API routes and dependencies (app/api/): These define endpoints handling user requests and AI communication.
- Activity Modules (app/activities/): Different stages of the tutoring flow (introduction, practice, assessment, review).
- Graph Management (app/graph/): Organizes the structured flow of learning activities (nodes, builder, assistant).
- AI and Learning Tools:
- Models (app/models/) for managing student state and AI configuration (e.g., llm_setup.py).
- Tools (app/tools/) that tailor subject-specific operations (math, science, language, assessment).
- Prompts (app/prompts/): Predefined prompts for guiding the AI tutor.

- Frontend Service (React):
- Main Application component (App.jsx) and entry point (index.jsx).
- UI components (under src/components/) for different interfaces like chat, dashboard, student profile, and layout.
- Service Layer (src/services/): For managing API calls to the backend.
- Supporting elements (hooks, contexts, utilities, and styles using Tailwind CSS) to manage the UI logic and global state.

##### Relationships and Interactions
- The frontend interacts with the backend via API endpoints represented in the app/api/routes module.
- The backend’s API layer orchestrates the flow using different activity modules and the graph structure to decide which activity to serve next.
- Student progress is managed in the models, and interactions are enhanced by the tools which use various subject-specific logic.
- The AI component (Google Gemini integration in llm_setup.py) is utilized to generate responses/feedback based on prompts and user input.

##### Important Architectural Patterns
- Modular Design: The separation of concerns into distinct folders (activities, graph, tools, models, and prompts).
- API Gateway/Microservices-Style for the backend using FastAPI.
- Separation of Concerns between Frontend and Backend.
- Component-Based Design on the frontend (React) that encapsulates UI elements and state management (contexts, hooks, services).
- Graph-Based Learning Flow: Using nodes and a builder to manage the sequence of tutoring interactions.

##### Relevant Technologies, Frameworks, and Libraries
- Backend: FastAPI (for API endpoints), Python modules for activity management, graph building, and student model tracking.
- AI Integration: Google Gemini (as configured in the llm_setup module and via environment variables).
- Frontend: React (for building the interactive UI) with Tailwind CSS for styling, along with npm-managed packages.
- Utilization of common tools such as ESLint for code quality and Vite as the build tool for the frontend.

##### Detail and Clarity
- Be as granular as possible—don’t hesitate to separate the backend into its defining parts (config, API, activities, graph, tools, models, prompts) and the frontend into its shared components, pages, and service layers.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Backend"
        BS["Backend Service (FastAPI)"]
        CFG["Configuration"]
        AR["API Routes"]
        AD["API Dependencies"]
        
        subgraph "Activity Modules"
            IN["Introduction Activity"]
            PR["Practice Activity"]
            AS["Assessment Activity"]
            RV["Review Activity"]
        end

        subgraph "Graph Management"
            GB["Graph Builder"]
            GN["Graph Nodes"]
            GA["Graph Assistant"]
        end

        subgraph "Models & AI"
            LLM["LLM Setup"]
            SM["Student State Model"]
        end

        subgraph "Tools"
            MT["Math Tools"]
            ST["Science Tools"]
            LT["Language Tools"]
            AT["Assessment Tools"]
            CT["Common Tools"]
        end

        PROM["Prompts (Predefined Tutor Guidance)"]
    end

    subgraph "Frontend"
        MI["Main Initialization"]
        AC["App Component"]
        UI["UI Components"]
        FS["Frontend Service Layer"]
    end

    %% Backend Connections
    BS --> CFG
    BS --> AR
    AR --> AD
    AR -->|"calls"| IN
    AR -->|"calls"| PR
    AR -->|"calls"| AS
    AR -->|"calls"| RV
    AR -->|"uses"| GB
    AR -->|"uses"| GN
    AR -->|"uses"| GA
    AR -->|"references"| PROM
    GA -->|"integrates with"| LLM
    LLM -->|"manages"| SM
    SM -->|"triggers"| MT
    SM -->|"triggers"| ST
    SM -->|"triggers"| LT
    SM -->|"triggers"| AT
    SM -->|"triggers"| CT
    LLM -->|"utilizes"| PROM

    %% Frontend Connections
    MI --> AC
    AC --> UI
    FS --> AC
    FS -->|"calls API"| AR

    %% Styles
    classDef backend fill:#ffcccc,stroke:#b30000,stroke-width:2px;
    classDef frontend fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef api fill:#ccffff,stroke:#008080,stroke-width:2px;
    
    class BS,CFG,AR,AD,IN,PR,AS,RV,GB,GN,GA,LLM,SM,MT,ST,LT,AT,CT,PROM backend;
    class MI,AC,UI,FS frontend;
    
    %% Click Events for Backend Components
    click BS "https://github.com/aniruddhabagal/mentormind/blob/main/backend/main.py"
    click CFG "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/config.py"
    click AR "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/api/routes.py"
    click AD "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/api/dependencies.py"
    click IN "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/activities/introduction.py"
    click PR "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/activities/practice.py"
    click AS "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/activities/assessment.py"
    click RV "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/activities/review.py"
    click GB "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/graph/builder.py"
    click GN "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/graph/nodes.py"
    click GA "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/graph/assistant.py"
    click LLM "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/models/llm_setup.py"
    click SM "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/models/student_model.py"
    click MT "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/tools/math_tools.py"
    click ST "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/tools/science_tools.py"
    click LT "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/tools/language_tools.py"
    click AT "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/tools/assessment_tools.py"
    click CT "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/tools/common_tools.py"
    click PROM "https://github.com/aniruddhabagal/mentormind/blob/main/backend/app/prompts/tutor_prompts.py"

    %% Click Events for Frontend Components
    click AC "https://github.com/aniruddhabagal/mentormind/blob/main/frontend/src/App.jsx"
    click MI "https://github.com/aniruddhabagal/mentormind/blob/main/frontend/src/main.jsx"
    click UI "https://github.com/aniruddhabagal/mentormind/tree/main/frontend/src/components/ui"
    click FS "https://github.com/aniruddhabagal/mentormind/blob/main/frontend/src/lib/utils.js"
```
