# eisoptrophobicc/saatya-engine architecture

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

- Interactive diagram: https://gitdiagram.com/eisoptrophobicc/saatya-engine
- Repository: https://github.com/eisoptrophobicc/saatya-engine

## Overview

1. **Repo shape**
   - The repository is split into two largely separate application surfaces:
     - `backend/`: the main FastAPI-based fact-verification engine.
     - `frontend/`: a mixed frontend/prototype area with static UI assets plus its own Node and Django-based backend experiments.
   - For architecture diagrams, the **backend** is the core system; the frontend looks like an auxiliary presentation layer rather than the primary logic host.

2. **Primary backend entrypoint**
   - `backend/app/main.py` is the FastAPI application entrypoint, with `backend/run.py` as the launcher.
   - Routing is divided into feature-specific API modules:
     - `routes_claims.py`
     - `routes_verify.py`
     - `routes_report.py`
   - This indicates a clean boundary between claim intake, verification execution, and report delivery.

3. **Request/response boundary**
   - `backend/app/schemas/request.py` and `response.py` define the API contract.
   - `backend/app/adapter/response_adapter.py` suggests output normalization so internal pipeline results are converted into stable API responses.
   - `backend/app/models/claim.py` holds the core claim domain object used across the pipeline.

4. **Orchestration layer**
   - The main work is not done in the routes themselves; it is delegated to services and agents.
   - `backend/app/services/pipeline_service.py` appears to coordinate the overall workflow.
   - `claim_extractor.py`, `claim_analyzer.py`, `merge_service.py`, and `filter_service.py` suggest the pipeline breaks one input into multiple claims, cleans/merges them, and prepares them for independent verification.

5. **Agent-based verification core**
   - The repo uses a manual multi-agent design rather than a framework like LangChain.
   - `agents/query_agent.py` is likely responsible for gathering evidence or crafting search queries.
   - `agents/verification_agent.py` performs the final reasoning step over claims and evidence.
   - `services/input_agent.py` indicates an abstraction for taking user input and placing it into the agent flow.

6. **Evidence retrieval subsystem**
   - `services/search_service.py` and `services/evidence_service.py` form the evidence-collection boundary.
   - The README states real-time search is done via external search APIs, specifically Tavily, so the architecture includes an external search dependency outside the repo.
   - `utils/url_loader.py` and `utils/text_utils.py` support ingestion and normalization of source material before verification.

7. **LLM abstraction and fallback**
   - `backend/app/llm/llm_router.py` is the central abstraction for choosing which model/provider to use.
   - Provider-specific clients exist in `gemini_client.py` and `openrouter_client.py`.
   - This is a reliability boundary: the system can fall back between LLM providers when one is unavailable or less suitable.

8. **Verification and reporting**
   - `services/verification_service.py` is the main verifier, likely combining claim text, retrieved evidence, and LLM reasoning.
   - `services/report_generator.py` turns verification output into a structured report.
   - `api/routes_report.py` exposes that report generation result separately from the verification call, which is useful for asynchronous or multi-step workflows.

9. **Media verification subsystem**
   - The backend also supports non-text inputs through a separate media pipeline:
     - `media_router.py`
     - `media_model_loader.py`
     - `media_detection_service.py`
     - `image`, `video`, `audio`, and `ai_detection` services
   - The README notes local AI models and signal-processing-based audio checks, so this subsystem is intentionally independent from the LLM verification path and avoids relying on LLMs for media analysis.

10. **Dependency/config boundary**
   - `config.py` and `dependencies.py` centralize environment setup and dependency injection for the FastAPI app.
   - This likely isolates model clients, search clients, and service instances from the route layer, making the app easier to wire and test.

11. **Testing surface**
   - `backend/query_agent_test.py` and `backend/media_ai_test.py` show two important test targets:
     - the text/evidence agent flow
     - the media-analysis pipeline
   - This reinforces that the repository has two major technical branches: claim verification and media authenticity analysis.

