# mohdzain98/docschat architecture

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

- Interactive diagram: https://gitdiagram.com/mohdzain98/docschat
- Repository: https://github.com/mohdzain98/docschat

## Overview

##### Project type and purpose
- Docschat is a full-stack, microservices-based web application that lets users upload and conversationally interact with various document types (PDF, TXT, CSV, PPTX, etc.) using Large Language Models (LLMs) and specialized retrieval tools.

##### File structure
- Top-level “Microservices” directory containing:
- LLM service (Python Flask) – handles document parsing, LLM queries, SQL execution, text extraction.
- User_auth service (Node.js/Express) – manages registration, login, JWT auth, user data models (Mongo or similar).
- “src” and “public” directories – React front-end application with Components, Context, State folders.
- “build” – production output of the React app.
- Configs: package.json, requirements.txt, GitHub Actions workflows for CI/CD per microservice.

##### README for additional insights
- Architecture description confirms microservices: Authentication, LLM processing, and a Tools service for Exa Search, Google Trends, Scholar, PubMed.
- Workflow: user logs in → uploads document → redirected to chat UI → front end sends queries to LLM service with auth token → LLM service orchestrates extraction and third-party tool calls.

a. Main components:
- Client (web browser)
- Front-end React application
- API Gateway or Front-end proxy
- User Authentication Microservice (Node.js/Express)
- LLM Microservice (Python Flask + bicycle.db)
- Tools Microservice / External Tools (SerpApi for Trends, Google Scholar API, PubMed API, Exa Search engine)
- Data stores: user database (MongoDB or similar), bicycle.db (SQLite), file storage (local or cloud)
- External LLM provider (OpenAI, Hugging Face)

b. Relationships and interactions:
1. User → React UI → Auth service (login/register) → issues JWT
2. React UI (with JWT) → API Gateway → routes to LLM service for document upload & chat queries
3. LLM service reads document from file storage, extracts text (pdf, pptx, spreadsheet modules), queries external LLM or internal chain logic, queries Tools service endpoints as needed
4. LLM service returns response to React UI
5. Auth service and LLM service persist data in their respective databases

c. Architectural patterns and design principles:
- Microservices: each service has its own repo, CI/CD, and runtime
- Stateless front-end communicates over REST/HTTP with backend services
- Token-based authentication (JWT) for API security
- Separation of concerns: Auth, LLM processing, and Tools retrieval in distinct services
- Externalized configuration (requirements.txt, package.json, GitHub workflows)

