# amoghk04/genhat architecture

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

- Interactive diagram: https://gitdiagram.com/amoghk04/genhat
- Repository: https://github.com/amoghk04/genhat

## Overview

##### Project type and purpose
- GenHat is a full-stack document intelligence platform.
- Frontend: Electron + TypeScript app providing a PDF viewer, interactive chat UI, file management.
- Backend: Python FastAPI service for PDF parsing, hybrid retrieval (BM25 + embeddings), AI analysis (Google Gemini), and text-to-speech (Azure).

##### File structure
- Top-level:
- Backend/ – FastAPI project (app.py, server.py, pdf_extractor.py, prompt_cache.py, temp_manager.py, requirements.txt) and a src/ folder divided into extract/, retrieval/, output/, utils/, plus a run_pipeline.py.
- Frontend/ – Electron app (index.html, main.js, package.json, src/api.ts, pdfViewer.ts, renderer.ts), plus integration/testing docs.
- setup.sh, run.sh – orchestration scripts.
- Patterns:
- Clear separation of concerns in Backend (extraction, retrieval, formatting).
- REST API boundary between Frontend and Backend.
- Pipeline runner module (run_pipeline.py).
- File-based caching and vector store under src/retrieval.

##### README for additional insights
- Confirms architecture: Frontend↔Backend over HTTP.
- Backend modules: PDF Parser → Content Chunker → Heading Extractor → Hybrid Retriever → Formatter → Gemini API/Azure Speech.
- Data persistence: local file cache, vector database for embeddings.
- External dependencies: Gemini API, Azure Speech.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User and Frontend Layer
    User["User"]:::external
    subgraph "Frontend Layer"
        direction TB
        indexHTML["index.html"]:::frontend
        mainJS["main.js"]:::frontend
        Renderer["renderer.ts"]:::frontend
        APIClient["api.ts"]:::frontend
        PDFViewer["pdfViewer.ts"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        direction TB
        subgraph "API Layer"
            direction TB
            Server["server.py"]:::backend
            App["app.py"]:::backend
        end
        subgraph "Ingestion/Extraction"
            direction TB
            PDFExtractor["pdf_extractor.py"]:::backend
            ContentChunker["content_chunker.py"]:::backend
            HeadingExtractor["heading_extractor.py"]:::backend
        end
        subgraph "Pipeline Runner"
            direction TB
            Runner["run_pipeline.py"]:::backend
        end
        subgraph "Retrieval"
            direction TB
            HybridRetriever["hybrid_retriever.py"]:::backend
            VectorStore["vector_store.py"]:::storage
        end
        subgraph "Output & Formatting"
            direction TB
            Formatter["formatter.py"]:::backend
        end
        subgraph "Persistence"
            direction TB
            PromptCache["prompt_cache.py"]:::storage
            TempManager["temp_manager.py"]:::storage
            FileUtils["file_utils.py"]:::storage
            Requirements["requirements.txt"]:::storage
        end
    end

    %% External Services
    Google["Google Gemini API"]:::external
    Azure["Azure Text-to-Speech"]:::external

    %% Orchestration Scripts
    Setup["setup.sh"]:::backend
    RunScript["run.sh"]:::backend

    %% Connections
    User -->|Interacts| Renderer
    User -->|Views PDF| PDFViewer
    Renderer -->|Calls REST| APIClient
    APIClient -->|HTTP Request| Server
    Server -->|Routes to| App
    App -->|Invokes| Runner
    Runner -->|Uses| PDFExtractor
    Runner -->|Uses| ContentChunker
    Runner -->|Uses| HeadingExtractor
    Runner -->|Stores chunks| VectorStore
    Runner -->|Stores cache| TempManager
    Runner -->|Caches prompts| PromptCache
    App -->|Retrieves data| HybridRetriever
    HybridRetriever -->|Embeddings| VectorStore
    HybridRetriever -->|BM25 index| FileUtils
    App -->|Formats output| Formatter
    App -->|Calls| Google
    App -->|Calls| Azure
    Setup -->|Configures env| Requirements
    RunScript -->|Starts services| Server

    %% Click Events
    click indexHTML "https://github.com/amoghk04/genhat/blob/main/Frontend/index.html"
    click mainJS "https://github.com/amoghk04/genhat/blob/main/Frontend/main.js"
    click Renderer "https://github.com/amoghk04/genhat/blob/main/Frontend/src/renderer.ts"
    click APIClient "https://github.com/amoghk04/genhat/blob/main/Frontend/src/api.ts"
    click PDFViewer "https://github.com/amoghk04/genhat/blob/main/Frontend/src/pdfViewer.ts"
    click Server "https://github.com/amoghk04/genhat/blob/main/Backend/server.py"
    click App "https://github.com/amoghk04/genhat/blob/main/Backend/app.py"
    click PDFExtractor "https://github.com/amoghk04/genhat/blob/main/Backend/pdf_extractor.py"
    click ContentChunker "https://github.com/amoghk04/genhat/blob/main/Backend/src/extract/content_chunker.py"
    click HeadingExtractor "https://github.com/amoghk04/genhat/blob/main/Backend/src/extract/heading_extractor.py"
    click Runner "https://github.com/amoghk04/genhat/blob/main/Backend/src/run_pipeline.py"
    click HybridRetriever "https://github.com/amoghk04/genhat/blob/main/Backend/src/retrieval/hybrid_retriever.py"
    click VectorStore "https://github.com/amoghk04/genhat/blob/main/Backend/src/retrieval/vector_store.py"
    click Formatter "https://github.com/amoghk04/genhat/blob/main/Backend/src/output/formatter.py"
    click PromptCache "https://github.com/amoghk04/genhat/blob/main/Backend/prompt_cache.py"
    click TempManager "https://github.com/amoghk04/genhat/blob/main/Backend/temp_manager.py"
    click FileUtils "https://github.com/amoghk04/genhat/blob/main/Backend/src/utils/file_utils.py"
    click Requirements "https://github.com/amoghk04/genhat/blob/main/Backend/requirements.txt"
    click Setup "https://github.com/amoghk04/genhat/blob/main/setup.sh"
    click RunScript "https://github.com/amoghk04/genhat/blob/main/run.sh"

    %% Styles
    classDef frontend fill:#D3E5FF,stroke:#0366d6,color:#0366d6
    classDef backend fill:#E8F0FE,stroke:#1A73E8,color:#1A73E8
    classDef storage fill:#E6F4EA,stroke:#34A853,color:#34A853
    classDef external fill:#FFEFD5,stroke:#FF8C00,color:#CD6600
```
