# lkiwan/chatbot-ammc architecture

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

- Interactive diagram: https://gitdiagram.com/lkiwan/chatbot-ammc
- Repository: https://github.com/lkiwan/chatbot-ammc

## Overview

AMMC Financial Intelligence Platform collects regulator reports, extracts searchable text and structured financials, and serves bilingual questions and company data through a web/API product. The main workflow is AMMC report discovery and download, PDF extraction/indexing, query routing to SQL and vector retrieval, then LLM-backed answers with report sources. The graph also preserves the financial-data explorer, PDF proxy, and admin analytics/authentication capabilities. Unsampled subsystem links rely on README statements or SOURCE INDEX references; no deeper behavior is inferred where neither provides evidence.

Main entry points: [`api/main.py`](https://github.com/lkiwan/chatbot-ammc/blob/main/api/main.py) (Platform API), [`ammc_report_scraper/main.py`](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/main.py) (Scraper workflow), [`frontend/src/App.jsx`](https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/App.jsx) (Web application), [`retrieval/hybrid_retriever.py`](https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/hybrid_retriever.py) (Hybrid retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_acquisition["Report acquisition"]
  node_scraper_entry["Scraper workflow<br/>[main.py]"]
  node_emitters["Emitter discovery<br/>[ammc_emitters.py]"]
  node_company_reports["Company reports<br/>[ammc_company.py]"]
  node_report_listing["Report listing<br/>[ammc_reports.py]"]
  node_scraper_http["HTTP session<br/>[base.py]"]
  node_report_parser["Report records<br/>[report_parser.py]"]
  node_pdf_download["PDF download<br/>[pdf_downloader.py]"]
  node_scraper_config["Scraper settings<br/>[config.py]"]
  node_scraper_names["Name normalization<br/>[normalization.py]"]
end

subgraph group_data["Financial data"]
  node_ingest_bridge["Scraped ingest<br/>[ingest_scraped.py]"]
  node_text_extract["PDF text chunks<br/>[extract.py]"]
  node_index_build["Vector indexing<br/>[build_index.py]"]
  node_financial_extract["Financial extraction"]
  node_financial_normalize["Financial normalization<br/>[normalizer.py]"]
  node_financial_vocabulary["Metric vocabulary<br/>[vocabulary.py]"]
  node_chroma[("ChromaDB")]
end

subgraph group_answering["Query and answers"]
  node_hybrid["Hybrid retrieval"]
  node_query_router["Query routing<br/>[router.py]"]
  node_sql_retrieval["SQL retrieval<br/>[sql_retriever.py]"]
  node_vector_retrieval["Vector retrieval"]
  node_chat["Answer orchestration<br/>[chat.py]"]
end

subgraph group_platform["API and persistence"]
  node_postgres[("PostgreSQL")]
  node_api["Platform API<br/>[main.py]"]
  node_analytics["Admin analytics<br/>[analytics.py]"]
  node_auth["Demo and admin auth<br/>[auth.py]"]
  node_db_models["Financial data model<br/>[models.py]"]
  node_db_session["Database sessions<br/>[session.py]"]
end

subgraph group_client["Web experience"]
  node_web_app["Web application<br/>[App.jsx]"]
  node_frontend_api["API client<br/>[api.js]"]
  node_chat_panel["Chat panel<br/>[ChatPanel.jsx]"]
  node_pdf_viewer["PDF viewer<br/>[PdfViewer.jsx]"]
end

node_researcher(("Platform user"))
node_ammc(("AMMC site"))
node_llm(("Groq LLM"))

node_researcher -->|"uses"| node_web_app
node_ammc -->|"provides listings"| node_emitters
node_scraper_entry -->|"scrapes"| node_emitters
node_scraper_entry -->|"queries companies"| node_company_reports
node_scraper_entry -->|"fetches reports"| node_report_listing
node_scraper_entry -->|"downloads PDFs"| node_pdf_download
node_scraper_entry -->|"uses records"| node_report_parser
node_emitters -->|"fetches pages"| node_scraper_http
node_company_reports -->|"fetches pages"| node_scraper_http
node_report_listing -->|"fetches pages"| node_scraper_http
node_company_reports -->|"parses reports"| node_report_parser
node_report_listing -->|"parses reports"| node_report_parser
node_pdf_download -->|"downloads through"| node_scraper_http
node_pdf_download -->|"uses settings"| node_scraper_config
node_company_reports -->|"normalizes names"| node_scraper_names
node_ingest_bridge -->|"triggers indexing"| node_index_build
node_ammc -->|"supplies reports"| node_scraper_entry
node_scraper_entry -->|"writes scraped PDFs"| node_ingest_bridge
node_text_extract -->|"provides chunks"| node_index_build
node_index_build -->|"builds index"| node_chroma
node_financial_extract -->|"normalizes values"| node_financial_normalize
node_financial_extract -->|"uses metrics"| node_financial_vocabulary
node_financial_extract -->|"stores financials"| node_postgres
node_api -->|"requests answers"| node_chat
node_api -->|"searches reports"| node_hybrid
node_api -->|"serves analytics"| node_analytics
node_api -->|"delegates login"| node_auth
node_api -->|"serves financial queries"| node_sql_retrieval
node_hybrid -->|"routes queries"| node_query_router
node_hybrid -->|"queries structured data"| node_sql_retrieval
node_hybrid -->|"queries narrative data"| node_vector_retrieval
node_sql_retrieval -->|"reads through"| node_db_session
node_db_session -->|"opens sessions"| node_postgres
node_db_models -->|"defines schema"| node_postgres
node_vector_retrieval -->|"searches index"| node_chroma
node_chat -->|"generates answers"| node_llm
node_chat -->|"retrieves context"| node_hybrid
node_web_app -->|"calls API"| node_frontend_api
node_web_app -->|"renders chat"| node_chat_panel
node_web_app -->|"renders PDFs"| node_pdf_viewer
node_chat_panel -->|"sends questions"| node_frontend_api
node_frontend_api -->|"calls endpoints"| node_api
node_pdf_viewer -->|"requests PDF proxy"| node_api
node_web_app -->|"loads platform data"| node_api
node_api -->|"reads financial data"| node_postgres
node_api -->|"uses data model"| node_db_models

click node_scraper_entry "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/main.py"
click node_emitters "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_emitters.py"
click node_company_reports "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_company.py"
click node_report_listing "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_reports.py"
click node_scraper_http "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/base.py"
click node_report_parser "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/parsers/report_parser.py"
click node_pdf_download "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/downloaders/pdf_downloader.py"
click node_scraper_config "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/config.py"
click node_scraper_names "https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/utils/normalization.py"
click node_ingest_bridge "https://github.com/lkiwan/chatbot-ammc/blob/main/ingest_scraped.py"
click node_text_extract "https://github.com/lkiwan/chatbot-ammc/blob/main/extract.py"
click node_index_build "https://github.com/lkiwan/chatbot-ammc/blob/main/build_index.py"
click node_financial_extract "https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/financial_extractor.py"
click node_financial_normalize "https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/normalizer.py"
click node_financial_vocabulary "https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/vocabulary.py"
click node_api "https://github.com/lkiwan/chatbot-ammc/blob/main/api/main.py"
click node_analytics "https://github.com/lkiwan/chatbot-ammc/blob/main/api/analytics.py"
click node_auth "https://github.com/lkiwan/chatbot-ammc/blob/main/api/auth.py"
click node_db_models "https://github.com/lkiwan/chatbot-ammc/blob/main/db/models.py"
click node_db_session "https://github.com/lkiwan/chatbot-ammc/blob/main/db/session.py"
click node_hybrid "https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/hybrid_retriever.py"
click node_query_router "https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/router.py"
click node_sql_retrieval "https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/sql_retriever.py"
click node_vector_retrieval "https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/vector_retriever.py"
click node_chat "https://github.com/lkiwan/chatbot-ammc/blob/main/chat.py"
click node_web_app "https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/App.jsx"
click node_frontend_api "https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/api.js"
click node_chat_panel "https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/components/ChatPanel.jsx"
click node_pdf_viewer "https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/components/PdfViewer.jsx"

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_scraper_entry,node_emitters,node_company_reports,node_report_listing,node_scraper_http,node_report_parser,node_pdf_download,node_scraper_config,node_scraper_names,node_researcher toneBlue
class node_ingest_bridge,node_text_extract,node_index_build,node_financial_extract,node_financial_normalize,node_financial_vocabulary,node_chroma toneAmber
class node_hybrid,node_query_router,node_sql_retrieval,node_vector_retrieval,node_chat toneMint
class node_postgres,node_api,node_analytics,node_auth,node_db_models,node_db_session toneRose
class node_web_app,node_frontend_api,node_chat_panel,node_pdf_viewer,node_ammc,node_llm toneIndigo
```

## Components

### Report acquisition

- [Scraper workflow](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/main.py): `ammc_report_scraper/main.py`
- [Emitter discovery](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_emitters.py): `ammc_report_scraper/src/scrapers/ammc_emitters.py`
- [Company reports](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_company.py): `ammc_report_scraper/src/scrapers/ammc_company.py`
- [Report listing](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/ammc_reports.py): `ammc_report_scraper/src/scrapers/ammc_reports.py`
- [HTTP session](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/scrapers/base.py): `ammc_report_scraper/src/scrapers/base.py`
- [Report records](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/parsers/report_parser.py): `ammc_report_scraper/src/parsers/report_parser.py`
- [PDF download](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/downloaders/pdf_downloader.py): `ammc_report_scraper/src/downloaders/pdf_downloader.py`
- [Scraper settings](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/config.py): `ammc_report_scraper/src/config.py`
- [Name normalization](https://github.com/lkiwan/chatbot-ammc/blob/main/ammc_report_scraper/src/utils/normalization.py): `ammc_report_scraper/src/utils/normalization.py`

### Financial data

- [Scraped ingest](https://github.com/lkiwan/chatbot-ammc/blob/main/ingest_scraped.py): `ingest_scraped.py`
- [PDF text chunks](https://github.com/lkiwan/chatbot-ammc/blob/main/extract.py): `extract.py`
- [Vector indexing](https://github.com/lkiwan/chatbot-ammc/blob/main/build_index.py): `build_index.py`
- [Financial extraction](https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/financial_extractor.py): `extraction/financial_extractor.py`
- [Financial normalization](https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/normalizer.py): `extraction/normalizer.py`
- [Metric vocabulary](https://github.com/lkiwan/chatbot-ammc/blob/main/extraction/vocabulary.py): `extraction/vocabulary.py`
- **ChromaDB**

### Query and answers

- [Hybrid retrieval](https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/hybrid_retriever.py): `retrieval/hybrid_retriever.py`
- [Query routing](https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/router.py): `retrieval/router.py`
- [SQL retrieval](https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/sql_retriever.py): `retrieval/sql_retriever.py`
- [Vector retrieval](https://github.com/lkiwan/chatbot-ammc/blob/main/retrieval/vector_retriever.py): `retrieval/vector_retriever.py`
- [Answer orchestration](https://github.com/lkiwan/chatbot-ammc/blob/main/chat.py): `chat.py`

### API and persistence

- **PostgreSQL**
- [Platform API](https://github.com/lkiwan/chatbot-ammc/blob/main/api/main.py): `api/main.py`
- [Admin analytics](https://github.com/lkiwan/chatbot-ammc/blob/main/api/analytics.py): `api/analytics.py`
- [Demo and admin auth](https://github.com/lkiwan/chatbot-ammc/blob/main/api/auth.py): `api/auth.py`
- [Financial data model](https://github.com/lkiwan/chatbot-ammc/blob/main/db/models.py): `db/models.py`
- [Database sessions](https://github.com/lkiwan/chatbot-ammc/blob/main/db/session.py): `db/session.py`

### Web experience

- [Web application](https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [API client](https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/api.js): `frontend/src/api.js`
- [Chat panel](https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/components/ChatPanel.jsx): `frontend/src/components/ChatPanel.jsx`
- [PDF viewer](https://github.com/lkiwan/chatbot-ammc/blob/main/frontend/src/components/PdfViewer.jsx): `frontend/src/components/PdfViewer.jsx`

### Other components

- **Platform user**
- **AMMC site**
- **Groq LLM**

## Connections

- Platform user → Web application: uses (evidence: `README.md`)
- AMMC site → Emitter discovery: provides listings (evidence: `README.md`)
- Scraper workflow → Emitter discovery: scrapes (evidence: `ammc_report_scraper/main.py`)
- Scraper workflow → Company reports: queries companies (evidence: `ammc_report_scraper/main.py`)
- Scraper workflow → Report listing: fetches reports (evidence: `ammc_report_scraper/main.py`)
- Scraper workflow → PDF download: downloads PDFs (evidence: `ammc_report_scraper/main.py`)
- Scraper workflow → Report records: uses records (evidence: `ammc_report_scraper/main.py`)
- Emitter discovery → HTTP session: fetches pages (evidence: `ammc_report_scraper/src/scrapers/ammc_emitters.py`)
- Company reports → HTTP session: fetches pages (evidence: `ammc_report_scraper/src/scrapers/ammc_company.py`)
- Report listing → HTTP session: fetches pages (evidence: `ammc_report_scraper/src/scrapers/ammc_reports.py`)
- Company reports → Report records: parses reports (evidence: `ammc_report_scraper/src/scrapers/ammc_company.py`)
- Report listing → Report records: parses reports (evidence: `ammc_report_scraper/src/scrapers/ammc_reports.py`)
- PDF download → HTTP session: downloads through (evidence: `ammc_report_scraper/src/downloaders/pdf_downloader.py`)
- PDF download → Scraper settings: uses settings (evidence: `ammc_report_scraper/src/downloaders/pdf_downloader.py`)
- Company reports → Name normalization: normalizes names (evidence: `ammc_report_scraper/src/scrapers/ammc_company.py`)
- Scraped ingest → Vector indexing: triggers indexing (evidence: `README.md`)
- AMMC site → Scraper workflow: supplies reports (evidence: `README.md`)
- Scraper workflow → Scraped ingest: writes scraped PDFs (evidence: `README.md`)
- PDF text chunks → Vector indexing: provides chunks (evidence: `README.md`)
- Vector indexing → ChromaDB: builds index (evidence: `README.md`)
- Financial extraction → Financial normalization: normalizes values (evidence: `extraction/financial_extractor.py`)
- Financial extraction → Metric vocabulary: uses metrics (evidence: `extraction/financial_extractor.py`)
- Financial extraction → PostgreSQL: stores financials (evidence: `README.md`)
- Platform API → Answer orchestration: requests answers (evidence: `api/main.py`)
- Platform API → Hybrid retrieval: searches reports (evidence: `api/main.py`)
- Platform API → Admin analytics: serves analytics (evidence: `api/main.py`)
- Platform API → Demo and admin auth: delegates login (evidence: `api/main.py`)
- Platform API → SQL retrieval: serves financial queries (evidence: `api/main.py`)
- Hybrid retrieval → Query routing: routes queries (evidence: `retrieval/hybrid_retriever.py`)
- Hybrid retrieval → SQL retrieval: queries structured data (evidence: `retrieval/hybrid_retriever.py`)
- Hybrid retrieval → Vector retrieval: queries narrative data (evidence: `retrieval/hybrid_retriever.py`)
- SQL retrieval → Database sessions: reads through (evidence: `retrieval/sql_retriever.py`)
- Database sessions → PostgreSQL: opens sessions (evidence: `db/session.py`)
- Financial data model → PostgreSQL: defines schema (evidence: `README.md`)
- Vector retrieval → ChromaDB: searches index (evidence: `README.md`)
- Answer orchestration → Groq LLM: generates answers (evidence: `README.md`)
- Answer orchestration → Hybrid retrieval: retrieves context (evidence: `README.md`)
- Web application → API client: calls API (evidence: `frontend/src/App.jsx`)
- Web application → Chat panel: renders chat (evidence: `frontend/src/App.jsx`)
- Web application → PDF viewer: renders PDFs (evidence: `frontend/src/App.jsx`)
- Chat panel → API client: sends questions (evidence: `frontend/src/components/ChatPanel.jsx`)
- API client → Platform API: calls endpoints (evidence: `README.md`)
- PDF viewer → Platform API: requests PDF proxy (evidence: `README.md`)
- Web application → Platform API: loads platform data (evidence: `frontend/src/App.jsx`)
- Platform API → PostgreSQL: reads financial data (evidence: `README.md`)
- Platform API → Financial data model: uses data model (evidence: `api/main.py`)
