# superiorpython/marketlens architecture

> Architecture diagram of the GitHub repository superiorpython/marketlens, 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/superiorpython/marketlens
- Repository: https://github.com/superiorpython/marketlens

## Overview

MarketLens turns SEC-reported financials into company reports, screens, and industry comparisons. The user workflow runs from a React page through the FastAPI API to SEC data or PostgreSQL, then returns report or peer-analysis results to the browser. A separate ingestion path loads SEC facts into the database. The README documents SQL-backed point-in-time screening, industry ranks, and a refreshed latest-metrics snapshot; implementation details for those SQL functions were not sampled, so their relationships are documented rather than inferred from source.

Main entry points: [`src/marketlens/main.py`](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/main.py) (FastAPI routes), [`frontend/src/App.tsx`](https://github.com/superiorpython/marketlens/blob/master/frontend/src/App.tsx) (Page routing), [`frontend/src/api.ts`](https://github.com/superiorpython/marketlens/blob/master/frontend/src/api.ts) (API client), [`src/marketlens/load.py`](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/load.py) (Ticker loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_app["Page routing<br/>[App.tsx]"]
  node_company_views["Company reports<br/>[ReportPage.tsx]"]
  node_screen_view["Company screener<br/>[ScreenerPage.tsx]"]
  node_industry_views["Industry comparisons<br/>[IndustriesPage.tsx]"]
  node_industry_detail["Peer charts and ranks<br/>[IndustryPage.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API and analysis"]
  node_api["FastAPI routes<br/>[main.py]"]
  node_report_analysis["Report analysis<br/>[report.py]"]
  node_metrics["Financial metrics<br/>[metrics.py]"]
  node_screener["Screen queries<br/>[screener.py]"]
  node_industries["Industry queries<br/>[industries.py]"]
  node_stats["Loaded-data stats<br/>[stats.py]"]
end

subgraph group_ingest["SEC data ingestion"]
  node_edgar_client["SEC EDGAR client<br/>[edgar.py]"]
  node_annual_facts["Annual fact extraction<br/>[fundamentals.py]"]
  node_ttm["TTM extraction<br/>[ttm.py]"]
  node_loader["Ticker loader<br/>[load.py]"]
  node_bulk_loader["Bulk archive loader<br/>[bulk.py]"]
end

subgraph group_storage["Financial data store"]
  node_postgres[("PostgreSQL")]
  node_migration["Database schema setup<br/>[migrate.py]"]
end

node_user(("Researcher"))
node_sec{{"SEC EDGAR"}}

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_company_views
node_app -->|"routes to"| node_screen_view
node_app -->|"routes to"| node_industry_views
node_app -->|"routes to"| node_industry_detail
node_company_views -->|"requests data"| node_api_client
node_screen_view -->|"requests data"| node_api_client
node_industry_views -->|"requests data"| node_api_client
node_industry_detail -->|"requests data"| node_api_client
node_api_client -->|"calls endpoints"| node_api
node_api -->|"builds report"| node_report_analysis
node_report_analysis -->|"uses metrics"| node_metrics
node_api -->|"serves screens"| node_screener
node_api -->|"serves comparisons"| node_industries
node_api -->|"serves stats"| node_stats
node_api -->|"loads SEC facts"| node_edgar_client
node_api -->|"extracts facts"| node_annual_facts
node_api -->|"extracts TTM"| node_ttm
node_edgar_client -->|"fetches filings"| node_sec
node_loader -->|"fetches company data"| node_edgar_client
node_loader -->|"extracts fundamentals"| node_annual_facts
node_bulk_loader -->|"loads companies"| node_loader
node_loader -.->|"writes facts"| node_postgres
node_bulk_loader -->|"reads archives"| node_sec
node_screener -->|"queries screens"| node_postgres
node_industries -->|"queries peer data"| node_postgres
node_stats -.->|"queries loaded data"| node_postgres
node_migration -->|"creates schema"| node_postgres
node_postgres -->|"returns results"| node_screener
node_postgres -->|"returns ranks"| node_industries

click node_app "https://github.com/superiorpython/marketlens/blob/master/frontend/src/App.tsx"
click node_company_views "https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/ReportPage.tsx"
click node_screen_view "https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/ScreenerPage.tsx"
click node_industry_views "https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/IndustriesPage.tsx"
click node_industry_detail "https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/IndustryPage.tsx"
click node_api_client "https://github.com/superiorpython/marketlens/blob/master/frontend/src/api.ts"
click node_api "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/main.py"
click node_report_analysis "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/analysis/report.py"
click node_metrics "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/analysis/metrics.py"
click node_screener "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/screener.py"
click node_industries "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/industries.py"
click node_stats "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/stats.py"
click node_edgar_client "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/edgar.py"
click node_annual_facts "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/fundamentals.py"
click node_ttm "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/ttm.py"
click node_loader "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/load.py"
click node_bulk_loader "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/bulk.py"
click node_migration "https://github.com/superiorpython/marketlens/blob/master/src/marketlens/db/migrate.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_app,node_company_views,node_screen_view,node_industry_views,node_industry_detail,node_api_client toneBlue
class node_api,node_report_analysis,node_metrics,node_screener,node_industries,node_stats toneAmber
class node_edgar_client,node_annual_facts,node_ttm,node_loader,node_bulk_loader toneMint
class node_postgres,node_migration toneRose
class node_user,node_sec toneIndigo
```

## Components

### Web experience

- [Page routing](https://github.com/superiorpython/marketlens/blob/master/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Company reports](https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/ReportPage.tsx): `frontend/src/pages/ReportPage.tsx`
- [Company screener](https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/ScreenerPage.tsx): `frontend/src/pages/ScreenerPage.tsx`
- [Industry comparisons](https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/IndustriesPage.tsx): `frontend/src/pages/IndustriesPage.tsx`
- [Peer charts and ranks](https://github.com/superiorpython/marketlens/blob/master/frontend/src/pages/IndustryPage.tsx): `frontend/src/pages/IndustryPage.tsx`
- [API client](https://github.com/superiorpython/marketlens/blob/master/frontend/src/api.ts): `frontend/src/api.ts`

### API and analysis

- [FastAPI routes](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/main.py): `src/marketlens/main.py`
- [Report analysis](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/analysis/report.py): `src/marketlens/analysis/report.py`
- [Financial metrics](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/analysis/metrics.py): `src/marketlens/analysis/metrics.py`
- [Screen queries](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/screener.py): `src/marketlens/screener.py`
- [Industry queries](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/industries.py): `src/marketlens/industries.py`
- [Loaded-data stats](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/stats.py): `src/marketlens/stats.py`

### SEC data ingestion

- [SEC EDGAR client](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/edgar.py): `src/marketlens/data/edgar.py`
- [Annual fact extraction](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/fundamentals.py): `src/marketlens/data/fundamentals.py`
- [TTM extraction](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/data/ttm.py): `src/marketlens/data/ttm.py`
- [Ticker loader](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/load.py): `src/marketlens/load.py`
- [Bulk archive loader](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/bulk.py): `src/marketlens/bulk.py`

### Financial data store

- **PostgreSQL**
- [Database schema setup](https://github.com/superiorpython/marketlens/blob/master/src/marketlens/db/migrate.py): `src/marketlens/db/migrate.py`

### Other components

- **Researcher**
- **SEC EDGAR**

## Connections

- Researcher → Page routing: uses
- Page routing → Company reports: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Company screener: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Industry comparisons: routes to (evidence: `frontend/src/App.tsx`)
- Page routing → Peer charts and ranks: routes to (evidence: `frontend/src/App.tsx`)
- Company reports → API client: requests data (evidence: `frontend/src/pages/ReportPage.tsx`)
- Company screener → API client: requests data (evidence: `frontend/src/pages/ScreenerPage.tsx`)
- Industry comparisons → API client: requests data (evidence: `frontend/src/pages/IndustriesPage.tsx`)
- Peer charts and ranks → API client: requests data (evidence: `frontend/src/pages/IndustryPage.tsx`)
- API client → FastAPI routes: calls endpoints
- FastAPI routes → Report analysis: builds report (evidence: `src/marketlens/main.py`)
- Report analysis → Financial metrics: uses metrics (evidence: `src/marketlens/analysis/report.py`)
- FastAPI routes → Screen queries: serves screens (evidence: `src/marketlens/main.py`)
- FastAPI routes → Industry queries: serves comparisons (evidence: `src/marketlens/main.py`)
- FastAPI routes → Loaded-data stats: serves stats (evidence: `src/marketlens/main.py`)
- FastAPI routes → SEC EDGAR client: loads SEC facts (evidence: `src/marketlens/main.py`)
- FastAPI routes → Annual fact extraction: extracts facts (evidence: `src/marketlens/main.py`)
- FastAPI routes → TTM extraction: extracts TTM (evidence: `src/marketlens/main.py`)
- SEC EDGAR client → SEC EDGAR: fetches filings (evidence: `src/marketlens/data/edgar.py`)
- Ticker loader → SEC EDGAR client: fetches company data (evidence: `src/marketlens/load.py`)
- Ticker loader → Annual fact extraction: extracts fundamentals (evidence: `src/marketlens/load.py`)
- Bulk archive loader → Ticker loader: loads companies (evidence: `src/marketlens/bulk.py`)
- Ticker loader → PostgreSQL: writes facts
- Bulk archive loader → SEC EDGAR: reads archives
- Screen queries → PostgreSQL: queries screens
- Industry queries → PostgreSQL: queries peer data
- Loaded-data stats → PostgreSQL: queries loaded data
- Database schema setup → PostgreSQL: creates schema
- PostgreSQL → Screen queries: returns results
- PostgreSQL → Industry queries: returns ranks
