# dashfin-fardb/financial-asset-relationship-db architecture

> Architecture diagram of the GitHub repository dashfin-fardb/financial-asset-relationship-db, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dashfin-fardb/financial-asset-relationship-db
- Repository: https://github.com/dashfin-fardb/financial-asset-relationship-db

## Overview

1. **Overall shape**
   This repo is a hybrid application with two user-facing paths: a legacy **Gradio app** started from `app.py`, and a newer **Next.js frontend + FastAPI backend** split across `frontend/` and `api/`. Both sit on top of the same financial-asset relationship domain.

2. **Primary request/response flow**
   In the modern path, the browser talks to the **Next.js UI** on the frontend side, which calls the **FastAPI API** in `api/main.py`. The API serves asset graph data, metrics, and visualization payloads through routers such as `api/routers/assets.py` and `api/routers/graph.py`.

3. **Core domain engine**
   The architectural center is `src/logic/asset_graph.py`. This is where assets are loaded into a graph, relationships are discovered or added, strengths are calculated, and network metrics are produced. The README indicates this engine also produces the 3D visualization data consumed by the UIs.

4. **Domain model boundary**
   `src/models/financial_models.py` defines the financial entities and enums that represent the business domain: equities, bonds, commodities, currencies, and regulatory events. This layer is the shared vocabulary used by the graph engine, data layer, and report generation.

5. **Data ingestion and persistence**
   The data boundary lives in `src/data/`. `sample_data.py` seeds demo content, `real_data_fetcher.py` suggests optional external data ingestion, and `repository.py` plus `database.py`/`db_models.py` abstract persistence. The repo also includes `asset_graph.db` and `migrations/001_initial.sql`, which indicate a lightweight local database schema and migration path.

6. **Visualization subsystem**
   `src/visualizations/` contains the rendering logic for graph and metric views. The files are split by concern: graph layout/positions/traces, validation, directional arrows, and metric visuals. This is the presentation transformation layer that turns graph state into plot-ready structures, likely using Plotly as noted in the README.

7. **Reporting subsystem**
   `src/reports/` generates schema and integration reports, including `schema_report.py` and `schema_report_generator.py`. This looks like a non-UI output path used for documentation, validation, and possibly API exposure through the schema-report router in `src/api/routers/schema_report.py` and the analogous `api/` package.

8. **API-specific infrastructure**
   The `api/` package contains cross-cutting concerns for the backend: `auth.py`, `cors_utils.py`, `database.py`, `graph_lifecycle.py`, and `models.py`. That suggests the FastAPI service is responsible not just for endpoints, but also for access control, CORS policy, and graph/resource lifecycle management.

9. **Frontend structure**
   `frontend/app/` is a standard Next.js app-router structure with reusable components such as `AssetList`, `MetricsDashboard`, and `NetworkVisualization`. `frontend/app/lib/api.ts` is the likely boundary where the UI integrates with the FastAPI backend, while `frontend/app/types/api.ts` defines the contract shape used by the client.

10. **Legacy interface**
   `app.py` is the original top-level entry point described in the README as a Gradio-based interface. Architecturally, it provides an alternative UI path over the same core financial graph logic, separate from the newer web stack.

11. **Validation and test boundary**
   The repo has a strong test split: Python unit/integration tests under `tests/`, API and database tests at the root, and frontend Jest tests under `frontend/__tests__/`. That indicates most subsystem boundaries are explicitly verified: domain logic, persistence, API contracts, and UI components.

12. **Operational/tooling layer**
   The repository includes extensive CI/CD and security automation under `.github/workflows/`, plus Docker, deployment, and quality tooling. These do not define runtime architecture, but they are important operational boundaries because they validate, scan, and package the Python backend, the frontend, and container deployments.

13. **Recommended diagram emphasis**
   An accurate architecture diagram should show: **data sources / sample data / DB → repository and graph engine → metrics, relationships, and 3D visualization data → FastAPI and/or Gradio UI → Next.js frontend**. The key split is between the **shared domain core** and the **two presentation stacks** built on top of it.

