# abdulrahman-m-code/finsight_ai architecture

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

- Interactive diagram: https://gitdiagram.com/abdulrahman-m-code/finsight_ai
- Repository: https://github.com/abdulrahman-m-code/finsight_ai

## Overview

FinSight AI is an unfinished financial-planning application: users register, enter household finances, debts, goals, and investment-risk information, then view portfolio, debt, and goal recommendations. The frontend also exposes portfolio analytics, settings, and successive-value modeling; a backend worker handles background advice and portfolio rebalancing. The graph follows documented routes and source-index references. Several frontend-to-backend endpoint details and unsampled route implementations are not shown, so those connections are omitted rather than inferred.

Main entry points: [`backend/app/worker.py`](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/worker.py) (Background task worker), [`backend/app/routes/financial_data.py`](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/financial_data.py) (Financial data routes), [`frontend/src/App.tsx`](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/App.tsx) (Application routes), [`backend/app/main.py`](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Frontend experience"]
  node_app["Application routes<br/>[App.tsx]"]
  node_onboarding["Financial questionnaire"]
  node_goals_ui["Goals advice view<br/>[GoalsAdvice.tsx]"]
  node_portfolio_ui["Portfolio analytics"]
  node_debt_ui["Debt advice view"]
  node_settings_ui["User settings<br/>[SettingsPage.tsx]"]
  node_auth_ui["Signup and login<br/>[Signup.tsx]"]
end

subgraph group_identity["Identity and API"]
  node_api["FastAPI application<br/>[main.py]"]
  node_auth_routes["Authentication routes<br/>[auth.py]"]
end

subgraph group_planning["Financial planning"]
  node_financial_routes["Financial data routes<br/>[financial_data.py]"]
  node_goal_routes["Goal advice routes"]
  node_debt_routes["Debt advice routes"]
  node_portfolio_routes["Portfolio advice routes"]
  node_portfolio_engine["Portfolio construction"]
  node_goal_engine["Goals advisor<br/>[goals_advisor.py]"]
  node_debt_engine["Successive value model"]
end

subgraph group_storage["Persistence"]
  node_db[("Relational database<br/>[database.py]")]
  node_financial_records["Financial and advice records"]
  node_portfolio_records["Portfolio records<br/>[portfolios.py]"]
  node_debt_records["Debt advice records<br/>[debts_advices.py]"]
  node_user_records["User records<br/>[user.py]"]
end

subgraph group_async["Background services"]
  node_worker["Background task worker<br/>[worker.py]"]
  node_rebalance["Rebalancing WebSocket<br/>[rebalancing_ws.py]"]
end

node_user(("User"))
node_market["Market price data"]
node_redis["Redis pub/sub"]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_auth_ui
node_app -->|"routes to"| node_onboarding
node_app -->|"routes to"| node_goals_ui
node_app -->|"routes to"| node_portfolio_ui
node_app -->|"routes to"| node_debt_ui
node_app -->|"routes to"| node_settings_ui
node_user -->|"enters finances"| node_onboarding
node_api -->|"registers"| node_auth_routes
node_api -->|"registers"| node_financial_routes
node_api -->|"registers"| node_goal_routes
node_api -->|"registers"| node_debt_routes
node_api -->|"registers"| node_portfolio_routes
node_auth_routes -->|"queries and updates"| node_user_records
node_auth_routes -->|"opens session"| node_db
node_financial_routes -->|"invokes"| node_portfolio_engine
node_financial_routes -->|"invokes"| node_goal_engine
node_financial_routes -->|"invokes"| node_debt_engine
node_financial_routes -->|"reads and writes"| node_financial_records
node_financial_routes -->|"reads and writes"| node_portfolio_records
node_financial_routes -->|"reads and writes"| node_debt_records
node_financial_routes -->|"dispatches tasks"| node_worker
node_worker -->|"invokes"| node_portfolio_engine
node_worker -->|"invokes"| node_goal_engine
node_worker -->|"invokes"| node_debt_engine
node_worker -->|"persists"| node_financial_records
node_worker -->|"reads and writes"| node_portfolio_records
node_worker -->|"persists"| node_debt_records
node_worker -->|"opens sessions"| node_db
node_worker -->|"requests prices"| node_market
node_worker -->|"publishes updates"| node_redis
node_rebalance -.->|"uses manager"| node_worker
node_financial_records -->|"maps to"| node_db
node_portfolio_records -->|"maps to"| node_db
node_debt_records -->|"maps to"| node_db
node_user_records -->|"maps to"| node_db

click node_app "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/App.tsx"
click node_onboarding "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/MultiStepContext.tsx"
click node_goals_ui "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/GoalsAdvice.tsx"
click node_portfolio_ui "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/PortfolioAnalytics.tsx"
click node_debt_ui "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/SuccessiveValueFormulaModeling.tsx"
click node_settings_ui "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/SettingsPage.tsx"
click node_auth_ui "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/Signup.tsx"
click node_api "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/main.py"
click node_auth_routes "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/auth.py"
click node_financial_routes "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/financial_data.py"
click node_goal_routes "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_goals_ui_data.py"
click node_debt_routes "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_debts_advice_data.py"
click node_portfolio_routes "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_portfolio_advice_ui_data.py"
click node_portfolio_engine "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/portfolio_construction.py"
click node_goal_engine "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/goals_advisor.py"
click node_debt_engine "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/successive_value_modeling.py"
click node_db "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/database.py"
click node_financial_records "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/user_financial_data.py"
click node_portfolio_records "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/portfolio_models/portfolios.py"
click node_debt_records "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/debt_models/debts_advices.py"
click node_user_records "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/registration/user.py"
click node_worker "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/worker.py"
click node_rebalance "https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/rebalancing_ws.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_onboarding,node_goals_ui,node_portfolio_ui,node_debt_ui,node_settings_ui,node_auth_ui,node_user toneBlue
class node_api,node_auth_routes,node_redis toneAmber
class node_financial_routes,node_goal_routes,node_debt_routes,node_portfolio_routes,node_portfolio_engine,node_goal_engine,node_debt_engine toneMint
class node_db,node_financial_records,node_portfolio_records,node_debt_records,node_user_records toneRose
class node_worker,node_rebalance,node_market toneIndigo
```

## Components

### Frontend experience

- [Application routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Financial questionnaire](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/MultiStepContext.tsx): `frontend/src/Pages/MultiStepContext.tsx`
- [Goals advice view](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/GoalsAdvice.tsx): `frontend/src/Pages/GoalsAdvice.tsx`
- [Portfolio analytics](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/PortfolioAnalytics.tsx): `frontend/src/Pages/PortfolioAnalytics.tsx`
- [Debt advice view](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/SuccessiveValueFormulaModeling.tsx): `frontend/src/Pages/SuccessiveValueFormulaModeling.tsx`
- [User settings](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/SettingsPage.tsx): `frontend/src/Pages/SettingsPage.tsx`
- [Signup and login](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/frontend/src/Pages/Signup.tsx): `frontend/src/Pages/Signup.tsx`

### Identity and API

- [FastAPI application](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/auth.py): `backend/app/routes/auth.py`

### Financial planning

- [Financial data routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/financial_data.py): `backend/app/routes/financial_data.py`
- [Goal advice routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_goals_ui_data.py): `backend/app/routes/get_goals_ui_data.py`
- [Debt advice routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_debts_advice_data.py): `backend/app/routes/get_debts_advice_data.py`
- [Portfolio advice routes](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/get_portfolio_advice_ui_data.py): `backend/app/routes/get_portfolio_advice_ui_data.py`
- [Portfolio construction](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/portfolio_construction.py): `backend/app/core/finance/portfolio_construction.py`
- [Goals advisor](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/goals_advisor.py): `backend/app/core/finance/goals_advisor.py`
- [Successive value model](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/core/finance/successive_value_modeling.py): `backend/app/core/finance/successive_value_modeling.py`

### Persistence

- [Relational database](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/database.py): `backend/app/database.py`
- [Financial and advice records](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/user_financial_data.py): `backend/app/models/user_financial_data.py`
- [Portfolio records](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/portfolio_models/portfolios.py): `backend/app/models/portfolio_models/portfolios.py`
- [Debt advice records](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/debt_models/debts_advices.py): `backend/app/models/debt_models/debts_advices.py`
- [User records](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/models/registration/user.py): `backend/app/models/registration/user.py`

### Background services

- [Background task worker](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/worker.py): `backend/app/worker.py`
- [Rebalancing WebSocket](https://github.com/abdulrahman-m-code/finsight_ai/blob/main/backend/app/routes/rebalancing_ws.py): `backend/app/routes/rebalancing_ws.py`

### Other components

- **User**
- **Market price data**
- **Redis pub/sub**

## Connections

- User → Application routes: uses (evidence: `frontend/src/App.tsx`)
- Application routes → Signup and login: routes to (evidence: `frontend/src/App.tsx`)
- Application routes → Financial questionnaire: routes to (evidence: `frontend/src/App.tsx`)
- Application routes → Goals advice view: routes to (evidence: `frontend/src/App.tsx`)
- Application routes → Portfolio analytics: routes to (evidence: `frontend/src/App.tsx`)
- Application routes → Debt advice view: routes to (evidence: `frontend/src/App.tsx`)
- Application routes → User settings: routes to (evidence: `frontend/src/App.tsx`)
- User → Financial questionnaire: enters finances (evidence: `frontend/src/Pages/MultiStepContext.tsx`)
- FastAPI application → Authentication routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Financial data routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Goal advice routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Debt advice routes: registers (evidence: `backend/app/main.py`)
- FastAPI application → Portfolio advice routes: registers (evidence: `backend/app/main.py`)
- Authentication routes → User records: queries and updates (evidence: `backend/app/routes/auth.py`)
- Authentication routes → Relational database: opens session (evidence: `backend/app/routes/auth.py`)
- Financial data routes → Portfolio construction: invokes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Goals advisor: invokes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Successive value model: invokes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Financial and advice records: reads and writes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Portfolio records: reads and writes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Debt advice records: reads and writes (evidence: `backend/app/routes/financial_data.py`)
- Financial data routes → Background task worker: dispatches tasks (evidence: `backend/app/routes/financial_data.py`)
- Background task worker → Portfolio construction: invokes (evidence: `backend/app/worker.py`)
- Background task worker → Goals advisor: invokes (evidence: `backend/app/worker.py`)
- Background task worker → Successive value model: invokes (evidence: `backend/app/worker.py`)
- Background task worker → Financial and advice records: persists (evidence: `backend/app/worker.py`)
- Background task worker → Portfolio records: reads and writes (evidence: `backend/app/worker.py`)
- Background task worker → Debt advice records: persists (evidence: `backend/app/worker.py`)
- Background task worker → Relational database: opens sessions (evidence: `backend/app/worker.py`)
- Background task worker → Market price data: requests prices (evidence: `backend/app/worker.py`)
- Background task worker → Redis pub/sub: publishes updates (evidence: `backend/app/worker.py`)
- Rebalancing WebSocket → Background task worker: uses manager
- Financial and advice records → Relational database: maps to (evidence: `backend/app/models/user_financial_data.py`)
- Portfolio records → Relational database: maps to (evidence: `backend/app/models/portfolio_models/portfolios.py`)
- Debt advice records → Relational database: maps to (evidence: `backend/app/models/debt_models/debts_advices.py`)
- User records → Relational database: maps to (evidence: `backend/app/models/registration/user.py`)