d. Key technologies and frameworks:
- Front-end: React, Context API, Redux-like state management
- Auth service: Node.js, Express, Mongoose (Mongo)
- LLM service: Python, Flask, SQLite (bicycle.db), custom document parsers
- Tools: SerpApi, Google Trends API, Scholar scraping modules, PubMed API
- CI/CD: GitHub Actions workflows per microservice

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Browser["Web Browser"]:::frontend

    %% Front-end
    subgraph "Front-end (React)" 
        direction TB
        FE["React App"]:::frontend
        FE_index["index.js"]:::frontend
        FE_app["App.js"]:::frontend
        FE_components["Components"]:::frontend
        FE_toolsui["Components/Tools"]:::frontend
        FE_context["Context"]:::frontend
        FE_state["State"]:::frontend
        FE_public["public"]:::frontend
        FE_build["build"]:::frontend
    end

    %% API Gateway
    APIG["Nginx/API Proxy"]:::backend

    %% Auth Service
    subgraph "Auth Service (Node.js)"
        direction TB
        Auth_srv["Auth Service"]:::backend
        Auth_index["index.js"]:::backend
        Auth_dbconn["db.js"]:::backend
        Auth_routes["routes"]:::backend
        Auth_access["routes/access.js"]:::backend
        Auth_auth["routes/auth.js"]:::backend
        Auth_tokens["routes/moretokens.js"]:::backend
        Auth_mail["routes/mail.js"]:::backend
        Auth_models["models"]:::backend
        Auth_User["models/User.js"]:::backend
        Auth_AccessModel["models/Acess.js"]:::backend
        Auth_Like["models/Like.js"]:::backend
        Auth_MoreTokens["models/MoreTokens.js"]:::backend
        Auth_middleware["middleware/fetchuser.js"]:::backend
        Auth_pkg["package.json"]:::backend
        Auth_CI[".github/workflows/main.yml"]:::backend
    end

    %% LLM Service
    subgraph "LLM Service (Python Flask)"
        direction TB
        LLM_srv["LLM Service"]:::backend
        LLM_app1["app.py"]:::backend
        LLM_app2["app2.py"]:::backend
        LLM_db["bicycle.db"]:::db
        LLM_initialize["Initialize.py"]:::backend
        LLM_pdftxt["pdftxt.py"]:::backend
        LLM_spread["spreadsheet.py"]:::backend
        LLM_ppt["files/pptword.py"]:::backend
        LLM_sql["sql.py"]:::backend
        LLM_static["static"]:::backend
        LLM_chain["static/Chain.py"]:::backend
        LLM_fname["static/Filename.py"]:::backend
        LLM_tokensmod["static/Tokens.py"]:::backend
        LLM_reqs["requirements.txt"]:::backend
        LLM_CI[".github/workflows/main.yml"]:::backend
    end

    %% Databases & Storage
    subgraph "Databases & Storage"
        direction TB
        MongoDB["MongoDB"]:::db
        FileStorage["File Storage"]:::db
    end

    %% External APIs
    subgraph "External APIs"
        direction TB
        OpenAI["OpenAI/HuggingFace"]:::external
        SerpApi["SerpApi (Trends)"]:::external
        GoogleScholar["Google Scholar"]:::external
        PubMed["PubMed API"]:::external
        ExaSearch["Exa Search"]:::external
    end

    %% Root CI
    Root_CI["Root CI/CD"]:::backend

    %% Connections
    Browser --> FE
    FE --> APIG
    APIG --> Auth_srv
    APIG --> LLM_srv
    Auth_srv --> MongoDB
    LLM_srv --> LLM_db
    LLM_srv --> FileStorage
    LLM_srv --> OpenAI
    LLM_srv --> SerpApi
    LLM_srv --> GoogleScholar
    LLM_srv --> PubMed
    LLM_srv --> ExaSearch
    Auth_srv -->|"JWT"| FE
    LLM_srv -->|"Response"| FE
    Root_CI -.-> Auth_CI
    Root_CI -.-> LLM_CI

    %% Click Events
    click FE_index "https://github.com/mohdzain98/docschat/blob/main//src/index.js"
    click FE_app "https://github.com/mohdzain98/docschat/blob/main//src/App.js"
    click FE_components "https://github.com/mohdzain98/docschat/tree/main//src/Components"
    click FE_toolsui "https://github.com/mohdzain98/docschat/tree/main//src/Components/Tools"
    click FE_context "https://github.com/mohdzain98/docschat/tree/main//src/Context"
    click FE_state "https://github.com/mohdzain98/docschat/tree/main//src/State"
    click FE_public "https://github.com/mohdzain98/docschat/tree/main//public"
    click FE_build "https://github.com/mohdzain98/docschat/tree/main//build"
    click Auth_srv "https://github.com/mohdzain98/docschat/tree/main//Microservices/User_auth"
    click Auth_index "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/index.js"
    click Auth_dbconn "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/db.js"
    click Auth_routes "https://github.com/mohdzain98/docschat/tree/main//Microservices/User_auth/routes"
    click Auth_access "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/routes/access.js"
    click Auth_auth "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/routes/auth.js"
    click Auth_tokens "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/routes/moretokens.js"
    click Auth_mail "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/routes/mail.js"
    click Auth_models "https://github.com/mohdzain98/docschat/tree/main//Microservices/User_auth/models"
    click Auth_User "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/models/User.js"
    click Auth_AccessModel "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/models/Acess.js"
    click Auth_Like "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/models/Like.js"
    click Auth_MoreTokens "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/models/MoreTokens.js"
    click Auth_middleware "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/middleware/fetchuser.js"
    click Auth_pkg "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/package.json"
    click Auth_CI "https://github.com/mohdzain98/docschat/blob/main//Microservices/User_auth/.github/workflows/main.yml"
    click LLM_srv "https://github.com/mohdzain98/docschat/tree/main//Microservices/LLM"
    click LLM_app1 "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/app.py"
    click LLM_app2 "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/app2.py"
    click LLM_db "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/bicycle.db"
    click LLM_initialize "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/Initialize.py"
    click LLM_pdftxt "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/pdftxt.py"
    click LLM_spread "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/spreadsheet.py"
    click LLM_ppt "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/files/pptword.py"
    click LLM_sql "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/sql.py"
    click LLM_static "https://github.com/mohdzain98/docschat/tree/main//Microservices/LLM/static"
    click LLM_chain "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/static/Chain.py"
    click LLM_fname "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/static/Filename.py"
    click LLM_tokensmod "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/static/Tokens.py"
    click LLM_reqs "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/requirements.txt"
    click LLM_CI "https://github.com/mohdzain98/docschat/blob/main//Microservices/LLM/.github/workflows/main.yml"
    click Root_CI "https://github.com/mohdzain98/docschat/blob/main//.github/workflows/main.yml"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef db fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
