# team-finch/finch-ai architecture

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

- Interactive diagram: https://gitdiagram.com/team-finch/finch-ai
- Repository: https://github.com/team-finch/finch-ai

## Overview

FINCH AI is a FastAPI service for financial analysis and grounded LLM responses. The principal flow is backend request → feature route → deterministic calculations and/or retrieval → guarded narrative generation → structured response. Separate ingestion jobs populate market and document data for search and briefings. The README documents several capabilities whose route implementations were not sampled; their nodes are retained, but uncertain internal calls are omitted.

Main entry points: [`app/api/main.py`](https://github.com/team-finch/finch-ai/blob/master/app/api/main.py) (FastAPI application), [`app/api/routes/portfolio.py`](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/portfolio.py) (Portfolio route), [`app/llm/generate.py`](https://github.com/team-finch/finch-ai/blob/master/app/llm/generate.py) (Narrative generation), [`ingest`](https://github.com/team-finch/finch-ai/tree/master/ingest) (Data ingestion jobs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API features"]
  node_api["FastAPI application<br/>[main.py]"]
  node_briefing_route["Briefing route<br/>[briefing.py]"]
  node_chat_route["Chat route<br/>[chat.py]"]
  node_portfolio_route["Portfolio route<br/>[portfolio.py]"]
  node_orders_route["Order checks<br/>[orders.py]"]
  node_stocks_route["Stock analysis<br/>[stocks.py]"]
  node_wiki_route["Thesis wiki<br/>[wiki.py]"]
  node_feedback_route["User feedback<br/>[feedback.py]"]
  node_chat_jobs["Chat job queue<br/>[chat_jobs.py]"]
end

subgraph group_domain["Financial analysis"]
  node_ledger["Ledger adapter<br/>[adapters.py]"]
  node_portfolio_engine["Portfolio engine<br/>[portfolio.py]"]
  node_attribution_engine["Return attribution<br/>[attribution.py]"]
  node_risk_engine["Risk assessment<br/>[risk.py]"]
  node_briefing_engine["Briefing ranking<br/>[briefing.py]"]
end

subgraph group_llm["Grounded generation"]
  node_agent["Tool-using agent<br/>[agent.py]"]
  node_tools["Financial tools<br/>[tools.py]"]
  node_generation["Narrative generation<br/>[generate.py]"]
  node_guards["Input/output guards<br/>[output.py]"]
  node_llm_client["LLM provider client<br/>[client.py]"]
end

subgraph group_knowledge["Knowledge pipeline"]
  node_rag_search["Hybrid document search<br/>[search.py]"]
  node_wiki_store["Thesis storage<br/>[store.py]"]
  node_ingestion["Data ingestion jobs"]
  node_chunking["Document chunking<br/>[chunking.py]"]
  node_embedding["Text embeddings<br/>[embedding.py]"]
end

subgraph group_data["Persistence"]
  node_database[("PostgreSQL + pgvector")]
end

node_backend(("Backend client"))
node_market_sources(("News, filings, markets"))

node_backend -->|"requests"| node_api
node_api -->|"routes to"| node_briefing_route
node_api -->|"routes to"| node_chat_route
node_api -->|"routes to"| node_portfolio_route
node_api -->|"routes to"| node_orders_route
node_api -->|"routes to"| node_stocks_route
node_api -->|"routes to"| node_wiki_route
node_api -->|"routes to"| node_feedback_route
node_portfolio_route -->|"loads ledger"| node_ledger
node_portfolio_route -->|"computes portfolio"| node_portfolio_engine
node_portfolio_route -->|"assesses risk"| node_risk_engine
node_portfolio_route -->|"calculates attribution"| node_attribution_engine
node_briefing_route -->|"ranks briefing data"| node_briefing_engine
node_briefing_route -->|"generates narrative"| node_generation
node_portfolio_route -->|"generates narrative"| node_generation
node_chat_route -->|"enqueues work"| node_chat_jobs
node_chat_route -->|"runs agent"| node_agent
node_agent -->|"dispatches tools"| node_tools
node_tools -->|"searches documents"| node_rag_search
node_tools -->|"uses calculations"| node_portfolio_engine
node_tools -->|"reads wiki"| node_wiki_store
node_generation -->|"calls model"| node_llm_client
node_generation -->|"validates output"| node_guards
node_guards -->|"requests regeneration"| node_generation
node_generation -->|"returns segments"| node_backend
node_ingestion -->|"collects data"| node_market_sources
node_ingestion -->|"chunks documents"| node_chunking
node_ingestion -->|"embeds chunks"| node_embedding
node_ingestion -->|"stores records"| node_database
node_rag_search -->|"retrieves documents"| node_database
node_wiki_route -.->|"uses thesis data"| node_wiki_store

click node_api "https://github.com/team-finch/finch-ai/blob/master/app/api/main.py"
click node_briefing_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/briefing.py"
click node_chat_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/chat.py"
click node_portfolio_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/portfolio.py"
click node_orders_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/orders.py"
click node_stocks_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/stocks.py"
click node_wiki_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/wiki.py"
click node_feedback_route "https://github.com/team-finch/finch-ai/blob/master/app/api/routes/feedback.py"
click node_ledger "https://github.com/team-finch/finch-ai/blob/master/app/core/adapters.py"
click node_portfolio_engine "https://github.com/team-finch/finch-ai/blob/master/app/engines/portfolio.py"
click node_attribution_engine "https://github.com/team-finch/finch-ai/blob/master/app/engines/attribution.py"
click node_risk_engine "https://github.com/team-finch/finch-ai/blob/master/app/engines/risk.py"
click node_briefing_engine "https://github.com/team-finch/finch-ai/blob/master/app/engines/briefing.py"
click node_chat_jobs "https://github.com/team-finch/finch-ai/blob/master/app/chat_jobs.py"
click node_agent "https://github.com/team-finch/finch-ai/blob/master/app/llm/agent.py"
click node_tools "https://github.com/team-finch/finch-ai/blob/master/app/llm/tools.py"
click node_generation "https://github.com/team-finch/finch-ai/blob/master/app/llm/generate.py"
click node_guards "https://github.com/team-finch/finch-ai/blob/master/app/llm/guard/output.py"
click node_llm_client "https://github.com/team-finch/finch-ai/blob/master/app/llm/client.py"
click node_rag_search "https://github.com/team-finch/finch-ai/blob/master/app/rag/search.py"
click node_wiki_store "https://github.com/team-finch/finch-ai/blob/master/app/wiki/store.py"
click node_ingestion "https://github.com/team-finch/finch-ai/tree/master/ingest"
click node_chunking "https://github.com/team-finch/finch-ai/blob/master/app/rag/chunking.py"
click node_embedding "https://github.com/team-finch/finch-ai/blob/master/app/rag/embedding.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_api,node_briefing_route,node_chat_route,node_portfolio_route,node_orders_route,node_stocks_route,node_wiki_route,node_feedback_route,node_chat_jobs,node_backend toneBlue
class node_ledger,node_portfolio_engine,node_attribution_engine,node_risk_engine,node_briefing_engine toneAmber
class node_agent,node_tools,node_generation,node_guards,node_llm_client toneMint
class node_rag_search,node_wiki_store,node_ingestion,node_chunking,node_embedding toneRose
class node_database,node_market_sources toneIndigo
```

## Components

### API features

- [FastAPI application](https://github.com/team-finch/finch-ai/blob/master/app/api/main.py): `app/api/main.py`
- [Briefing route](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/briefing.py): `app/api/routes/briefing.py`
- [Chat route](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/chat.py): `app/api/routes/chat.py`
- [Portfolio route](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/portfolio.py): `app/api/routes/portfolio.py`
- [Order checks](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/orders.py): `app/api/routes/orders.py`
- [Stock analysis](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/stocks.py): `app/api/routes/stocks.py`
- [Thesis wiki](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/wiki.py): `app/api/routes/wiki.py`
- [User feedback](https://github.com/team-finch/finch-ai/blob/master/app/api/routes/feedback.py): `app/api/routes/feedback.py`
- [Chat job queue](https://github.com/team-finch/finch-ai/blob/master/app/chat_jobs.py): `app/chat_jobs.py`

### Financial analysis

- [Ledger adapter](https://github.com/team-finch/finch-ai/blob/master/app/core/adapters.py): `app/core/adapters.py`
- [Portfolio engine](https://github.com/team-finch/finch-ai/blob/master/app/engines/portfolio.py): `app/engines/portfolio.py`
- [Return attribution](https://github.com/team-finch/finch-ai/blob/master/app/engines/attribution.py): `app/engines/attribution.py`
- [Risk assessment](https://github.com/team-finch/finch-ai/blob/master/app/engines/risk.py): `app/engines/risk.py`
- [Briefing ranking](https://github.com/team-finch/finch-ai/blob/master/app/engines/briefing.py): `app/engines/briefing.py`

### Grounded generation

- [Tool-using agent](https://github.com/team-finch/finch-ai/blob/master/app/llm/agent.py): `app/llm/agent.py`
- [Financial tools](https://github.com/team-finch/finch-ai/blob/master/app/llm/tools.py): `app/llm/tools.py`
- [Narrative generation](https://github.com/team-finch/finch-ai/blob/master/app/llm/generate.py): `app/llm/generate.py`
- [Input/output guards](https://github.com/team-finch/finch-ai/blob/master/app/llm/guard/output.py): `app/llm/guard/output.py`
- [LLM provider client](https://github.com/team-finch/finch-ai/blob/master/app/llm/client.py): `app/llm/client.py`

### Knowledge pipeline

- [Hybrid document search](https://github.com/team-finch/finch-ai/blob/master/app/rag/search.py): `app/rag/search.py`
- [Thesis storage](https://github.com/team-finch/finch-ai/blob/master/app/wiki/store.py): `app/wiki/store.py`
- [Data ingestion jobs](https://github.com/team-finch/finch-ai/tree/master/ingest): `ingest`
- [Document chunking](https://github.com/team-finch/finch-ai/blob/master/app/rag/chunking.py): `app/rag/chunking.py`
- [Text embeddings](https://github.com/team-finch/finch-ai/blob/master/app/rag/embedding.py): `app/rag/embedding.py`

### Persistence

- **PostgreSQL + pgvector**

### Other components

- **Backend client**
- **News, filings, markets**

## Connections

- Backend client → FastAPI application: requests
- FastAPI application → Briefing route: routes to (evidence: `app/api/main.py`)
- FastAPI application → Chat route: routes to (evidence: `app/api/main.py`)
- FastAPI application → Portfolio route: routes to (evidence: `app/api/main.py`)
- FastAPI application → Order checks: routes to (evidence: `app/api/main.py`)
- FastAPI application → Stock analysis: routes to (evidence: `app/api/main.py`)
- FastAPI application → Thesis wiki: routes to (evidence: `app/api/main.py`)
- FastAPI application → User feedback: routes to (evidence: `app/api/main.py`)
- Portfolio route → Ledger adapter: loads ledger (evidence: `app/api/routes/portfolio.py`)
- Portfolio route → Portfolio engine: computes portfolio (evidence: `app/api/routes/portfolio.py`)
- Portfolio route → Risk assessment: assesses risk (evidence: `app/api/routes/portfolio.py`)
- Portfolio route → Return attribution: calculates attribution (evidence: `app/api/routes/portfolio.py`)
- Briefing route → Briefing ranking: ranks briefing data (evidence: `app/api/routes/briefing.py`)
- Briefing route → Narrative generation: generates narrative (evidence: `app/api/routes/briefing.py`)
- Portfolio route → Narrative generation: generates narrative (evidence: `app/api/routes/portfolio.py`)
- Chat route → Chat job queue: enqueues work (evidence: `app/api/routes/chat.py`)
- Chat route → Tool-using agent: runs agent (evidence: `app/api/routes/chat.py`)
- Tool-using agent → Financial tools: dispatches tools (evidence: `app/llm/tools.py`)
- Financial tools → Hybrid document search: searches documents (evidence: `app/llm/tools.py`)
- Financial tools → Portfolio engine: uses calculations (evidence: `app/llm/tools.py`)
- Financial tools → Thesis storage: reads wiki (evidence: `app/llm/tools.py`)
- Narrative generation → LLM provider client: calls model (evidence: `app/llm/generate.py`)
- Narrative generation → Input/output guards: validates output (evidence: `app/llm/generate.py`)
- Input/output guards → Narrative generation: requests regeneration
- Narrative generation → Backend client: returns segments
- Data ingestion jobs → News, filings, markets: collects data
- Data ingestion jobs → Document chunking: chunks documents (evidence: `ingest/news.py`)
- Data ingestion jobs → Text embeddings: embeds chunks
- Data ingestion jobs → PostgreSQL + pgvector: stores records
- Hybrid document search → PostgreSQL + pgvector: retrieves documents (evidence: `app/rag/search.py`)
- Thesis wiki → Thesis storage: uses thesis data