12. **Frontend/prototype area**
   - `frontend/index.html`, `frontend/js/app.js`, and `frontend/css/styles.css` form a lightweight UI.
   - `frontend/backend/server.js` plus `users.json` indicate a small Node-based backend, while `frontend/backend_py/` contains a Django app with its own settings, URLs, and SQLite database.
   - This looks like a separate prototype or auxiliary app stack, not tightly integrated with the main FastAPI backend.

13. **End-to-end flow to draw**
   - The clearest architecture diagram is:
     - user input (text or URL, optionally media)
     - claim extraction and normalization
     - agent orchestration
     - external search/evidence retrieval
     - LLM-based claim verification
     - response adaptation and report generation
   - In parallel, media inputs can be routed through the local media-analysis pipeline before or alongside textual verification.

14. **Core architectural takeaway**
   - The repo is a modular verification platform with a strong separation between:
     - API surface
     - orchestration/services
     - agent reasoning
     - model/provider routing
     - media-analysis path
     - response/report formatting
   - That separation is the key thing to capture in an architecture diagram.

Main entry points: [`backend/app/services/pipeline_service.py`](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/pipeline_service.py) (Pipeline service), [`backend/app/main.py`](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/services/verification_service.py`](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/verification_service.py) (Verification service), [`backend/app/api/routes_claims.py`](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_claims.py) (Claims API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_main_app["FastAPI app<br/>entrypoint<br/>[main.py]"]
  node_api_claims["Claims API<br/>api route<br/>[routes_claims.py]"]
  node_api_verify["Verify API<br/>api route<br/>[routes_verify.py]"]
  node_api_report["Report API<br/>api route<br/>[routes_report.py]"]
  node_config_dep{{"Config & deps<br/>wiring<br/>[config.py]"}}
  node_schemas["API schemas<br/>contract<br/>[request.py]"]
  node_claim_model["Claim model<br/>domain model<br/>[claim.py]"]
  node_response_adapter["Response adapter"]
  node_pipeline_service{{"Pipeline service<br/>orchestrator"}}
  node_input_agent["Input agent<br/>[input_agent.py]"]
  node_claim_extractor["Claim extractor<br/>[claim_extractor.py]"]
  node_claim_analyzer["Claim analyzer<br/>[claim_analyzer.py]"]
  node_merge_filter["Merge/filter<br/>[merge_service.py]"]
  node_search_evidence{{"Search & evidence<br/>retrieval<br/>[search_service.py]"}}
  node_query_agent["Query agent<br/>[query_agent.py]"]
  node_verification_agent["Verifier agent"]
  node_llm_router{{"LLM router<br/>model router<br/>[llm_router.py]"}}
  node_verification_service{{"Verification service"}}
  node_report_generator["Report generator"]
  node_media_router["Media router<br/>media api<br/>[media_router.py]"]
  node_media_detection{{"Media detection<br/>media pipeline"}}
  node_media_models["Media models<br/>media loader"]
  node_text_utils["Text/url utils<br/>[text_utils.py]"]
end

subgraph group_frontend["Frontend"]
  node_ui_static["Static UI<br/>presentation<br/>[index.html]"]
  node_node_backend["Node backend<br/>prototype backend<br/>[server.js]"]
  node_django_backend["Django app<br/>prototype backend<br/>[manage.py]"]
end

node_main_app -->|"wired by"| node_config_dep
node_main_app -->|"mounts"| node_api_claims
node_main_app -->|"mounts"| node_api_verify
node_main_app -->|"mounts"| node_api_report
node_api_claims -->|"uses"| node_schemas
node_api_verify -->|"uses"| node_schemas
node_api_report -->|"uses"| node_response_adapter
node_api_claims -->|"delegates"| node_pipeline_service
node_api_verify -->|"delegates"| node_verification_service
node_api_report -->|"delegates"| node_report_generator
node_pipeline_service -->|"starts with"| node_input_agent
node_pipeline_service -->|"invokes"| node_claim_extractor
node_pipeline_service -->|"invokes"| node_claim_analyzer
node_pipeline_service -->|"invokes"| node_merge_filter
node_claim_extractor -->|"normalizes"| node_text_utils
node_claim_analyzer -->|"produces"| node_claim_model
node_verification_service -->|"retrieves"| node_search_evidence
node_verification_service -->|"orchestrates"| node_query_agent
node_verification_service -->|"reasons with"| node_verification_agent
node_query_agent -->|"queries"| node_search_evidence
node_verification_agent -->|"calls"| node_llm_router
node_llm_router -->|"returns"| node_verification_agent
node_llm_router -.->|"supports"| node_response_adapter
node_report_generator -->|"formats"| node_response_adapter
node_media_router -->|"delegates"| node_media_detection
node_media_detection -->|"loads"| node_media_models
node_media_detection -.->|"shares utils"| node_text_utils
node_ui_static -->|"calls"| node_api_claims
node_node_backend -->|"serves"| node_ui_static
node_django_backend -.->|"prototypes"| node_ui_static

click node_main_app "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/main.py"
click node_api_claims "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_claims.py"
click node_api_verify "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_verify.py"
click node_api_report "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_report.py"
click node_config_dep "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/config.py"
click node_schemas "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/schemas/request.py"
click node_claim_model "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/models/claim.py"
click node_response_adapter "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/adapter/response_adapter.py"
click node_pipeline_service "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/pipeline_service.py"
click node_input_agent "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/input_agent.py"
click node_claim_extractor "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/claim_extractor.py"
click node_claim_analyzer "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/claim_analyzer.py"
click node_merge_filter "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/merge_service.py"
click node_search_evidence "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/search_service.py"
click node_query_agent "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/agents/query_agent.py"
click node_verification_agent "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/agents/verification_agent.py"
click node_llm_router "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/llm/llm_router.py"
click node_verification_service "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/verification_service.py"
click node_report_generator "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/report_generator.py"
click node_media_router "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_router.py"
click node_media_detection "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_detection_service.py"
click node_media_models "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_model_loader.py"
click node_text_utils "https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/utils/text_utils.py"
click node_ui_static "https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/index.html"
click node_node_backend "https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/backend/server.js"
click node_django_backend "https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/backend_py/manage.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main_app,node_api_claims,node_api_verify,node_api_report,node_config_dep,node_schemas,node_claim_model,node_response_adapter,node_pipeline_service,node_input_agent,node_claim_extractor,node_claim_analyzer,node_merge_filter,node_search_evidence,node_query_agent,node_verification_agent,node_llm_router,node_verification_service,node_report_generator,node_media_router,node_media_detection,node_media_models,node_text_utils toneBlue
class node_ui_static,node_node_backend,node_django_backend toneAmber
```

## Components

### Backend

Primary FastAPI verification engine

- [FastAPI app](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/main.py): entrypoint · Application startup and app wiring · `backend/app/main.py`
- [Claims API](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_claims.py): api route · Claim intake and creation endpoints · `backend/app/api/routes_claims.py`
- [Verify API](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_verify.py): api route · Verification execution endpoints · `backend/app/api/routes_verify.py`
- [Report API](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/api/routes_report.py): api route · Report delivery endpoints · `backend/app/api/routes_report.py`
- [Config & deps](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/config.py): wiring · Environment setup and dependency injection · `backend/app/config.py`
- [API schemas](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/schemas/request.py): contract · Request and response shapes · `backend/app/schemas/request.py`
- [Claim model](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/models/claim.py): domain model · Core claim object shared across the pipeline · `backend/app/models/claim.py`
- [Response adapter](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/adapter/response_adapter.py): adapter · Normalizes internal results into API responses · `backend/app/adapter/response_adapter.py`
- [Pipeline service](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/pipeline_service.py): orchestrator · Coordinates claim processing workflow · `backend/app/services/pipeline_service.py`
- [Input agent](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/input_agent.py): service · Ingests user input into the agent flow · `backend/app/services/input_agent.py`
- [Claim extractor](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/claim_extractor.py): service · Splits inputs into candidate claims · `backend/app/services/claim_extractor.py`
- [Claim analyzer](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/claim_analyzer.py): service · Analyzes and prepares claims for verification · `backend/app/services/claim_analyzer.py`
- [Merge/filter](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/merge_service.py): service · Cleans, merges, and filters claims · `backend/app/services/merge_service.py`
- [Search & evidence](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/search_service.py): retrieval · External search and evidence collection boundary · `backend/app/services/search_service.py`
- [Query agent](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/agents/query_agent.py): agent · Builds search queries and gathers evidence · `backend/app/agents/query_agent.py`
- [Verifier agent](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/agents/verification_agent.py): agent · Reasons over claims and evidence · `backend/app/agents/verification_agent.py`
- [LLM router](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/llm/llm_router.py): model router · Selects provider and handles fallback · `backend/app/llm/llm_router.py`
- [Verification service](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/verification_service.py): service · Combines claims, evidence, and LLM reasoning · `backend/app/services/verification_service.py`
- [Report generator](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/report_generator.py): service · Creates structured verification reports · `backend/app/services/report_generator.py`
- [Media router](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_router.py): media api · Entry to media authenticity analysis · `backend/app/services/media_router.py`
- [Media detection](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_detection_service.py): media pipeline · Coordinates image, video, audio, and AI checks · `backend/app/services/media_detection_service.py`
- [Media models](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/services/media_model_loader.py): media loader · Loads local models used by media analysis · `backend/app/services/media_model_loader.py`
- [Text/url utils](https://github.com/eisoptrophobicc/saatya-engine/blob/main/backend/app/utils/text_utils.py): utility · Normalizes source text and loaded URLs · `backend/app/utils/text_utils.py`

### Frontend

Auxiliary UI and prototype stacks

- [Static UI](https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/index.html): presentation · Lightweight browser interface · `frontend/index.html`
- [Node backend](https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/backend/server.js): prototype backend · Small Node-based backend experiment · `frontend/backend/server.js`
- [Django app](https://github.com/eisoptrophobicc/saatya-engine/blob/main/frontend/backend_py/manage.py): prototype backend · Separate Django prototype stack · `frontend/backend_py/manage.py`

## Connections

- FastAPI app → Config & deps: wired by · App uses centralized config and dependencies
- FastAPI app → Claims API: mounts · Registers claim endpoints
- FastAPI app → Verify API: mounts · Registers verification endpoints
- FastAPI app → Report API: mounts · Registers report endpoints
- Claims API → API schemas: uses · Validates claim intake contract
- Verify API → API schemas: uses · Validates verification request contract
- Report API → Response adapter: uses · Formats report responses
- Claims API → Pipeline service: delegates · Hands off claim intake for processing
- Verify API → Verification service: delegates · Runs verification workflow
- Report API → Report generator: delegates · Builds report payloads
- Pipeline service → Input agent: starts with · Begins by ingesting user input
- Pipeline service → Claim extractor: invokes · Extracts candidate claims
- Pipeline service → Claim analyzer: invokes · Analyzes extracted claims
- Pipeline service → Merge/filter: invokes · Cleans and consolidates claims
- Claim extractor → Text/url utils: normalizes · Prepares text and URL sources
- Claim analyzer → Claim model: produces · Works on core claim objects
- Verification service → Search & evidence: retrieves · Collects supporting evidence
- Verification service → Query agent: orchestrates · Uses agent for evidence search
- Verification service → Verifier agent: reasons with · Runs final claim assessment
- Query agent → Search & evidence: queries · Forms and sends search requests
- Verifier agent → LLM router: calls · Uses provider routing for reasoning
- LLM router → Verifier agent: returns · Provides model output back to agent
- LLM router → Response adapter: supports · Model outputs are normalized for API use
- Report generator → Response adapter: formats · Converts results into report-ready responses
- Media router → Media detection: delegates · Hands media inputs to analysis pipeline
- Media detection → Media models: loads · Uses local models for analysis
- Media detection → Text/url utils: shares utils · Reuses normalization helpers where needed
- Static UI → Claims API: calls · Browser UI submits requests to backend APIs
- Node backend → Static UI: serves · Prototype Node layer serves the UI
- Django app → Static UI: prototypes · Separate Django stack alongside the static UI
