# dinakar-s/linguamentor architecture

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

## Overview

##### Main Components
- Frontend: The Streamlit interface (ui.py) where users interact with the chatbot.
- Backend API: The FastAPI server (app.py) managing API endpoints and core logic.
- Database: The SQLite database (mistakes.db) along with db.py that handles all database operations (logging user mistakes, retrieval for feedback).
- AI Integration: The external language model services (e.g., OpenRouter AI or DeepSeek) used for processing language and generating feedback.
- Prompt Template Module: The prompt_templates.py file, which centralizes the construction of prompts or dialogues that interface with the external AI.

##### Out Relationships and Interactions
- User Interaction: Users interact with the chatbot via the Streamlit UI.
- Data Flow: The UI captures user inputs and sends them to the backend API.
- API Processing: The FastAPI server receives requests, utilizes the prompt_templates module to generate appropriate queries, and interfaces with the external AI service (via the Requests library) for language understanding and mistake correction.
- Database Logging: Any user mistakes detected or session data required for progress tracking is stored or retrieved from the SQLite database (managed by db.py and persisted in mistakes.db).
- Response Flow: Corrected responses or expert feedback is then returned through the API and rendered in the UI.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clearly split between frontend (Streamlit UI), backend (FastAPI server), and database (SQLite). Each component has a distinct responsibility.
- API-Centric Communication: The UI uses API calls to interact with the FastAPI backend, which in turn orchestrates interactions with external service APIs.
- Integration Layer: The prompt_templates serve as a middleware/component to standardize the prompts for the language model.

##### Relevant Technologies/Frameworks
- Backend: FastAPI.
- Frontend: Streamlit.
- Database: SQLite.
- External Services: OpenRouter AI/DeepSeek.
- Additional Libraries: Requests (for API communication), along with any Python runtime configurations seen in requirements.txt.

- Use clear labels for each component (e.g., “Streamlit UI”, “FastAPI Backend”, “SQLite Database”, “External AI Service”, “Prompt Templates”).
- From the user to the Streamlit UI,
- From the UI to the FastAPI backend,
- From FastAPI to both the external AI service (for processing corrections) and the database (for logging and retrieval),
- Rectangles for core components (UI, API, Database),

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    subgraph "User Interaction"
        U["User"]:::user
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Streamlit UI"]:::frontend
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        API["FastAPI Backend"]:::backend
        PT["Prompt Templates"]:::integration
    end

    %% Data Storage Layer
    subgraph "Data Storage Layer"
        DB["SQLite Database"]:::database
    end

    %% External Services
    subgraph "External Services"
        AI["External AI Service"]:::external
    end

    %% Data Flows
    U -->|"sends_input"| UI
    UI -->|"calls_API"| API
    API -->|"builds_prompt"| PT
    API -->|"logs_retrieves"| DB
    API -->|"calls_AI"| AI
    AI -->|"returns_corrections"| API
    API -->|"sends_response"| UI

    %% Click Events
    click UI "https://github.com/dinakar-s/linguamentor/blob/main/ui.py"
    click API "https://github.com/dinakar-s/linguamentor/blob/main/app.py"
    click DB "https://github.com/dinakar-s/linguamentor/blob/main/db.py"
    click DB "https://github.com/dinakar-s/linguamentor/blob/main/mistakes.db"
    click PT "https://github.com/dinakar-s/linguamentor/blob/main/prompt_templates.py"

    %% Styles
    classDef frontend fill:#a2d9ce,stroke:#1e8449,stroke-width:2px;
    classDef backend fill:#fad7a0,stroke:#d35400,stroke-width:2px;
    classDef database fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef integration fill:#d7bde2,stroke:#6c3483,stroke-width:2px;
    classDef user fill:#d6eaf8,stroke:#2471a3,stroke-width:2px;
```
