# ammar-alnagar/enlightener architecture

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

- Interactive diagram: https://gitdiagram.com/ammar-alnagar/enlightener
- Repository: https://github.com/ammar-alnagar/enlightener

## Overview

##### Main Components
- Data Sources/Input:
– Represent folders like “Data” and “data2”, which host raw PDFs and other data files.
– These represent the raw text/document inputs for the system.
- Data Preprocessing & Indexing:
– Components like “Indexer.py”, “newindexer.py”, and possibly preprocessing routines (alluded to in the README’s “scripts/preprocess_data.py” step) form the ingestion and transformation pipeline.
- Core NLP and Model Modules:
– “Mamba.py” is central to executing the SSM models.
– “Gemini.py” and “improvedrag.py” suggest additional model variants or enhanced retrieval functionalities.
- Main Application & Query Handling:
– “main.py”, “newmain.py”, and “chat_history.py” likely support the orchestration of model inference and query-response dialogue management.
- Auxiliary Components:
– Files like “localaudio.py” hint at integration with local audio for speech-based interaction.
– “cagtest.py” and any testing utilities and sample HTML like “testvoice.html” could be noted as supplementary testing/demo interfaces.
- Configuration & Dependencies:
– The README mentions tuning via a YAML file (config/config.yaml) and the use of “requirements.txt” ensures that supporting libraries are installed.
- (Optionally) Notebook/Analysis Tools:
– Although notebooks aren’t shown in the file tree, the README mentions interactive notebooks for data and model analysis. These can be drawn as separate, interacting components if needed.

##### Relationships and Data Flow
- Data goes through an indexing service (using Indexer.py/newindexer.py) that prepares it for rapid retrieval.
- Any incoming query (via a CLI or even through local demos like testvoice.html) is processed by the main orchestration modules (main.py/newmain.py).
- The query then gets routed to the retrieval component to fetch relevant documents or snippet inputs.
- The selected data is then processed by the core NLP models (Mamba, Gemini, or improvedrag modules) to generate answers.
- The output is eventually compiled and may use chat_history.py to maintain conversational context.
- For local audio, localaudio.py could capture audio and then forward transcribed content into the system.
- Optionally, connections to Jupyter notebook analytics can be depicted as a separate analysis loop.

##### Architectural Patterns and Design Insights
- Separation of concerns: Data ingestion and preprocessing, retrieval/indexing, and model inference are distinct, interact via well-defined interfaces.
- That the architecture leans towards modular design, enabling targeted testing (pytest mentioned) and potential enhancements.

##### Relevant Technologies and Frameworks
- Python is the primary language; dependencies are handled through requirements.txt.
- Test and evaluation components are integrated (with pytest and demo HTML interfaces) and can be shown to interact with the main pipeline.
- Configuration management is handled via YAML files (as mentioned in the README).

- Data Sources: “Data” and “data2” directories (raw documents)
- Preprocessing/Indexing: “Indexer.py”, “newindexer.py” (data transformation pipeline)
- Core NLP Modules: “Mamba.py”, “Gemini.py”, “improvedrag.py” (model execution)
- Application Orchestration: “main.py”, “newmain.py”, “chat_history.py” (query processing and response generation)
- Audio Interface: “localaudio.py” (for speech input)
- Testing/Utility: “cagtest.py”, “testvoice.html” (demonstration and testing modules)
- External links: Dependencies (requirements.txt) and configuration management (config/config.yaml as described in the README)
- Optionally reference a “Notebooks” component for exploratory analysis

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Sources
    subgraph "Data Sources"
        DS1["Data"]:::datain
        DS2["data2"]:::datain
    end

    %% Data Preprocessing & Indexing
    subgraph "Data Preprocessing & Indexing"
        IDX1["Indexer.py"]:::preprocess
        IDX2["newindexer.py"]:::preprocess
    end

    %% Core NLP Modules
    subgraph "Core NLP Modules"
        NLP1["Mamba.py"]:::model
        NLP2["Gemini.py"]:::model
        NLP3["improvedrag.py"]:::model
    end

    %% Main Application & Query Handling
    subgraph "Main Application & Query Handling"
        APP1["main.py"]:::mainapp
        APP2["newmain.py"]:::mainapp
        APP3["chat_history.py"]:::mainapp
    end

    %% Auxiliary Components
    subgraph "Auxiliary Components"
        AUX1["localaudio.py"]:::auxiliary
        AUX2["cagtest.py"]:::auxiliary
        AUX3["testvoice.html"]:::auxiliary
    end

    %% Configuration & Dependencies
    Config["requirements.txt"]:::config

    %% Connections between core components
    DS1 -->|"feeds"| IDX1
    DS2 -->|"feeds"| IDX2

    IDX1 -->|"processes"| NLP1
    IDX1 -->|"processes"| NLP2
    IDX2 -->|"processes"| NLP1
    IDX2 -->|"processes"| NLP3

    NLP1 -->|"generates output"| APP1
    NLP2 -->|"generates output"| APP2
    NLP3 -->|"generates output"| APP3

    %% Auxiliary components feeding into the main application
    AUX1 -->|"audio input"| APP1
    AUX2 -->|"testing"| APP1
    AUX3 -->|"demo"| APP1

    %% Configuration supports core operations
    Config ---|"dependency"| IDX1
    Config ---|"dependency"| NLP1
    Config ---|"dependency"| APP1

    %% Click Events for Data Sources
    click DS1 "https://github.com/ammar-alnagar/enlightener/tree/main/Data"
    click DS2 "https://github.com/ammar-alnagar/enlightener/tree/main/data2"

    %% Click Events for Data Preprocessing & Indexing
    click IDX1 "https://github.com/ammar-alnagar/enlightener/blob/main/Indexer.py"
    click IDX2 "https://github.com/ammar-alnagar/enlightener/blob/main/newindexer.py"

    %% Click Events for Core NLP Modules
    click NLP1 "https://github.com/ammar-alnagar/enlightener/blob/main/Mamba.py"
    click NLP2 "https://github.com/ammar-alnagar/enlightener/blob/main/Gemini.py"
    click NLP3 "https://github.com/ammar-alnagar/enlightener/blob/main/improvedrag.py"

    %% Click Events for Main Application & Query Handling
    click APP1 "https://github.com/ammar-alnagar/enlightener/blob/main/main.py"
    click APP2 "https://github.com/ammar-alnagar/enlightener/blob/main/newmain.py"
    click APP3 "https://github.com/ammar-alnagar/enlightener/blob/main/chat_history.py"

    %% Click Events for Auxiliary Components
    click AUX1 "https://github.com/ammar-alnagar/enlightener/blob/main/localaudio.py"
    click AUX2 "https://github.com/ammar-alnagar/enlightener/blob/main/cagtest.py"
    click AUX3 "https://github.com/ammar-alnagar/enlightener/blob/main/testvoice.html"

    %% Click Event for Configuration & Dependencies
    click Config "https://github.com/ammar-alnagar/enlightener/blob/main/requirements.txt"

    %% Styles
    classDef datain fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef preprocess fill:#FFF59D,stroke:#333,stroke-width:2px;
    classDef model fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef mainapp fill:#FFCC80,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#CE93D8,stroke:#333,stroke-width:2px;
    classDef config fill:#E0E0E0,stroke:#333,stroke-width:2px;
```
