# rexya05/findocai architecture

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

- Interactive diagram: https://gitdiagram.com/rexya05/findocai
- Repository: https://github.com/rexya05/findocai

## Overview

FinDocAI turns SEC filing PDFs into searchable, citation-grounded answers, then audits those answers before presenting them through a UI or REST API. The documented ingestion path extracts, cleans, chunks, embeds, and stores filing text; the query path retrieves relevant chunks, generates an answer, and checks citations and faithfulness. A LangGraph workflow adds routing, revision, and remediation, while a benchmark module compares baseline and agentic behavior. The graph combines sampled source with README descriptions; some agent wiring and API details were not fully shown, so those links rely on documented behavior.

Main entry points: [`src/stage6_api.py`](https://github.com/rexya05/findocai/blob/main/src/stage6_api.py) (FastAPI Service), [`src/stage7_ui.py`](https://github.com/rexya05/findocai/blob/main/src/stage7_ui.py) (Streamlit UI), [`src/stage8_agents.py`](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py) (Compliance Auditor), [`src/stage4_rag.py`](https://github.com/rexya05/findocai/blob/main/src/stage4_rag.py) (Grounded RAG)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Filing Ingestion"]
  node_extract["PDF Extraction"]
  node_chunk["Text Chunking<br/>[stage2_chunking.py]"]
  node_embed["Embeddings<br/>[stage3_embed.py]"]
end

subgraph group_analysis["Grounded Analysis"]
  node_rag["Grounded RAG<br/>[stage4_rag.py]"]
  node_guardrails["Answer Guardrails"]
  node_router["Query Router<br/>[stage8_agents.py]"]
  node_agent_retriever["Agent Retriever<br/>[stage8_agents.py]"]
  node_analyst["Financial Analyst<br/>[stage8_agents.py]"]
  node_auditor["Compliance Auditor<br/>[stage8_agents.py]"]
  node_remediation["Remediation Node<br/>[stage8_agents.py]"]
end

subgraph group_serving["User Interfaces"]
  node_api["FastAPI Service<br/>[stage6_api.py]"]
  node_ui["Streamlit UI<br/>[stage7_ui.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Benchmark Evaluation<br/>[stage9_eval.py]"]
end

node_user(("User"))
node_sec["SEC EDGAR"]
node_vectors[("Chunk Vector Store")]
node_gemini["Gemini"]

node_user -->|"submits query"| node_ui
node_ui -->|"calls REST API"| node_api
node_user -->|"calls REST API"| node_api
node_api -->|"downloads and extracts"| node_extract
node_extract -->|"downloads PDF"| node_sec
node_api -->|"cleans and chunks"| node_chunk
node_api -->|"indexes chunks"| node_embed
node_embed -->|"stores vectors"| node_vectors
node_rag -->|"searches vectors"| node_embed
node_rag -->|"generates answer"| node_gemini
node_api -->|"requests answer"| node_rag
node_api -->|"verifies answer"| node_guardrails
node_guardrails -->|"scores faithfulness"| node_gemini
node_router -->|"routes in-scope"| node_agent_retriever
node_agent_retriever -->|"retrieves chunks"| node_embed
node_agent_retriever -->|"provides context"| node_analyst
node_analyst -->|"submits draft"| node_auditor
node_auditor -->|"returns critique"| node_analyst
node_auditor -->|"routes after retries"| node_remediation
node_router -->|"returns routed result"| node_ui
node_auditor -->|"returns approved answer"| node_ui
node_remediation -->|"returns safe response"| node_ui
node_evaluation -->|"benchmarks baseline"| node_rag
node_evaluation -->|"benchmarks agent graph"| node_router

click node_extract "https://github.com/rexya05/findocai/blob/main/src/stage1_extractor.py"
click node_chunk "https://github.com/rexya05/findocai/blob/main/src/stage2_chunking.py"
click node_embed "https://github.com/rexya05/findocai/blob/main/src/stage3_embed.py"
click node_rag "https://github.com/rexya05/findocai/blob/main/src/stage4_rag.py"
click node_guardrails "https://github.com/rexya05/findocai/blob/main/src/stage5_guardrails.py"
click node_api "https://github.com/rexya05/findocai/blob/main/src/stage6_api.py"
click node_ui "https://github.com/rexya05/findocai/blob/main/src/stage7_ui.py"
click node_router "https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py"
click node_agent_retriever "https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py"
click node_analyst "https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py"
click node_auditor "https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py"
click node_remediation "https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py"
click node_evaluation "https://github.com/rexya05/findocai/blob/main/src/stage9_eval.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_extract,node_chunk,node_embed,node_user toneBlue
class node_rag,node_guardrails,node_router,node_agent_retriever,node_analyst,node_auditor,node_remediation,node_vectors toneAmber
class node_api,node_ui toneMint
class node_evaluation toneRose
class node_sec,node_gemini toneIndigo
```

## Components

### Filing Ingestion

- [PDF Extraction](https://github.com/rexya05/findocai/blob/main/src/stage1_extractor.py): `src/stage1_extractor.py`
- [Text Chunking](https://github.com/rexya05/findocai/blob/main/src/stage2_chunking.py): `src/stage2_chunking.py`
- [Embeddings](https://github.com/rexya05/findocai/blob/main/src/stage3_embed.py): `src/stage3_embed.py`

### Grounded Analysis

- [Grounded RAG](https://github.com/rexya05/findocai/blob/main/src/stage4_rag.py): `src/stage4_rag.py`
- [Answer Guardrails](https://github.com/rexya05/findocai/blob/main/src/stage5_guardrails.py): `src/stage5_guardrails.py`
- [Query Router](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py): `src/stage8_agents.py`
- [Agent Retriever](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py): `src/stage8_agents.py`
- [Financial Analyst](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py): `src/stage8_agents.py`
- [Compliance Auditor](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py): `src/stage8_agents.py`
- [Remediation Node](https://github.com/rexya05/findocai/blob/main/src/stage8_agents.py): `src/stage8_agents.py`

### User Interfaces

- [FastAPI Service](https://github.com/rexya05/findocai/blob/main/src/stage6_api.py): `src/stage6_api.py`
- [Streamlit UI](https://github.com/rexya05/findocai/blob/main/src/stage7_ui.py): `src/stage7_ui.py`

### Evaluation

- [Benchmark Evaluation](https://github.com/rexya05/findocai/blob/main/src/stage9_eval.py): `src/stage9_eval.py`

### Other components

- **User**
- **SEC EDGAR**
- **Chunk Vector Store**
- **Gemini**

## Connections

- User → Streamlit UI: submits query (evidence: `README.md`)
- Streamlit UI → FastAPI Service: calls REST API (evidence: `src/stage7_ui.py`)
- User → FastAPI Service: calls REST API (evidence: `README.md`)
- FastAPI Service → PDF Extraction: downloads and extracts (evidence: `src/stage6_api.py`)
- PDF Extraction → SEC EDGAR: downloads PDF (evidence: `src/stage1_extractor.py`)
- FastAPI Service → Text Chunking: cleans and chunks (evidence: `src/stage6_api.py`)
- FastAPI Service → Embeddings: indexes chunks (evidence: `src/stage6_api.py`)
- Embeddings → Chunk Vector Store: stores vectors (evidence: `src/stage3_embed.py`)
- Grounded RAG → Embeddings: searches vectors (evidence: `src/stage4_rag.py`)
- Grounded RAG → Gemini: generates answer (evidence: `src/stage4_rag.py`)
- FastAPI Service → Grounded RAG: requests answer (evidence: `src/stage6_api.py`)
- FastAPI Service → Answer Guardrails: verifies answer (evidence: `README.md`)
- Answer Guardrails → Gemini: scores faithfulness (evidence: `src/stage5_guardrails.py`)
- Query Router → Agent Retriever: routes in-scope (evidence: `README.md`)
- Agent Retriever → Embeddings: retrieves chunks (evidence: `src/stage8_agents.py`)
- Agent Retriever → Financial Analyst: provides context (evidence: `README.md`)
- Financial Analyst → Compliance Auditor: submits draft (evidence: `README.md`)
- Compliance Auditor → Financial Analyst: returns critique (evidence: `README.md`)
- Compliance Auditor → Remediation Node: routes after retries (evidence: `README.md`)
- Query Router → Streamlit UI: returns routed result (evidence: `README.md`)
- Compliance Auditor → Streamlit UI: returns approved answer (evidence: `README.md`)
- Remediation Node → Streamlit UI: returns safe response (evidence: `README.md`)
- Benchmark Evaluation → Grounded RAG: benchmarks baseline (evidence: `src/stage9_eval.py`)
- Benchmark Evaluation → Query Router: benchmarks agent graph (evidence: `src/stage9_eval.py`)
