# saadan-hashmi-0p/dualis_ai architecture

> Architecture diagram of the GitHub repository saadan-hashmi-0p/dualis_ai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/saadan-hashmi-0p/dualis_ai
- Repository: https://github.com/saadan-hashmi-0p/dualis_ai

## Overview

##### Project Type and Purpose
- This is a lightweight, monolithic full-stack web application built with Streamlit. It serves as a chatbot UI (“frontend”) and chat-processing engine (“backend”) in one Python script (Dualis.py), augmented by custom CSS (style.css). It relies on the Hugging Face API as an external NLP service.

##### File Structure Analysis
- Dualis.py (the main app entrypoint: UI definitions, session-state management, mode-switching logic, API calls)
- style.css (custom styling for Streamlit components)
- README.md (project description, setup, tech stack)
- .gitattributes (VCS settings)
No separate folders for “frontend” vs. “backend”—both live in Dualis.py.

##### Key Components
a. Client Browser (User)
b. Streamlit App Server (Dualis.py)
– UI Layer: Streamlit widgets, chat history panels, typing animation
– Application Layer: Mode controller (General vs. Focused), session state for histories
– Utility Layer: PIL for logo handling, requests to external APIs
c. External NLP Service: Hugging Face API (authentication via secrets.toml)
d. Assets: style.css (injected into the UI)

##### Relationships & Data Flows
1. User enters a message in the browser → HTTP to Streamlit server
2. Streamlit UI invokes Dualis.py chat handler
3. Chat handler selects mode → formats request → uses requests library to call Hugging Face API
4. API returns generated text → Dualis.py updates session state → Streamlit pushes new message to UI
5. Browser renders updated chat history (styled by style.css)

##### Architectural Patterns & Design Principles
- Three-tier separation (Presentation / Application / External Service)
- Single-page, event-driven UI (Streamlit’s rerun model)
- Stateless external API calls, with session state held in memory
- Extendable modules (future OCR/PDF/TTS blocks can slot into Utility Layer)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Streamlit App Server"
        Dualis["Streamlit App (Dualis.py)"]:::logic
        subgraph "UI Layer"
            TextInput["st.text_input()"]:::user
            ChatPanel["st.chat_message() Panels"]:::user
            Typing["Typing Animation"]:::user
        end
        subgraph "Application Layer"
            ModeCtrl["Mode Controller (General vs. Focused)"]:::logic
            Session["Session State (in-memory)"]:::logic
        end
        subgraph "Utility Layer"
            PILMod["PIL.Image.open()"]:::logic
            ReqMod["requests.post()"]:::logic
            Planned["Planned Modules (OCR/PDF/TTS)"]:::logic
        end
    end

    Browser["Client Browser (User)"]:::user
    HuggingFace["Hugging Face API"]:::external
    Style["style.css"]:::asset
    README["README.md"]:::doc
    GIT[".gitattributes"]:::doc

    Browser -->|enter message| TextInput
    TextInput -->|triggers rerun| ChatPanel
    TextInput -->|calls handler| ModeCtrl
    ModeCtrl -->|formats request| ReqMod
    ReqMod -->|POST request| HuggingFace
    HuggingFace -->|returns response| ReqMod
    ReqMod -->|returns text| ModeCtrl
    ModeCtrl -->|updates| Session
    Session -->|renders| ChatPanel
    ChatPanel -->|display| Browser
    Style -->|injects CSS| ChatPanel

    click Dualis "https://github.com/saadan-hashmi-0p/dualis_ai/blob/main/Dualis.py"
    click Style "https://github.com/saadan-hashmi-0p/dualis_ai/blob/main/style.css"
    click README "https://github.com/saadan-hashmi-0p/dualis_ai/blob/main/README.md"
    click GIT "https://github.com/saadan-hashmi-0p/dualis_ai/blob/main/.gitattributes"

    classDef user fill:#CEE7F8,stroke:#0366d6,color:#0366d6
    classDef logic fill:#E2F8E1,stroke:#22863a,color:#22863a
    classDef external fill:#FFE8D6,stroke:#D15704,color:#D15704
    classDef asset fill:#F3E8FF,stroke:#6f42c1,color:#6f42c1
    classDef doc fill:#F0F0F0,stroke:#6a737d,color:#6a737d
```
