# redditarun/helix architecture

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

- Interactive diagram: https://gitdiagram.com/redditarun/helix
- Repository: https://github.com/redditarun/helix

## Overview

##### Project Type and Purpose
- From the file tree and README, Helix Agent is a full-stack web application.
- Frontend: React + TypeScript (Vite) for a user interface with chat, document upload, and workspace components.
- Backend: Flask (Python) providing REST APIs for chat, document ingestion, and sequence management.
- Persistence: PostgreSQL (via SQLAlchemy + Alembic migrations) and Pinecone (vector store).
- External AI Services: Gemini (LLM) and Pinecone (vector embeddings).

##### File Structure
- Top level:
- helix-backend/ – Flask service
- helix-frontend/ – React application
- helix-backend/app/
- api/ – route handlers: chat.py, document.py, sequence.py (controllers)
- services/ – business logic: chat_service.py, document_service.py, sequence_service.py
- models/ – ORM classes: Messages, Sequences, Session
- tools/ – utilities for external integrations (e.g., vector tooling, LLM prompts)
- config.py, extensions.py – app configuration, Flask extensions (SQLAlchemy, Migrate, CORS, etc.)
- helix-backend/migrations/ – Alembic DB migrations
- helix-backend/run.py – entrypoint for Flask server
- helix-frontend/src/components/ – UI components: ChatBox, DocumentUpload, NavBar, WorkSpace

##### README for Additional Insights
- The backend exposes REST endpoints on port 5000.
- The frontend runs on port 5173 and calls backend APIs.
- Requires setting environment variables for DB URL, Gemini API key, and Pinecone key.

##### Detailed Guidance
- Notes on environment-driven configuration and migrations (e.g., Alembic).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend UI" 
        direction TB
        ChatBox["ChatBox UI"]:::frontend
        DocumentUpload["Document Upload UI"]:::frontend
        NavBar["Navigation Bar"]:::frontend
        WorkSpace["Workspace UI"]:::frontend
    end

    %% Backend Entry Point
    RunServer["Flask Server (run.py)"]:::backend

    %% API Layer
    subgraph "API Layer" 
        direction TB
        ChatAPI["/api/chat Endpoint"]:::api
        DocumentAPI["/api/document Endpoint"]:::api
        SequenceAPI["/api/sequence Endpoint"]:::api
    end

    %% Service Layer
    subgraph "Service Layer"
        direction TB
        ChatService["ChatService"]:::service
        DocumentService["DocumentService"]:::service
        SequenceService["SequenceService"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        MessageModel["Message Model"]:::model
        SequenceModel["Sequence Model"]:::model
        SessionModel["Session Model"]:::model
    end

    %% Tools & Config & Extensions
    subgraph "Utilities & Config"
        direction TB
        Tools["Integration Utilities"]:::infra
        Config["App Config"]:::infra
        Extensions["Flask Extensions"]:::infra
        Migrations["Alembic Migrations"]:::infra
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Postgres["PostgreSQL"]:::external
        PineconeDB["Pinecone Vector Store"]:::external
        Gemini["Gemini LLM API"]:::external
    end

    %% Frontend to Backend
    ChatBox -->|"POST /api/chat"| ChatAPI
    DocumentUpload -->|"POST /api/document"| DocumentAPI
    WorkSpace -->|"POST /api/sequence"| SequenceAPI
    NavBar -->|"Navigate"| RunServer

    %% Entrypoint to API
    RunServer --> ChatAPI
    RunServer --> DocumentAPI
    RunServer --> SequenceAPI

    %% API to Services
    ChatAPI -->|"chat_service.generate_response()"| ChatService
    DocumentAPI -->|"document_service.ingest()"| DocumentService
    SequenceAPI -->|"sequence_service.manage()"| SequenceService

    %% Services to Data & Tools
    ChatService -->|"CRUD"| MessageModel
    ChatService -->|"embed/query"| PineconeDB
    ChatService -->|"generate"| Gemini

    DocumentService -->|"CRUD"| SessionModel
    DocumentService -->|"embed/upsert"| PineconeDB
    DocumentService -->|"tooling"| Tools

    SequenceService -->|"CRUD"| SequenceModel
    SequenceService -->|"logic"| Tools

    %% Config & Extensions usage
    RunServer --> Config
    RunServer --> Extensions
    Config --> Extensions
    Extensions --> MessageModel
    Extensions --> SequenceModel
    Extensions --> SessionModel

    %% Migrations to DB
    Migrations --> Postgres

    %% Click Events
    click ChatBox "https://github.com/redditarun/helix/blob/main/helix-frontend/src/components/chatbox/ChatBox.tsx"
    click DocumentUpload "https://github.com/redditarun/helix/blob/main/helix-frontend/src/components/documents/DocumentUpload.tsx"
    click NavBar "https://github.com/redditarun/helix/blob/main/helix-frontend/src/components/navbar/NavBar.tsx"
    click WorkSpace "https://github.com/redditarun/helix/blob/main/helix-frontend/src/components/workspace/WorkSpace.tsx"
    click RunServer "https://github.com/redditarun/helix/blob/main/helix-backend/run.py"
    click ChatAPI "https://github.com/redditarun/helix/blob/main/helix-backend/app/api/chat.py"
    click DocumentAPI "https://github.com/redditarun/helix/blob/main/helix-backend/app/api/document.py"
    click SequenceAPI "https://github.com/redditarun/helix/blob/main/helix-backend/app/api/sequence.py"
    click ChatService "https://github.com/redditarun/helix/blob/main/helix-backend/app/services/chat_service.py"
    click DocumentService "https://github.com/redditarun/helix/blob/main/helix-backend/app/services/document_service.py"
    click SequenceService "https://github.com/redditarun/helix/blob/main/helix-backend/app/services/sequence_service.py"
    click MessageModel "https://github.com/redditarun/helix/blob/main/helix-backend/app/models/messages.py"
    click SequenceModel "https://github.com/redditarun/helix/blob/main/helix-backend/app/models/sequences.py"
    click SessionModel "https://github.com/redditarun/helix/blob/main/helix-backend/app/models/session.py"
    click Migrations "https://github.com/redditarun/helix/tree/main/helix-backend/migrations/"
    click Tools "https://github.com/redditarun/helix/blob/main/helix-backend/app/tools/all_tools.py"
    click Config "https://github.com/redditarun/helix/blob/main/helix-backend/app/config.py"
    click Extensions "https://github.com/redditarun/helix/blob/main/helix-backend/app/extensions.py"

    %% Styling
    classDef frontend fill:#D6EAF8,stroke:#5DADE2,color:#154360
    classDef backend fill:#D5F5E3,stroke:#27AE60,color:#145A32
    classDef api fill:#FCF3CF,stroke:#F4D03F,color:#7D6608
    classDef service fill:#FCF3CF,stroke:#F4D03F,color:#7D6608
    classDef model fill:#FADBD8,stroke:#EC7063,color:#78281F
    classDef infra fill:#E8DAEF,stroke:#A569BD,color:#4A235A
    classDef external fill:#F5CBA7,stroke:#EB984E,color:#6E2C00
```
