# lostalice/econ_ai_ta architecture

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

## Overview

##### Main Components
- Frontend: Built using Next.js (note the pages, components, and Next configuration files). It includes pages for chats, documentation, mock exam interfaces, and language support (i18n). It communicates with the backend via API calls.
- Backend: Organized in a dedicated folder with subdirectories for API endpoints (under Backend/api/v1) and utilities (helpers for models, database connectivity, and RAG – Retrieval Augmented Generation – components). This layer handles core features like intelligent TA interactions, file uploads, and manages multiple API endpoints (for chat, authorization, documentation, etc.).
- Database: The README shows clear configuration for a (likely) MySQL database. The backend includes modules that wrap database operations (see the “database” directories under utils and helper/model).
- External Services and LLM Components: The README provides detailed parameters for LLM deployment (openai, Ollama) and vector databases such as Milvus. These services support the chatbot’s intelligent Q&A, as well as associated embedding processing.
- Deployment: Docker configuration files (dockerfile, docker-compose.yaml, .dockerignore files) in both Frontend and Backend indicate containerization, which is an integral part of the deployment architecture.

##### Relationships and Interactions
- The Frontend sends HTTP requests (API calls) to the Backend. The API endpoints in Backend/api/v1 (chatroom, authorization, etc.) handle these requests.
- The Backend manages business logic, routing, and processing of requests. It interacts with the Database layer for storing and retrieving data, as well as with external LLM services.
- Utilities under RAG help to process documents, extract vectors, and handle responses. These likely interact with the external LLM or vector embedding services as mentioned.
- Docker is used to containerize both the Frontend and Backend for consistent environment setup and deployment.
- Authentication parameters indicate secure access between components, while cross-origin (CORS) setups in the main backend file manage frontend-backend communication.

##### Important Architectural Patterns
- Separation of Concerns: Clear modular separation between Frontend and Backend, including distinct directories for API endpoints, helper functions, and database operations.
- Microservice/Modular API Design: Backend/api/v1 and corresponding helper/model directories show that the API is organized into specific endpoints (e.g., chatroom, authorization, and documentation), which may be scaled or updated independently.
- Containerization: Use of Docker and docker-compose files ensures that the system can be deployed consistently across different environments.
- Integration with External APIs and Services: The configuration for LLM (openai, Ollama) and vector search (Milvus) indicates a system design that makes use of external intelligent services.

##### Final Practical Steps
- To clearly represent sequential workflows – for example, a user interaction triggers the Frontend, which calls an API endpoint in the Backend that then involves RAG processing and database queries.
- Modular nature of the design – each component should be clearly delineated to facilitate future growth (such as adding mock exam functionalities or additional language support).

## Diagram (Mermaid)

```mermaid
flowchart TD 
    subgraph "Presentation Layer"
        FE["Frontend (Next.js Application)"]:::frontend
        ACTX["Auth Context"]:::auth
    end

    subgraph "Business Logic Layer"
        BE["Backend (Python API & Business Logic)"]:::backend
        API["API Endpoints (chat,authorization,documentation,mock)"]:::backend
        AUTH["Authorization API"]:::auth
    end

    subgraph "Data & Integration Layer"
        DB1["Database Ops (utils)"]:::data
        DB2["Database Ops (helper/model)"]:::data
        RAG["RAG Utilities"]:::integration
        RAG_HELP["RAG Helper (model)"]:::integration
        LLM["LLM & Embedding Integration"]:::integration
    end

    subgraph "Deployment Layer"
        BE_DOCK["Backend Docker Deployment"]:::deploy
        FE_DOCK["Frontend Docker Deployment"]:::deploy
    end

    U["User"]:::user

    %% Connections
    U -->|"uses"| FE
    FE -->|"callsAPI"| BE
    FE -->|"handlesAuth"| ACTX
    ACTX -->|"syncsWith"| AUTH
    BE -->|"routesTo"| API
    BE -->|"performsCRUD"| DB1
    BE -->|"performsCRUD"| DB2
    BE -->|"processesWith"| RAG
    RAG -->|"assists"| RAG_HELP
    RAG -->|"integrates"| LLM
    BE -->|"securedBy"| AUTH
    FE -->|"deployedIn"| FE_DOCK
    BE -->|"deployedIn"| BE_DOCK

    FE_DOCK -.-> FE
    BE_DOCK -.-> BE

    %% Click Events
    click FE "https://github.com/lostalice/econ_ai_ta/tree/main/Frontend/"
    click BE "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/"
    click API "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/api/v1/"
    click DB1 "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/utils/database/"
    click DB2 "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/utils/helper/model/database/"
    click RAG "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/utils/RAG/"
    click RAG_HELP "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/utils/helper/model/RAG/"
    click LLM "https://github.com/lostalice/econ_ai_ta/blob/main/Backend/utils/RAG/vector_extractor.py"
    click AUTH "https://github.com/lostalice/econ_ai_ta/blob/main/Backend/api/v1/authorization.py"
    click ACTX "https://github.com/lostalice/econ_ai_ta/blob/main/Frontend/contexts/AuthContext.tsx"
    click BE_DOCK "https://github.com/lostalice/econ_ai_ta/tree/main/Backend/dockerfile"
    click FE_DOCK "https://github.com/lostalice/econ_ai_ta/tree/main/Frontend/dockerfile"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef backend fill:#F9E79F,stroke:#7D6608,stroke-width:2px;
    classDef data fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef integration fill:#F5B7B1,stroke:#78281F,stroke-width:2px;
    classDef deploy fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef auth fill:#FAD7A0,stroke:#7D6608,stroke-width:2px;
    classDef user fill:#D2B4DE,stroke:#512E5F,stroke-width:2px;
```