Main entry points: [`api/main.py`](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/main.py) (API app), [`src/logic/asset_graph.py`](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/logic/asset_graph.py) (Asset graph), [`frontend/app/lib/api.ts`](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/lib/api.ts) (API client), [`frontend/app/page.tsx`](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/page.tsx) (Next.js app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core domain"]
  node_asset_graph{{"Asset graph<br/>graph engine<br/>[asset_graph.py]"}}
  node_financial_models["Financial models<br/>domain model"]
  node_sample_data["Sample data<br/>seed data<br/>[sample_data.py]"]
  node_real_data_fetcher["Data fetcher<br/>ingestion"]
  node_repository[("Repository<br/>persistence gateway<br/>[repository.py]")]
  node_database[("DB layer<br/>storage<br/>[database.py]")]
  node_db_models["DB models<br/>persistence model<br/>[db_models.py]"]
end

subgraph group_backend["Backend services"]
  node_api_main(("API app<br/>[main.py]"))
  node_api_assets["Assets API<br/>router<br/>[assets.py]"]
  node_api_graph["Graph API<br/>router<br/>[graph.py]"]
  node_api_auth["Auth<br/>infrastructure<br/>[auth.py]"]
  node_api_db[("API DB<br/>infrastructure<br/>[database.py]")]
  node_api_lifecycle["Lifecycle<br/>infrastructure<br/>[graph_lifecycle.py]"]
  node_schema_reports["Schema reports<br/>reporting<br/>[schema_report.py]"]
end

subgraph group_frontend["Frontend UI"]
  node_frontend_page(("Next.js app<br/>frontend entry<br/>[page.tsx]"))
  node_network_viz["Network view"]
  node_metrics_dash["Metrics dashboard"]
  node_asset_list["Asset list<br/>[AssetList.tsx]"]
  node_api_client["API client<br/>client boundary<br/>[api.ts]"]
end

subgraph group_legacy["Legacy/ops"]
  node_legacy_app(("Legacy app<br/>Gradio app<br/>[app.py]"))
end

node_sample_data -->|"seed"| node_repository
node_real_data_fetcher -->|"ingest"| node_repository
node_repository -->|"stores"| node_database
node_database -->|"maps"| node_db_models
node_repository -->|"loads"| node_asset_graph
node_financial_models -->|"types"| node_asset_graph
node_asset_graph -.->|"reports"| node_schema_reports
node_asset_graph -->|"serves"| node_api_assets
node_asset_graph -->|"serves"| node_api_graph
node_api_main -->|"mounts"| node_api_assets
node_api_main -->|"mounts"| node_api_graph
node_api_main -->|"uses"| node_api_auth
node_api_main -->|"uses"| node_api_db
node_api_main -->|"uses"| node_api_lifecycle
node_frontend_page -->|"calls"| node_api_client
node_api_client -->|"requests"| node_api_main
node_frontend_page -->|"renders"| node_network_viz
node_frontend_page -->|"renders"| node_metrics_dash
node_frontend_page -->|"renders"| node_asset_list
node_network_viz -->|"loads data"| node_api_client
node_metrics_dash -->|"loads data"| node_api_client
node_asset_list -->|"loads data"| node_api_client
node_legacy_app -->|"uses"| node_asset_graph

click node_asset_graph "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/logic/asset_graph.py"
click node_financial_models "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/models/financial_models.py"
click node_sample_data "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/sample_data.py"
click node_real_data_fetcher "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/real_data_fetcher.py"
click node_repository "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/repository.py"
click node_database "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/database.py"
click node_db_models "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/db_models.py"
click node_api_main "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/main.py"
click node_api_assets "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/routers/assets.py"
click node_api_graph "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/routers/graph.py"
click node_api_auth "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/auth.py"
click node_api_db "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/database.py"
click node_api_lifecycle "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/graph_lifecycle.py"
click node_frontend_page "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/page.tsx"
click node_network_viz "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/NetworkVisualization.tsx"
click node_metrics_dash "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/MetricsDashboard.tsx"
click node_asset_list "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/AssetList.tsx"
click node_api_client "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/lib/api.ts"
click node_legacy_app "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/app.py"
click node_schema_reports "https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/reports/schema_report.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_asset_graph,node_financial_models,node_sample_data,node_real_data_fetcher,node_repository,node_database,node_db_models toneBlue
class node_api_main,node_api_assets,node_api_graph,node_api_auth,node_api_db,node_api_lifecycle,node_schema_reports toneAmber
class node_frontend_page,node_network_viz,node_metrics_dash,node_asset_list,node_api_client toneMint
class node_legacy_app toneRose
```

## Components

### Core domain

Shared financial-asset graph engine and domain model

- [Asset graph](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/logic/asset_graph.py): graph engine · Loads assets, discovers relationships, computes strength and metrics, and prepares visualization data · `src/logic/asset_graph.py`
- [Financial models](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/models/financial_models.py): domain model · Equities, bonds, commodities, currencies, and event vocabularies · `src/models/financial_models.py`
- [Sample data](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/sample_data.py): seed data · Demo asset and relationship fixtures · `src/data/sample_data.py`
- [Data fetcher](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/real_data_fetcher.py): ingestion · Optional external data acquisition layer · `src/data/real_data_fetcher.py`
- [Repository](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/repository.py): persistence gateway · Abstracts reads and writes for graph state · `src/data/repository.py`
- [DB layer](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/database.py): storage · Database access and connection support · `src/data/database.py`
- [DB models](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/data/db_models.py): persistence model · Database schema objects for stored graph data · `src/data/db_models.py`

### Backend services

FastAPI services and data access around the shared core

- [API app](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/main.py): FastAPI app · Backend application entrypoint · `api/main.py`
- [Assets API](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/routers/assets.py): router · Asset and relationship endpoints · `api/routers/assets.py`
- [Graph API](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/routers/graph.py): router · Graph payload and visualization endpoints · `api/routers/graph.py`
- [Auth](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/auth.py): infrastructure · Backend access control boundary · `api/auth.py`
- [API DB](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/database.py): infrastructure · Backend database wiring · `api/database.py`
- [Lifecycle](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/api/graph_lifecycle.py): infrastructure · Graph/resource lifecycle management · `api/graph_lifecycle.py`
- [Schema reports](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/src/reports/schema_report.py): reporting · Schema and integration report generation · `src/reports/schema_report.py`

### Frontend UI

Next.js browser application and client boundary

- [Next.js app](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/page.tsx): frontend entry · Browser-facing application shell · `frontend/app/page.tsx`
- [Network view](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/NetworkVisualization.tsx): Asset network visualization component · `frontend/app/components/NetworkVisualization.tsx`
- [Metrics dashboard](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/MetricsDashboard.tsx): UI for graph metrics and summaries · `frontend/app/components/MetricsDashboard.tsx`
- [Asset list](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/components/AssetList.tsx): Asset browsing and selection component · `frontend/app/components/AssetList.tsx`
- [API client](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/frontend/app/lib/api.ts): client boundary · Frontend-to-backend request layer · `frontend/app/lib/api.ts`

### Legacy/ops

Alternate UI entrypoint and repository operations

- [Legacy app](https://github.com/dashfin-fardb/financial-asset-relationship-db/blob/main/app.py): Gradio app · Original top-level user interface entrypoint · `app.py`

## Connections

- Sample data → Repository: seed · Seeds the local persistence layer
- Data fetcher → Repository: ingest · Brings external data into storage
- Repository → DB layer: stores · Uses the database abstraction for persistence
- DB layer → DB models: maps · Persists through schema models
- Repository → Asset graph: loads · Provides assets and relations to the graph engine
- Financial models → Asset graph: types · Shared domain vocabulary for graph operations
- Asset graph → Schema reports: reports · Feeds schema and integration reporting
- Asset graph → Assets API: serves · Asset data exposed through API routes
- Asset graph → Graph API: serves · Graph and visualization payloads exposed through API routes
- API app → Assets API: mounts · Registers asset router
- API app → Graph API: mounts · Registers graph router
- API app → Auth: uses · Applies authentication and access control
- API app → API DB: uses · Initializes backend database wiring
- API app → Lifecycle: uses · Manages graph and resource lifecycle
- Next.js app → API client: calls · Browser UI requests backend data
- API client → API app: requests · Client boundary to FastAPI service
- Next.js app → Network view: renders · Shows graph visualization
- Next.js app → Metrics dashboard: renders · Shows metrics views
- Next.js app → Asset list: renders · Shows asset browsing UI
- Network view → API client: loads data · Consumes graph payloads
- Metrics dashboard → API client: loads data · Consumes metric payloads
- Asset list → API client: loads data · Consumes asset listings
- Legacy app → Asset graph: uses · Legacy UI path built on the same domain core
