# ananddangwal/docmind-ai architecture

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

- Interactive diagram: https://gitdiagram.com/ananddangwal/docmind-ai
- Repository: https://github.com/ananddangwal/docmind-ai

## Overview

Document Copilot is an analyst-facing research assistant for querying SEC filings and receiving answers with citations. The user workflow runs from sign-in and chat through retrieval, answer generation, citation validation, and streamed display. A separate corpus workflow loads filing sources, structures and chunks documents, embeds them, then verifies and activates searchable generations. The graph includes these documented capabilities; unsampled modules are represented by their exact tree paths, and edges are limited to relationships shown in excerpts, the source index, or README.

Main entry points: [`backend/app/chat/orchestrator.py`](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/orchestrator.py) (Turn Orchestrator), [`backend/app/retrieval/retriever.py`](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/retriever.py) (Document Retrieval), [`backend/app/database/session.py`](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/database/session.py) (Supabase Postgres), [`backend/ingest/chunk_and_embed.py`](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/chunk_and_embed.py) (Chunk and Embed)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Analyst Experience"]
  node_web_app["Research Interface<br/>[research-page.tsx]"]
  node_thread_chat["Thread Chat<br/>[ThreadChat.tsx]"]
  node_source_inspector["Citation Inspector"]
  node_frontend_auth["Sign-in<br/>[auth-context.tsx]"]
end

subgraph group_service["Chat Service"]
  node_auth_api["Auth Endpoint<br/>[router.py]"]
  node_chat_api["Chat API<br/>[chat.py]"]
  node_chat_orchestrator["Turn Orchestrator<br/>[orchestrator.py]"]
  node_chat_stream["Stream Formatting<br/>[streaming.py]"]
  node_chat_messages["Message Handling<br/>[messages.py]"]
end

subgraph group_research["Research and Grounding"]
  node_assistant_agent["Answer Agent<br/>[agent.py]"]
  node_assistant_deps["Agent Retrieval Tools<br/>[deps.py]"]
  node_retriever["Document Retrieval<br/>[retriever.py]"]
  node_retrieval_queries["Search Queries<br/>[queries.py]"]
  node_retrieval_fusion["Rank Fusion<br/>[fusion.py]"]
  node_query_embeddings["Query Embeddings<br/>[embeddings.py]"]
  node_grounding["Citation Validation<br/>[validator.py]"]
  node_answer_outputs["Answer Schemas<br/>[outputs.py]"]
end

subgraph group_corpus["Corpus Ingestion"]
  node_ingest_sources["Source Documents"]
  node_ingest_pipeline["Chunk and Embed<br/>[chunk_and_embed.py]"]
  node_chunking["Filing Chunking<br/>[chunking.py]"]
  node_sec_structure["SEC Structure<br/>[sec_structure.py]"]
  node_ingest_embeddings["Document Embeddings<br/>[embeddings.py]"]
  node_generation_verify["Generation Verification<br/>[verify.py]"]
  node_generation_activate["Generation Activation"]
end

subgraph group_state["Persistent State"]
  node_database[("Supabase Postgres<br/>[session.py]")]
  node_chat_storage["Chat Persistence<br/>[chats.py]"]
  node_models["Domain Models"]
end

node_analyst(("Analyst"))
node_gemini{{"Google Gemini"}}

node_analyst -->|"signs in"| node_frontend_auth
node_analyst -->|"asks questions"| node_web_app
node_web_app -.->|"opens chat"| node_thread_chat
node_frontend_auth -.->|"authenticates"| node_auth_api
node_thread_chat -->|"sends turns"| node_chat_api
node_chat_api -->|"delegates turns"| node_chat_orchestrator
node_chat_api -->|"handles messages"| node_chat_messages
node_chat_api -->|"loads threads"| node_chat_storage
node_chat_orchestrator -->|"retrieves evidence"| node_retriever
node_chat_orchestrator -.->|"runs analysis"| node_assistant_agent
node_chat_orchestrator -->|"saves turns"| node_chat_storage
node_chat_orchestrator -->|"validates answers"| node_grounding
node_chat_orchestrator -->|"streams response"| node_chat_stream
node_assistant_agent -->|"uses tools"| node_assistant_deps
node_assistant_agent -->|"generates answers"| node_gemini
node_assistant_deps -->|"queries passages"| node_retriever
node_retriever -->|"embeds query"| node_query_embeddings
node_retriever -->|"runs searches"| node_retrieval_queries
node_retriever -->|"fuses rankings"| node_retrieval_fusion
node_retriever -->|"reads chunks"| node_database
node_query_embeddings -->|"requests vectors"| node_gemini
node_grounding -->|"validates schema"| node_answer_outputs
node_grounding -.->|"provides citations"| node_source_inspector
node_chat_stream -.->|"streams events"| node_thread_chat
node_chat_storage -->|"reads and writes"| node_database
node_chat_storage -->|"uses records"| node_models
node_ingest_pipeline -->|"synchronizes filings"| node_ingest_sources
node_ingest_pipeline -->|"creates chunks"| node_chunking
node_chunking -->|"uses structure"| node_sec_structure
node_ingest_pipeline -->|"embeds chunks"| node_ingest_embeddings
node_ingest_embeddings -->|"requests vectors"| node_gemini
node_ingest_pipeline -->|"stores corpus"| node_database
node_generation_verify -.->|"checks generation"| node_database
node_generation_activate -.->|"activates generation"| node_database
node_generation_verify -->|"precedes activation"| node_generation_activate
node_models -.->|"defines records"| node_database

