# raju1998060745/docsynapse architecture

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

- Interactive diagram: https://gitdiagram.com/raju1998060745/docsynapse
- Repository: https://github.com/raju1998060745/docsynapse

## Overview

##### Main Components
- Ingestion Handler (Service-1): Even if its implementation isn’t in the file tree, the README explains that there is a component that monitors document storage (e.g., AWS S3) to detect new/updated files and initiates the embedding process.
- Processing & Storage (Service-2): The directory “service_2” has subdirectories for API endpoints (e.g., “api/user_routes.py”), configuration (with logging config), and core business logic (e.g., splitting text, embedding, exception handling, models, and retrieval logic). This service handles processing uploaded documents (splitting, embedding, adding metadata) and storing/updating them in the vector store.
- Query & Answer Engine (Service-3): The “service_3” folder appears to host the frontend application that handles user interactions. It contains an “app.py” alongside static assets (CSS, JavaScript) and HTML templates (chat, home, login, register). This service is responsible for user authentication and managing the query process—receiving user queries, retrieving relevant document chunks, and then forwarding requests to the LLM(s) using GROQ.

##### Relationships & Data Flows
- Users interact with the Presentation/UI layer in Service-3 (login, document upload, chat interface).
- Service-3 then communicates with the backend (likely via API calls) to perform queries.
- When a document is uploaded via the ingestion process (Service-1, even if not directly visible in the file tree), it is processed by Service-2:
- Service-2 takes care of splitting the document, generating embeddings via core processing (see “process.py” and “retrieve.py”), and storing metadata in the vector store.
- When a query is issued from Service-3, it retrieves the relevant document chunks that Service-2 stored and then calls an LLM (or multiple, via GROQ integration) to generate a contextual answer.
- External dependencies include:
- Cloud storage (e.g., AWS S3) for document files.
- A vector store (such as FAISS, Pinecone, or Weaviate) for embeddings.
- LLM providers and an underlying database (for user authentication and metadata).

##### Architectural Patterns & Design Principles
- Modular Service Architecture: The division into Service-1, Service-2, and Service-3 indicates separation of concerns, where file ingestion, processing, and query handling are performed as distinct modules.
- API Layer: Service-2 exposes APIs (as noted by the “service_2/api” folder) which can be used by the frontend (Service-3) or possibly by the ingestion handler.
- Core Logic Encapsulation: The “core” directory within Service-2 encapsulates the text processing and embedding logic alongside exception handling.
- Presentation Layer: Service-3 uses a combination of templates and static assets, suggesting a server-rendered frontend (which might be backed by a framework like Flask or FastAPI even though the README mentions React / Next.js).

##### Technologies & Frameworks
- Backend: FastAPI for API endpoints and service integration (as per the README).
- Frontend: While the README names React/Next.js, the file tree’s “service_3” structure (templates, static files) suggests a server-side rendered approach.
- External Services: AWS S3 for storage; vector stores (FAISS/Pinecone/Weaviate) for document embeddings; various LLMs integrated via a GROQ orchestrator.
- Supporting Libraries: Use of configuration and logging (see “logger_config.py”), along with core modules for processing and exception handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    AWS_S3["AWS S3 (Cloud Storage)"]:::external
    LLM["LLM Providers"]:::external
    VSTORE["Vector Store"]:::external
    USERDB["User Database"]:::external
    USER["User"]:::external

    %% Ingestion Handler (Service-1)
    Ingestion_Handler["Ingestion Handler (Service-1)"]:::ingestion

    %% Processing & Storage (Service-2)
    subgraph "Processing & Storage (Service-2)"
        Service2_Entry["Service-2 Entry"]:::processing
        Service2_Wrapper["Service2 Wrapper"]:::processing
        Service2_API["API Endpoints"]:::api
        Service2_Process["Process Module"]:::core
        Service2_Retrieve["Retrieve Module"]:::core
        Service2_Models["Models Module"]:::core
        Service2_Exceptions["Exceptions Module"]:::core
        Service2_Config["Configuration/Logging"]:::config
    end

    %% Query & Answer Engine (Service-3)
    subgraph "Query & Answer Engine (Service-3)"
        Service3_Backend["Backend & UI"]:::query
        Service3_Static["Static Assets"]:::query
        Service3_Templates["Templates"]:::query
    end

    %% Data Flow Connections
    AWS_S3 -->|"upload_trigger"| Ingestion_Handler
    Ingestion_Handler -->|"triggers"| Service2_Entry
    Service2_Entry -->|"initiates_API"| Service2_API
    Service2_API -->|"calls_processing"| Service2_Process
    Service2_Process -->|"stores_embeddings"| VSTORE
    Service2_Process -->|"retrieves_sections"| Service2_Retrieve
    Service2_Retrieve -->|"returns_chunks"| Service2_API
    Service2_API -->|"optionally_wraps"| Service2_Wrapper

    %% User Query Flow
    USER -->|"visits"| Service3_Templates
    Service3_Templates -->|"renders_UI"| Service3_Backend
    Service3_Backend -->|"authenticates_with"| USERDB
    Service3_Backend -->|"queries_via_API"| Service2_API
    Service2_API -->|"fetches_docs"| Service2_Retrieve
    Service2_Retrieve -->|"queries_LLM"| LLM
    LLM -->|"returns_answer"| Service2_API
    Service3_Backend -->|"displays_response"| USER

    %% Styling Classes
    classDef ingestion fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef processing fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef query fill:#f9844a,stroke:#333,stroke-width:2px;
    classDef external fill:#577590,stroke:#333,stroke-width:2px,color:#fff;
    classDef core fill:#277da1,stroke:#333,stroke-width:2px,color:#fff;
    classDef api fill:#f3722c,stroke:#333,stroke-width:2px,color:#fff;
    classDef config fill:#f94144,stroke:#333,stroke-width:2px,color:#fff;

    %% Click Events for Service-2 Components
    click Service2_API "https://github.com/raju1998060745/docsynapse/blob/main/service_2/api/user_routes.py"
    click Service2_Process "https://github.com/raju1998060745/docsynapse/blob/main/service_2/core/process.py"
    click Service2_Retrieve "https://github.com/raju1998060745/docsynapse/blob/main/service_2/core/retrieve.py"
    click Service2_Models "https://github.com/raju1998060745/docsynapse/blob/main/service_2/core/models.py"
    click Service2_Exceptions "https://github.com/raju1998060745/docsynapse/blob/main/service_2/core/exceptions.py"
    click Service2_Config "https://github.com/raju1998060745/docsynapse/blob/main/service_2/config/logger_config.py"
    click Service2_Entry "https://github.com/raju1998060745/docsynapse/blob/main/service_2/main.py"
    click Service2_Wrapper "https://github.com/raju1998060745/docsynapse/blob/main/service2.py"

    %% Click Events for Service-3 Components
    click Service3_Backend "https://github.com/raju1998060745/docsynapse/blob/main/service_3/app.py"
    click Service3_Static "https://github.com/raju1998060745/docsynapse/tree/main/service_3/static/"
    click Service3_Templates "https://github.com/raju1998060745/docsynapse/tree/main/service_3/templates/"
```
