# dartrint/ai-financial-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/dartrint/ai-financial-assistant
- Repository: https://github.com/dartrint/ai-financial-assistant

## Overview

AI Financial Assistant serves Vietnamese financial questions through separate market-data, knowledge-RAG, and combined-analysis flows. The principal local workflow starts at the FastAPI or CLI entry point, reaches FinancialAgent for intent routing and entity extraction, then selects a tool; responses include analysis and citations. The web deployment instead uses a Cloudflare frontend and Supabase Edge Function, with optional signed-in history and model-provider fallbacks. The graph preserves ETL and evaluation capabilities documented in the README. Some web and tool internals were not excerpted, so those links rely on README statements rather than inspected implementation.

Main entry points: [`agent.py`](https://github.com/dartrint/ai-financial-assistant/blob/master/agent.py) (FinancialAgent), [`etl/run_etl.py`](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/run_etl.py) (ETL Runner), [`retrieval/hybrid_retriever.py`](https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/hybrid_retriever.py) (Hybrid Retrieval), [`llm/router.py`](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/router.py) (LLM Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local Application"]
  node_fastapi["FastAPI API<br/>[app.py]"]
  node_cli["CLI<br/>[main.py]"]
  node_agent["FinancialAgent<br/>[agent.py]"]
  node_config["Financial Config<br/>[config.py]"]
  node_toolbase["Tool Registry<br/>[base.py]"]
  node_llmrouter["LLM Router<br/>[router.py]"]
  node_llmbase["Provider Interface<br/>[base.py]"]
  node_groq["Groq Provider<br/>[groq_provider.py]"]
  node_gemini["Gemini Provider<br/>[gemini_provider.py]"]
  node_ollama["Ollama Provider<br/>[ollama_provider.py]"]
end

subgraph group_market["Market Analysis"]
  node_markettool["Market Tool<br/>[market_data.py]"]
  node_stocktool["Stock Analysis<br/>[stock_analysis.py]"]
  node_economictool["Economic Analysis"]
  node_portfoliotool["Portfolio Metrics"]
  node_aggregator["Source Aggregator<br/>[aggregator.py]"]
  node_vnstock["vnstock Adapter<br/>[vnstock_source.py]"]
  node_ecodata["EcoData Adapter<br/>[ecodata_source.py]"]
  node_yahoo["Yahoo Adapter<br/>[yahoo_source.py]"]
  node_duckdb[("DuckDB Store<br/>[duckdb_store.py]")]
end

subgraph group_knowledge["Knowledge RAG"]
  node_concepttool["Concept Explainer<br/>[explain_concept.py]"]
  node_knowledgebase["Knowledge Base<br/>[loader.py]"]
  node_qdrant[("Qdrant Store<br/>[qdrant_store.py]")]
  node_collections["Collection Setup<br/>[collections.py]"]
  node_hybrid["Hybrid Retrieval"]
  node_bm25["BM25 Retrieval<br/>[bm25_retriever.py]"]
  node_embedding["Dense Retrieval"]
  node_reranker["Reranker<br/>[reranker.py]"]
end

subgraph group_etl["Knowledge ETL"]
  node_etlrunner["ETL Runner<br/>[run_etl.py]"]
  node_sources["Source Discovery<br/>[sources.py]"]
  node_extract["Content Extraction<br/>[extract.py]"]
  node_transform["Content Cleanup<br/>[transform.py]"]
  node_chunker["Document Chunker<br/>[chunker.py]"]
  node_etlstate[("ETL State<br/>[state.py]")]
end

subgraph group_web["Web Deployment"]
end

node_user(("User"))

node_user -->|"asks via API"| node_fastapi
node_user -->|"asks via CLI"| node_cli
node_fastapi -->|"invokes"| node_agent
node_cli -->|"uses"| node_agent
node_agent -->|"selects tool"| node_toolbase
node_agent -->|"dispatches"| node_markettool
node_agent -->|"dispatches"| node_stocktool
node_agent -->|"dispatches"| node_economictool
node_agent -->|"dispatches"| node_portfoliotool
node_agent -->|"dispatches"| node_concepttool
node_agent -->|"uses"| node_aggregator
node_agent -->|"uses"| node_hybrid
node_agent -->|"uses"| node_llmrouter
node_aggregator -->|"fetches from"| node_vnstock
node_aggregator -->|"fetches from"| node_ecodata
node_aggregator -->|"fetches from"| node_yahoo
node_knowledgebase -->|"searches"| node_qdrant
node_knowledgebase -->|"ensures collections"| node_collections
node_hybrid -->|"loads documents"| node_knowledgebase
node_hybrid -->|"retrieves"| node_bm25
node_hybrid -->|"retrieves"| node_embedding
node_hybrid -->|"reranks"| node_reranker
node_llmrouter -->|"tries provider"| node_groq
node_llmrouter -->|"tries provider"| node_gemini
node_llmrouter -.->|"tries provider"| node_ollama
node_groq -->|"implements"| node_llmbase
node_gemini -->|"implements"| node_llmbase
node_ollama -->|"implements"| node_llmbase
node_etlrunner -->|"discovers sources"| node_sources
node_etlrunner -->|"extracts content"| node_extract
node_etlrunner -->|"cleans content"| node_transform
node_etlrunner -->|"chunks documents"| node_chunker
node_etlrunner -->|"tracks state"| node_etlstate
node_etlrunner -->|"loads Qdrant"| node_knowledgebase

click node_fastapi "https://github.com/dartrint/ai-financial-assistant/blob/master/app.py"
click node_cli "https://github.com/dartrint/ai-financial-assistant/blob/master/main.py"
click node_agent "https://github.com/dartrint/ai-financial-assistant/blob/master/agent.py"
click node_config "https://github.com/dartrint/ai-financial-assistant/blob/master/config.py"
click node_toolbase "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/base.py"
click node_markettool "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/market_data.py"
click node_stocktool "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/stock_analysis.py"
click node_economictool "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/economic_analysis.py"
click node_portfoliotool "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/portfolio_metrics.py"
click node_concepttool "https://github.com/dartrint/ai-financial-assistant/blob/master/tools/explain_concept.py"
click node_aggregator "https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/aggregator.py"
click node_vnstock "https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/vnstock_source.py"
click node_ecodata "https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/ecodata_source.py"
click node_yahoo "https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/yahoo_source.py"
click node_duckdb "https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/duckdb_store.py"
click node_knowledgebase "https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/loader.py"
click node_qdrant "https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/qdrant_store.py"
click node_collections "https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/collections.py"
click node_hybrid "https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/hybrid_retriever.py"
click node_bm25 "https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/bm25_retriever.py"
click node_embedding "https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/embedding_retriever.py"
click node_reranker "https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/reranker.py"
click node_llmrouter "https://github.com/dartrint/ai-financial-assistant/blob/master/llm/router.py"
click node_llmbase "https://github.com/dartrint/ai-financial-assistant/blob/master/llm/base.py"
click node_groq "https://github.com/dartrint/ai-financial-assistant/blob/master/llm/groq_provider.py"
click node_gemini "https://github.com/dartrint/ai-financial-assistant/blob/master/llm/gemini_provider.py"
click node_ollama "https://github.com/dartrint/ai-financial-assistant/blob/master/llm/ollama_provider.py"
click node_etlrunner "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/run_etl.py"
click node_sources "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/sources.py"
click node_extract "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/extract.py"
click node_transform "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/transform.py"
click node_chunker "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/chunker.py"
click node_etlstate "https://github.com/dartrint/ai-financial-assistant/blob/master/etl/state.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_fastapi,node_cli,node_agent,node_config,node_toolbase,node_llmrouter,node_llmbase,node_groq,node_gemini,node_ollama,node_user toneBlue
class node_markettool,node_stocktool,node_economictool,node_portfoliotool,node_aggregator,node_vnstock,node_ecodata,node_yahoo,node_duckdb toneAmber
class node_concepttool,node_knowledgebase,node_qdrant,node_collections,node_hybrid,node_bm25,node_embedding,node_reranker toneMint
class node_etlrunner,node_sources,node_extract,node_transform,node_chunker,node_etlstate toneRose
```

## Components

### Local Application

- [FastAPI API](https://github.com/dartrint/ai-financial-assistant/blob/master/app.py): `app.py`
- [CLI](https://github.com/dartrint/ai-financial-assistant/blob/master/main.py): `main.py`
- [FinancialAgent](https://github.com/dartrint/ai-financial-assistant/blob/master/agent.py): `agent.py`
- [Financial Config](https://github.com/dartrint/ai-financial-assistant/blob/master/config.py): `config.py`
- [Tool Registry](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/base.py): `tools/base.py`
- [LLM Router](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/router.py): `llm/router.py`
- [Provider Interface](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/base.py): `llm/base.py`
- [Groq Provider](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/groq_provider.py): `llm/groq_provider.py`
- [Gemini Provider](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/gemini_provider.py): `llm/gemini_provider.py`
- [Ollama Provider](https://github.com/dartrint/ai-financial-assistant/blob/master/llm/ollama_provider.py): `llm/ollama_provider.py`

### Market Analysis

- [Market Tool](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/market_data.py): `tools/market_data.py`
- [Stock Analysis](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/stock_analysis.py): `tools/stock_analysis.py`
- [Economic Analysis](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/economic_analysis.py): `tools/economic_analysis.py`
- [Portfolio Metrics](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/portfolio_metrics.py): `tools/portfolio_metrics.py`
- [Source Aggregator](https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/aggregator.py): `market_data/aggregator.py`
- [vnstock Adapter](https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/vnstock_source.py): `market_data/vnstock_source.py`
- [EcoData Adapter](https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/ecodata_source.py): `market_data/ecodata_source.py`
- [Yahoo Adapter](https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/yahoo_source.py): `market_data/yahoo_source.py`
- [DuckDB Store](https://github.com/dartrint/ai-financial-assistant/blob/master/market_data/duckdb_store.py): `market_data/duckdb_store.py`

### Knowledge RAG

- [Concept Explainer](https://github.com/dartrint/ai-financial-assistant/blob/master/tools/explain_concept.py): `tools/explain_concept.py`
- [Knowledge Base](https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/loader.py): `knowledge/loader.py`
- [Qdrant Store](https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/qdrant_store.py): `knowledge/qdrant_store.py`
- [Collection Setup](https://github.com/dartrint/ai-financial-assistant/blob/master/knowledge/collections.py): `knowledge/collections.py`
- [Hybrid Retrieval](https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/hybrid_retriever.py): `retrieval/hybrid_retriever.py`
- [BM25 Retrieval](https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/bm25_retriever.py): `retrieval/bm25_retriever.py`
- [Dense Retrieval](https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/embedding_retriever.py): `retrieval/embedding_retriever.py`
- [Reranker](https://github.com/dartrint/ai-financial-assistant/blob/master/retrieval/reranker.py): `retrieval/reranker.py`

### Knowledge ETL

- [ETL Runner](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/run_etl.py): `etl/run_etl.py`
- [Source Discovery](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/sources.py): `etl/sources.py`
- [Content Extraction](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/extract.py): `etl/extract.py`
- [Content Cleanup](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/transform.py): `etl/transform.py`
- [Document Chunker](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/chunker.py): `etl/chunker.py`
- [ETL State](https://github.com/dartrint/ai-financial-assistant/blob/master/etl/state.py): `etl/state.py`

### Other components

- **User**

## Connections

- User → FastAPI API: asks via API (evidence: `README.md`)
- User → CLI: asks via CLI (evidence: `README.md`)
- FastAPI API → FinancialAgent: invokes (evidence: `app.py`)
- CLI → FinancialAgent: uses (evidence: `main.py`)
- FinancialAgent → Tool Registry: selects tool (evidence: `agent.py`)
- FinancialAgent → Market Tool: dispatches (evidence: `agent.py`)
- FinancialAgent → Stock Analysis: dispatches (evidence: `agent.py`)
- FinancialAgent → Economic Analysis: dispatches (evidence: `agent.py`)
- FinancialAgent → Portfolio Metrics: dispatches (evidence: `agent.py`)
- FinancialAgent → Concept Explainer: dispatches (evidence: `agent.py`)
- FinancialAgent → Source Aggregator: uses (evidence: `agent.py`)
- FinancialAgent → Hybrid Retrieval: uses (evidence: `agent.py`)
- FinancialAgent → LLM Router: uses (evidence: `agent.py`)
- Source Aggregator → vnstock Adapter: fetches from (evidence: `market_data/aggregator.py`)
- Source Aggregator → EcoData Adapter: fetches from (evidence: `market_data/aggregator.py`)
- Source Aggregator → Yahoo Adapter: fetches from (evidence: `market_data/aggregator.py`)
- Knowledge Base → Qdrant Store: searches (evidence: `knowledge/loader.py`)
- Knowledge Base → Collection Setup: ensures collections (evidence: `knowledge/loader.py`)
- Hybrid Retrieval → Knowledge Base: loads documents (evidence: `retrieval/hybrid_retriever.py`)
- Hybrid Retrieval → BM25 Retrieval: retrieves (evidence: `retrieval/hybrid_retriever.py`)
- Hybrid Retrieval → Dense Retrieval: retrieves (evidence: `retrieval/hybrid_retriever.py`)
- Hybrid Retrieval → Reranker: reranks (evidence: `retrieval/hybrid_retriever.py`)
- LLM Router → Groq Provider: tries provider (evidence: `llm/router.py`)
- LLM Router → Gemini Provider: tries provider (evidence: `llm/router.py`)
- LLM Router → Ollama Provider: tries provider
- Groq Provider → Provider Interface: implements (evidence: `llm/groq_provider.py`)
- Gemini Provider → Provider Interface: implements (evidence: `llm/gemini_provider.py`)
- Ollama Provider → Provider Interface: implements (evidence: `llm/ollama_provider.py`)
- ETL Runner → Source Discovery: discovers sources (evidence: `etl/run_etl.py`)
- ETL Runner → Content Extraction: extracts content (evidence: `etl/run_etl.py`)
- ETL Runner → Content Cleanup: cleans content (evidence: `etl/run_etl.py`)
- ETL Runner → Document Chunker: chunks documents (evidence: `etl/run_etl.py`)
- ETL Runner → ETL State: tracks state (evidence: `etl/run_etl.py`)
- ETL Runner → Knowledge Base: loads Qdrant (evidence: `README.md`)
