# ineerajrajeev/isource architecture

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

- Interactive diagram: https://gitdiagram.com/ineerajrajeev/isource
- Repository: https://github.com/ineerajrajeev/isource

## Overview

##### Main Components
- Frontend/UI: Representing the HTML templates and static assets (CSS, JS, images) served from the “app/templates” and “app/Static” directories. This is the user-facing layer where users interact with the forum and chatbot.
- Backend (Flask Application): This includes the app’s core code like app.py, initialization in app/__init__.py, business logic in app/models.py, and organized routes for different parts of the application (user, moderator, organization, etc.) within app/routes.
- Discussion Forum Module: A component focused on handling question posting, community responses, and official answer flagging.
- Chatbot RAG Module: Divided into both “Simple RAG” and “Hybrid RAG” flows as described in the README. This module handles the conversational interface, integrates with Elasticsearch for document retrieval, and uses either the Gemini API or an on-device LLM model for response synthesis.
- Database and Data Storage:
– SQLite: For storing application data (user information, discussion threads, flags, etc.).
– Elasticsearch: For vector-based indexing and rapid similarity search that feeds into the RAG operations.
- AI Integration Services:
– Gemini API: Represent the external API node for advanced natural language processing responses.
– On-Device LLM Models: An alternative or complementary node for local processing when needed.
- Admin Interface: Includes routes and templates for managing documents and forum interactions (e.g., document uploads, flagging official answers).
- Deployment/Containerization: Highlight Docker-related elements such as docker-compose.yaml, dockerfile, and any environment configurations.

##### Relationships & Interactions
- User journey starting from the Frontend (web browser) interacting with the Flask server.
- Admin functionalities with a dedicated module connecting to document management endpoints.

##### Architectural Patterns and Principles
- MVC/Blueprints: The project organizes its functionality via routes, models, and templates, which reflects an MVC-like separation.
- Separation of Concerns: Different modules are clearly separated (forum, chatbot, admin actions, file uploads) to ensure scalability.
- Dual/Hybrid Processing Paths in RAG: Emphasize the decision nodes that determine whether to leverage external (Gemini API) versus local LLM processing, followed by result synthesis.
- Integration Layers: Clearly differentiate between internal processing (Flask, SQLite) and external services (Elasticsearch, Gemini API).

##### Relevant Technologies & Frameworks
- Backend: Python with Flask.
- Frontend: HTML, CSS, JavaScript templated through Jinja2.
- Data Storage: SQLite and Elasticsearch.
- AI Integration: Gemini API, on-device LLM frameworks.
- Containerization: Docker (docker-compose.yaml, dockerfile).

##### Suggested Elements
- User request to the Flask server.
- Flask server to both databases (SQLite for data persistence and Elasticsearch for search queries).
- Query processing flow from Elasticsearch to the RAG component.
- Dual paths (external API call to Gemini API and local processing with on-device LLM).
- Consolidation/synthesis of response and back to user.
- Frontend vs. backend components.
- Internal services (databases, Flask) vs. external services (Gemini API, on-device LLM).
- Data retrieval flow (Elasticsearch operations) vs. user interaction flow.

##### Additional Detailing

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    A["User (Web Browser)"]:::frontend

    %% Frontend/UI Layer
    subgraph "Frontend/UI"
        FE1["Templates (HTML)"]:::frontend
        FE2["Static Assets (CSS,JS,Images)"]:::frontend
    end

    %% Backend Layer
    subgraph "Flask Backend"
        B1["app.py"]:::backend
        B2["app/__init__.py"]:::backend
        B3["app/models.py"]:::backend
        B4["Routes (app/routes)"]:::backend
        %% Modules under Routes
        DF["Discussion Forum Module"]:::module
        CR["Chatbot RAG Module"]:::module
        AD["Admin Interface"]:::module
    end

    %% Data Storage Layer
    subgraph "Data Storage"
        DB1["((SQLite Database))"]:::db
        DB2["((Elasticsearch))"]:::db
    end

    %% AI Integration Services
    subgraph "AI Integration"
        AI1["Gemini API"]:::external
        AI2["On-Device LLM"]:::external
    end

    %% Deployment/Containerization
    subgraph "Deployment/Containerization"
        DEP1["docker-compose.yaml"]:::deployment
        DEP2["dockerfile"]:::deployment
    end

    %% Connections
    A -->|"UserRequest"| FE1
    A -->|"UserRequest"| FE2
    FE1 -->|"Load UI"| B1
    FE2 -->|"Load UI"| B1

    %% Linking Backend components
    B1 --> B2
    B2 --> B3
    B3 --> B4
    B4 --> DF
    B4 --> CR
    B4 --> AD

    %% Backend database interactions
    B1 -->|"CRUD Operations"| DB1
    B1 -->|"Search Queries"| DB2

    %% Forum update mechanism feeding into search index
    DF -->|"UpdateKB"| DB2

    %% Chatbot RAG Flow: retrieval and AI processing
    CR -->|"RetrieveDocs"| DB2
    CR -->|"ExternalCall"| AI1
    CR -->|"LocalCall"| AI2
    AI1 -->|"ReturnResponse"| CR
    AI2 -->|"ReturnResponse"| CR

    %% Deployment linking to Backend
    DEP1 -->|"ContainerSetup"| B1
    DEP2 -->|"ContainerSetup"| B1

    %% Click Events
    click FE1 "https://github.com/ineerajrajeev/isource/tree/main/app/templates"
    click FE2 "https://github.com/ineerajrajeev/isource/tree/main/app/Static"
    click B1 "https://github.com/ineerajrajeev/isource/blob/main/app.py"
    click B2 "https://github.com/ineerajrajeev/isource/blob/main/app/__init__.py"
    click B3 "https://github.com/ineerajrajeev/isource/blob/main/app/models.py"
    click B4 "https://github.com/ineerajrajeev/isource/tree/main/app/routes"
    click DF "https://github.com/ineerajrajeev/isource/blob/main/app/routes/question_answer.py"
    click CR "https://github.com/ineerajrajeev/isource/blob/main/app/templates/chat.html"
    click AD "https://github.com/ineerajrajeev/isource/blob/main/app/templates/admin_dashboard.html"
    click AI1 "https://github.com/ineerajrajeev/isource/blob/main/app/utils/ai_part.py"
    click DEP1 "https://github.com/ineerajrajeev/isource/blob/main/docker-compose.yaml"
    click DEP2 "https://github.com/ineerajrajeev/isource/tree/main/dockerfile"

    %% Styles
    classDef frontend fill:#FFCCCC,stroke:#cc0000,stroke-width:2px;
    classDef backend fill:#CCFFCC,stroke:#009900,stroke-width:2px;
    classDef module fill:#CCCCFF,stroke:#000099,stroke-width:2px;
    classDef db fill:#FFFFCC,stroke:#999900,stroke-width:2px;
    classDef external fill:#E0FFFF,stroke:#00CCCC,stroke-width:2px;
    classDef deployment fill:#FFE6CC,stroke:#FF9900,stroke-width:2px;
```
