# imskr/northstar architecture

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

- Interactive diagram: https://gitdiagram.com/imskr/northstar
- Repository: https://github.com/imskr/northstar

## Overview

Northstar is a private, self-hosted portfolio ledger. An investor uses the browser app to manage holdings and trades, sync quotes, and review accounting, allocation, and goal projections; the Flask APIs provide account-scoped state and market data, with the database canonical after login. The README documents browser localStorage as a fast offline working copy. The sampled sources show API registration, authentication, persistence, catalog, and market-provider calls; goal and analytics features are documented but their internal implementation was not sampled.

Main entry points: [`northstar/__init__.py`](https://github.com/imskr/northstar/blob/main/northstar/__init__.py) (Flask application), [`northstar/auth.py`](https://github.com/imskr/northstar/blob/main/northstar/auth.py) (Authentication), [`northstar/market_api.py`](https://github.com/imskr/northstar/blob/main/northstar/market_api.py) (Market API), [`northstar/market_provider.py`](https://github.com/imskr/northstar/blob/main/northstar/market_provider.py) (Quote normalization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_portfolio_app["Ledger and goals<br/>[app.js]"]
  node_browser_cache[("Local working copy")]
end

subgraph group_server["Flask services"]
  node_flask_app["Flask application<br/>[__init__.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_password_reset["Password reset<br/>[password_reset.py]"]
  node_state_api["Portfolio state API<br/>[state_api.py]"]
  node_market_api["Market API<br/>[market_api.py]"]
end

subgraph group_markets["Instrument and markets"]
  node_catalog["Instrument catalog<br/>[catalog.py]"]
  node_market_provider["Quote normalization<br/>[market_provider.py]"]
  node_market_services["Yahoo Finance and Stooq"]
end

subgraph group_storage["Persistence"]
  node_database[("SQLite or Turso<br/>[db.py]")]
end

node_investor(("Investor"))

node_investor -->|"uses"| node_portfolio_app
node_portfolio_app -->|"calls JSON API"| node_flask_app
node_portfolio_app -->|"caches state"| node_browser_cache
node_flask_app -->|"registers"| node_auth
node_flask_app -->|"registers"| node_password_reset
node_flask_app -->|"registers"| node_state_api
node_flask_app -->|"registers"| node_market_api
node_flask_app -->|"initializes"| node_database
node_auth -->|"reads and writes"| node_database
node_auth -->|"uses security helpers"| node_market_provider
node_state_api -->|"requires login"| node_auth
node_state_api -->|"reads and writes"| node_database
node_market_api -->|"requires login"| node_auth
node_market_api -->|"searches and resolves"| node_catalog
node_market_api -->|"normalizes quotes"| node_market_provider
node_catalog -->|"validates symbols"| node_market_provider
node_market_provider -->|"fetches market data"| node_market_services
node_database -->|"stores account data"| node_investor

click node_portfolio_app "https://github.com/imskr/northstar/blob/main/static/js/app.js"
click node_flask_app "https://github.com/imskr/northstar/blob/main/northstar/__init__.py"
click node_auth "https://github.com/imskr/northstar/blob/main/northstar/auth.py"
click node_password_reset "https://github.com/imskr/northstar/blob/main/northstar/password_reset.py"
click node_state_api "https://github.com/imskr/northstar/blob/main/northstar/state_api.py"
click node_market_api "https://github.com/imskr/northstar/blob/main/northstar/market_api.py"
click node_catalog "https://github.com/imskr/northstar/blob/main/northstar/catalog.py"
click node_market_provider "https://github.com/imskr/northstar/blob/main/northstar/market_provider.py"
click node_database "https://github.com/imskr/northstar/blob/main/northstar/db.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_portfolio_app,node_browser_cache toneBlue
class node_flask_app,node_auth,node_password_reset,node_state_api,node_market_api toneAmber
class node_catalog,node_market_provider,node_market_services toneMint
class node_database toneRose
class node_investor toneIndigo
```

## Components

### Browser client

- [Ledger and goals](https://github.com/imskr/northstar/blob/main/static/js/app.js): `static/js/app.js`
- **Local working copy**

### Flask services

- [Flask application](https://github.com/imskr/northstar/blob/main/northstar/__init__.py): `northstar/__init__.py`
- [Authentication](https://github.com/imskr/northstar/blob/main/northstar/auth.py): `northstar/auth.py`
- [Password reset](https://github.com/imskr/northstar/blob/main/northstar/password_reset.py): `northstar/password_reset.py`
- [Portfolio state API](https://github.com/imskr/northstar/blob/main/northstar/state_api.py): `northstar/state_api.py`
- [Market API](https://github.com/imskr/northstar/blob/main/northstar/market_api.py): `northstar/market_api.py`

### Instrument and markets

- [Instrument catalog](https://github.com/imskr/northstar/blob/main/northstar/catalog.py): `northstar/catalog.py`
- [Quote normalization](https://github.com/imskr/northstar/blob/main/northstar/market_provider.py): `northstar/market_provider.py`
- **Yahoo Finance and Stooq**

### Persistence

- [SQLite or Turso](https://github.com/imskr/northstar/blob/main/northstar/db.py): `northstar/db.py`

### Other components

- **Investor**

## Connections

- Investor → Ledger and goals: uses (evidence: `README.md`)
- Ledger and goals → Flask application: calls JSON API (evidence: `README.md`)
- Ledger and goals → Local working copy: caches state (evidence: `README.md`)
- Flask application → Authentication: registers (evidence: `northstar/__init__.py`)
- Flask application → Password reset: registers (evidence: `northstar/__init__.py`)
- Flask application → Portfolio state API: registers (evidence: `northstar/__init__.py`)
- Flask application → Market API: registers (evidence: `northstar/__init__.py`)
- Flask application → SQLite or Turso: initializes (evidence: `northstar/__init__.py`)
- Authentication → SQLite or Turso: reads and writes (evidence: `northstar/auth.py`)
- Authentication → Quote normalization: uses security helpers (evidence: `northstar/auth.py`)
- Portfolio state API → Authentication: requires login (evidence: `northstar/state_api.py`)
- Portfolio state API → SQLite or Turso: reads and writes (evidence: `northstar/state_api.py`)
- Market API → Authentication: requires login (evidence: `northstar/market_api.py`)
- Market API → Instrument catalog: searches and resolves (evidence: `northstar/market_api.py`)
- Market API → Quote normalization: normalizes quotes (evidence: `northstar/market_api.py`)
- Instrument catalog → Quote normalization: validates symbols (evidence: `northstar/catalog.py`)
- Quote normalization → Yahoo Finance and Stooq: fetches market data (evidence: `README.md`)
- SQLite or Turso → Investor: stores account data (evidence: `README.md`)