click node_web_app "https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/pages/research-page.tsx"
click node_thread_chat "https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/components/chat/ThreadChat.tsx"
click node_source_inspector "https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/components/chat/SourceInspector.tsx"
click node_frontend_auth "https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/auth/auth-context.tsx"
click node_auth_api "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/auth/router.py"
click node_chat_api "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/api/chat.py"
click node_chat_orchestrator "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/orchestrator.py"
click node_chat_stream "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/streaming.py"
click node_chat_messages "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/messages.py"
click node_assistant_agent "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/agent.py"
click node_assistant_deps "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/deps.py"
click node_retriever "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/retriever.py"
click node_retrieval_queries "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/queries.py"
click node_retrieval_fusion "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/fusion.py"
click node_query_embeddings "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/embeddings.py"
click node_grounding "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/grounding/validator.py"
click node_answer_outputs "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/outputs.py"
click node_ingest_sources "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/source_documents.py"
click node_ingest_pipeline "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/chunk_and_embed.py"
click node_chunking "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/chunking.py"
click node_sec_structure "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/sec_structure.py"
click node_ingest_embeddings "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/embeddings.py"
click node_generation_verify "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/verify.py"
click node_generation_activate "https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/activate_generation.py"
click node_database "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/database/session.py"
click node_chat_storage "https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/database/chats.py"
click node_models "https://github.com/ananddangwal/docmind-ai/tree/main/backend/app/database/models"

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_web_app,node_thread_chat,node_source_inspector,node_frontend_auth toneBlue
class node_auth_api,node_chat_api,node_chat_orchestrator,node_chat_stream,node_chat_messages toneAmber
class node_assistant_agent,node_assistant_deps,node_retriever,node_retrieval_queries,node_retrieval_fusion,node_query_embeddings,node_grounding,node_answer_outputs toneMint
class node_ingest_sources,node_ingest_pipeline,node_chunking,node_sec_structure,node_ingest_embeddings,node_generation_verify,node_generation_activate toneRose
class node_database,node_chat_storage,node_models,node_analyst,node_gemini toneIndigo
```

## Components

### Analyst Experience

- [Research Interface](https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/pages/research-page.tsx): `frontend/src/pages/research-page.tsx`
- [Thread Chat](https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/components/chat/ThreadChat.tsx): `frontend/src/components/chat/ThreadChat.tsx`
- [Citation Inspector](https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/components/chat/SourceInspector.tsx): `frontend/src/components/chat/SourceInspector.tsx`
- [Sign-in](https://github.com/ananddangwal/docmind-ai/blob/main/frontend/src/auth/auth-context.tsx): `frontend/src/auth/auth-context.tsx`

### Chat Service

- [Auth Endpoint](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/auth/router.py): `backend/app/auth/router.py`
- [Chat API](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/api/chat.py): `backend/app/api/chat.py`
- [Turn Orchestrator](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/orchestrator.py): `backend/app/chat/orchestrator.py`
- [Stream Formatting](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/streaming.py): `backend/app/chat/streaming.py`
- [Message Handling](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/chat/messages.py): `backend/app/chat/messages.py`

### Research and Grounding

- [Answer Agent](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/agent.py): `backend/app/assistant/agent.py`
- [Agent Retrieval Tools](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/deps.py): `backend/app/assistant/deps.py`
- [Document Retrieval](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/retriever.py): `backend/app/retrieval/retriever.py`
- [Search Queries](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/queries.py): `backend/app/retrieval/queries.py`
- [Rank Fusion](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/fusion.py): `backend/app/retrieval/fusion.py`
- [Query Embeddings](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/retrieval/embeddings.py): `backend/app/retrieval/embeddings.py`
- [Citation Validation](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/grounding/validator.py): `backend/app/grounding/validator.py`
- [Answer Schemas](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/assistant/outputs.py): `backend/app/assistant/outputs.py`

### Corpus Ingestion

- [Source Documents](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/source_documents.py): `backend/ingest/source_documents.py`
- [Chunk and Embed](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/chunk_and_embed.py): `backend/ingest/chunk_and_embed.py`
- [Filing Chunking](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/chunking.py): `backend/ingest/chunking.py`
- [SEC Structure](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/sec_structure.py): `backend/ingest/sec_structure.py`
- [Document Embeddings](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/embeddings.py): `backend/ingest/embeddings.py`
- [Generation Verification](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/verify.py): `backend/ingest/verify.py`
- [Generation Activation](https://github.com/ananddangwal/docmind-ai/blob/main/backend/ingest/activate_generation.py): `backend/ingest/activate_generation.py`

### Persistent State

- [Supabase Postgres](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [Chat Persistence](https://github.com/ananddangwal/docmind-ai/blob/main/backend/app/database/chats.py): `backend/app/database/chats.py`
- [Domain Models](https://github.com/ananddangwal/docmind-ai/tree/main/backend/app/database/models): `backend/app/database/models`

### Other components

- **Analyst**
- **Google Gemini**

## Connections

- Analyst → Sign-in: signs in (evidence: `README.md`)
- Analyst → Research Interface: asks questions (evidence: `README.md`)
- Research Interface → Thread Chat: opens chat
- Sign-in → Auth Endpoint: authenticates
- Thread Chat → Chat API: sends turns (evidence: `README.md`)
- Chat API → Turn Orchestrator: delegates turns (evidence: `backend/app/api/chat.py`)
- Chat API → Message Handling: handles messages (evidence: `backend/app/api/chat.py`)
- Chat API → Chat Persistence: loads threads (evidence: `backend/app/api/chat.py`)
- Turn Orchestrator → Document Retrieval: retrieves evidence (evidence: `backend/app/chat/orchestrator.py`)
- Turn Orchestrator → Answer Agent: runs analysis
- Turn Orchestrator → Chat Persistence: saves turns (evidence: `backend/app/chat/orchestrator.py`)
- Turn Orchestrator → Citation Validation: validates answers (evidence: `backend/app/chat/orchestrator.py`)
- Turn Orchestrator → Stream Formatting: streams response (evidence: `backend/app/chat/orchestrator.py`)
- Answer Agent → Agent Retrieval Tools: uses tools (evidence: `backend/app/assistant/agent.py`)
- Answer Agent → Google Gemini: generates answers (evidence: `README.md`)
- Agent Retrieval Tools → Document Retrieval: queries passages (evidence: `backend/app/assistant/deps.py`)
- Document Retrieval → Query Embeddings: embeds query (evidence: `backend/app/retrieval/retriever.py`)
- Document Retrieval → Search Queries: runs searches (evidence: `backend/app/retrieval/retriever.py`)
- Document Retrieval → Rank Fusion: fuses rankings (evidence: `backend/app/retrieval/retriever.py`)
- Document Retrieval → Supabase Postgres: reads chunks (evidence: `backend/app/retrieval/retriever.py`)
- Query Embeddings → Google Gemini: requests vectors (evidence: `README.md`)
- Citation Validation → Answer Schemas: validates schema (evidence: `backend/app/grounding/validator.py`)
- Citation Validation → Citation Inspector: provides citations
- Stream Formatting → Thread Chat: streams events
- Chat Persistence → Supabase Postgres: reads and writes (evidence: `backend/app/database/chats.py`)
- Chat Persistence → Domain Models: uses records (evidence: `backend/app/database/chats.py`)
- Chunk and Embed → Source Documents: synchronizes filings (evidence: `backend/ingest/chunk_and_embed.py`)
- Chunk and Embed → Filing Chunking: creates chunks (evidence: `backend/ingest/chunk_and_embed.py`)
- Filing Chunking → SEC Structure: uses structure (evidence: `backend/ingest/chunking.py`)
- Chunk and Embed → Document Embeddings: embeds chunks (evidence: `backend/ingest/chunk_and_embed.py`)
- Document Embeddings → Google Gemini: requests vectors (evidence: `backend/ingest/embeddings.py`)
- Chunk and Embed → Supabase Postgres: stores corpus (evidence: `backend/ingest/chunk_and_embed.py`)
- Generation Verification → Supabase Postgres: checks generation
- Generation Activation → Supabase Postgres: activates generation
- Generation Verification → Generation Activation: precedes activation (evidence: `README.md`)
- Domain Models → Supabase Postgres: defines records
