# alankritkadian/pathway_rag architecture

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

- Interactive diagram: https://gitdiagram.com/alankritkadian/pathway_rag
- Repository: https://github.com/alankritkadian/pathway_rag

## Overview

##### Project type and purpose
- This is a full-stack web application that provides an interactive chat/replay/upload UI (built in Next.js/React) and a Python-based backend (“PathwayVectorServer”) that ingests documents, runs retrieval-augmented generation (RAG), domain-specific services (finance, maths, report generation), and returns structured chat responses.
- The README describes how to launch the backend (`python main.py` in the `server` folder) and the client (`Dockerfile` in `client` or `npm run dev` inside `client/client`).

##### File structure
- Top level:
- Dockerfile – containerizes the whole stack
- main.py & requirements.txt – a root-level script (likely a legacy entrypoint)
- client/ – Next.js TypeScript application
- server/ – Python Flask (or FastAPI) app with Socket.IO wrapper
- docs/, videos/ – static documentation
- client/ contains its own Dockerfile, README, and all UI code under `client/client/src`. Key folders:
- `app/` – Next.js app routes (chat, upload, replay)
- `components/` – reusable UI pieces (chat window, landing page, UI primitives)
- `firebase/` – Firebase initialization
- `pages/api/upload.ts` – REST endpoint for file uploads
- server/ contains:
- `app.py` & `routes.py` – main HTTP/WebSocket entrypoints
- `sio_wrapper.py` – wraps Socket.IO for real-time messaging
- `services/` – core business logic (architectural orchestrator, RAG engines, domain services, output parsing, report gen)

##### README for additional insights
- The server is called “PathwayVectorServer”—it uses the external `pathway_lib_zipped.zip` as a vector-store/processing engine.
- The backend runs in a virtual environment with dependencies in `server/requirements.txt`.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        Browser["User Browser"]:::external
        NextJs["Next.js Frontend"]:::frontend
        Firebase["Firebase Auth"]:::external
        UploadAPI["Upload API Endpoint"]:::api
        AppRoutes["React App Routes"]:::frontend
        UIComponents["Reusable UI Components"]:::frontend
    end

    %% Real-time Layer
    subgraph "Real-time Layer"
        SocketWrapper["Socket.IO Server Wrapper"]:::backend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        AppPy["Python Backend Entrypoints"]:::backend
        Routes["HTTP/WebSocket Routes"]:::backend
        Orchestrator["Service Orchestrator"]:::backend
        AdaptiveRAG["RAG Engine - Adaptive Retrieval"]:::service
        ModularAgent["RAG Engine - Modular Agent"]:::service
        FinanceService["Domain Service - Finance"]:::service
        FinanceConfig["Finance Personas Config"]:::service
        MathsService["Domain Service - Maths Executor"]:::service
        ReportService["Domain Service - Report Generation"]:::service
        OutputParser["Output Parser"]:::service
        ResponseTransform["Response Transformation"]:::service
        BadQuery["Bad Query Handling"]:::service
        Constants["Constants & Config"]:::service
        TestingNotebook["Test Notebook"]:::service
        TestData["Test Data"]:::service
        PathwayStore["Pathway Vector Store"]:::database
        LLM["LLM API"]:::external
        Storage["Persistent Storage"]:::database
    end

    %% Infrastructure
    subgraph "Infrastructure"
        DockerRoot["Root Dockerfile"]:::infra
        DockerClient["Client Dockerfile"]:::infra
        MainReq["Server Requirements"]:::infra
        MainScript["Root main.py"]:::infra
    end

    %% Connections - Frontend
    Browser --> NextJs
    NextJs --> UploadAPI
    NextJs --> AppRoutes
    NextJs --> UIComponents
    NextJs --> Firebase
    NextJs --> SocketWrapper

    %% Connections - Frontend to Backend
    UploadAPI --> AppPy
    SocketWrapper --> AppPy

    %% Backend internal flows
    AppPy --> Routes
    Routes --> Orchestrator
    Orchestrator --> AdaptiveRAG
    Orchestrator --> ModularAgent
    Orchestrator --> FinanceService
    FinanceService --> FinanceConfig
    Orchestrator --> MathsService
    Orchestrator --> ReportService
    Orchestrator --> OutputParser
    OutputParser --> ResponseTransform
    Orchestrator --> BadQuery
    Orchestrator --> Constants
    Orchestrator --> PathwayStore
    Orchestrator --> LLM
    Orchestrator --> Storage

    %% Infrastructure usage
    DockerRoot --> DockerClient
    DockerRoot --> MainReq
    DockerRoot --> MainScript

    %% Click events
    click NextJs "https://github.com/alankritkadian/pathway_rag/tree/main/client/client"
    click Firebase "https://github.com/alankritkadian/pathway_rag/blob/main/client/client/src/firebase/firebase.ts"
    click UploadAPI "https://github.com/alankritkadian/pathway_rag/blob/main/client/client/src/pages/api/upload.ts"
    click AppRoutes "https://github.com/alankritkadian/pathway_rag/tree/main/client/client/src/app"
    click UIComponents "https://github.com/alankritkadian/pathway_rag/tree/main/client/client/src/components"
    click SocketWrapper "https://github.com/alankritkadian/pathway_rag/blob/main/server/sio_wrapper.py"
    click AppPy "https://github.com/alankritkadian/pathway_rag/blob/main/server/app.py"
    click Routes "https://github.com/alankritkadian/pathway_rag/blob/main/server/routes.py"
    click Orchestrator "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/Architecture.py"
    click AdaptiveRAG "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/new_adaptive_rag.py"
    click ModularAgent "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/modular_agent.py"
    click FinanceService "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/finance/finance_group.py"
    click FinanceConfig "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/finance/personas.json"
    click MathsService "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/maths/code_executor.py"
    click ReportService "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/report_gen/report_gen.py"
    click OutputParser "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/output_parser.py"
    click ResponseTransform "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/response_transformation.py"
    click BadQuery "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/Bad_queries.py"
    click Constants "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/constants.py"
    click TestingNotebook "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/testing/Testing.ipynb"
    click TestData "https://github.com/alankritkadian/pathway_rag/blob/main/server/services/test.json"
    click PathwayStore "https://github.com/alankritkadian/pathway_rag/blob/main/pathway_lib_zipped.zip"
    click DockerRoot "https://github.com/alankritkadian/pathway_rag/tree/main/Dockerfile"
    click DockerClient "https://github.com/alankritkadian/pathway_rag/tree/main/client/Dockerfile"
    click MainReq "https://github.com/alankritkadian/pathway_rag/blob/main/server/requirements.txt"
    click MainScript "https://github.com/alankritkadian/pathway_rag/blob/main/main.py"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#0288D1,color:#000;
    classDef backend fill:#C8E6C9,stroke:#388E3C,color:#000;
    classDef service fill:#A5D6A7,stroke:#2E7D32,color:#000;
    classDef database fill:#FFE0B2,stroke:#F57C00,color:#000;
    classDef external fill:#E1BEE7,stroke:#8E24AA,color:#000;
    classDef api fill:#B3E5FC,stroke:#039BE5,color:#000;
    classDef infra fill:#CFD8DC,stroke:#546E7A,color:#000;
```
