# hmdank/ourportfolios architecture

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

- Interactive diagram: https://gitdiagram.com/hmdank/ourportfolios
- Repository: https://github.com/hmdank/ourportfolios

## Overview

#### Purpose and Runtime

OurPortfolios is a stock-analysis platform for investor portfolio research: selecting securities, analyzing individual tickers and industries, comparing instruments, and creating recommendation frameworks. It is a Python Reflex application, started locally with `uv run reflex run`; Reflex configuration and app composition are centered in `rxconfig.py` and `ourportfolios/ourportfolios.py`. An optional PostgreSQL URI is supplied through `.env`.

#### Application Composition and Routing

The Reflex app assembles page-level views into a multi-page frontend. Page modules are the primary route boundaries, with reusable visual elements separated from page orchestration:
- `ourportfolios/ourportfolios.py`
- `ourportfolios/pages/landing/index.py`
- `ourportfolios/pages/analyze/index.py`

Likely user flow begins at landing, then moves through security selection, ticker/industry analysis, comparison, and recommendations.

#### Selection and Search Workflow

The selection experience combines filtering/control UI with page-local state, while shared search and ticker-board state support reusable market-navigation surfaces:
- `ourportfolios/pages/select/index.py`
- `ourportfolios/pages/select/filters.py`
- `ourportfolios/pages/select/state.py`
- `ourportfolios/state/search_state.py`
- `ourportfolios/state/ticker_board_state.py`

This creates a boundary between interactive Reflex state/event handling and declarative page components.

#### Instrument and Financial Analysis

Ticker analysis is decomposed into company identity, metrics, performance, and chart presentation. Financial-statement handling is a cross-cutting state concern, with transformations isolated under utilities:
- `ourportfolios/pages/ticker_analysis/index.py`
- `ourportfolios/pages/ticker_analysis/state.py`
- `ourportfolios/state/financial_statement_state.py`
- `ourportfolios/components/financial_statement.py`
- `ourportfolios/utils/compute_instrument.py`
- `ourportfolios/utils/preprocessing/financial_statements.py`

Data is loaded and normalized before being computed into instrument-level metrics and rendered as cards, statements, and price charts.

#### Comparison and Portfolio Cart

Comparison uses dedicated controls, cards, and shared comparison state; cart state represents a separate selection/portfolio boundary:
- `ourportfolios/pages/compare/index.py`
- `ourportfolios/pages/compare/controls.py`
- `ourportfolios/state/comparison_state.py`
- `ourportfolios/state/cart_state.py`
- `ourportfolios/components/metric_cards.py`

The expected control flow is user selection → stateful comparison/cart updates → rendered comparative metrics.

#### Recommendation Frameworks

Recommendations are modeled as user-managed frameworks, with dialogs for creating or editing framework definitions and state for their lifecycle:
- `ourportfolios/pages/recommend/index.py`
- `ourportfolios/pages/recommend/state.py`
- `ourportfolios/pages/recommend/framework_cards.py`
- `ourportfolios/state/framework_state.py`

This is the main extensibility point for converting analysis inputs into personalized portfolio criteria.

#### Shared UI, Data Access, and External Boundaries

Reusable components provide consistent navigation, dialogs/drawers, charts, cards, and loading behavior:
- `ourportfolios/components/navbar.py`
- `ourportfolios/components/dialog.py`
- `ourportfolios/components/price_chart.py`
- `assets/chart.js`

Data-access/query concerns are isolated from page code in `ourportfolios/utils/load_data.py` and `ourportfolios/utils/generate_query.py`; PostgreSQL is the explicit external persistence option. Text/event preprocessing and a scheduler suggest prepared market/news-derived content and periodic background-oriented work:
- `ourportfolios/utils/preprocess_texts.py`
- `ourportfolios/utils/preprocessing/events_texts.py`
- `ourportfolios/utils/scheduler.py`

Main entry points: [`ourportfolios/ourportfolios.py`](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/ourportfolios.py) (App composition), [`ourportfolios/pages/select/index.py`](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/select/index.py) (Security selection), [`ourportfolios/pages/ticker_analysis/index.py`](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/ticker_analysis/index.py) (Ticker analysis), [`ourportfolios/pages/compare/index.py`](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/compare/index.py) (Comparison)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Reflex Runtime"]
  node_config["Reflex config<br/>configuration<br/>[rxconfig.py]"]
  node_app["App composition<br/>Reflex app<br/>[ourportfolios.py]"]
end

subgraph group_pages["Page Routes"]
  node_landing["Landing<br/>route page<br/>[index.py]"]
  node_selection["Security selection<br/>route page<br/>[index.py]"]
  node_ticker["Ticker analysis<br/>route page<br/>[index.py]"]
  node_compare["Comparison<br/>route page<br/>[index.py]"]
  node_recommend["Recommendations<br/>route page<br/>[index.py]"]
  node_select_controls["Selection filters<br/>page controls<br/>[filters.py]"]
  node_compare_controls["Comparison controls<br/>page controls<br/>[controls.py]"]
end

subgraph group_state["Interactive State"]
  node_ticker_state["Ticker state<br/>Reflex state<br/>[state.py]"]
  node_search_state["Search state<br/>Reflex state<br/>[search_state.py]"]
  node_ticker_board["Ticker board state<br/>Reflex state"]
  node_comparison_state["Comparison state<br/>Reflex state"]
  node_cart_state["Portfolio cart state<br/>Reflex state<br/>[cart_state.py]"]
  node_framework_state["Framework state<br/>Reflex state<br/>[framework_state.py]"]
  node_financial_state["Financial statement state<br/>Reflex state"]
end

subgraph group_analysis["Data &amp; Analysis"]
  node_data_access["Query and data loading<br/>data access<br/>[load_data.py]"]
  node_statement_prep["Statement normalization<br/>data transformation"]
  node_instrument_compute["Instrument metrics<br/>analytics"]
  node_content_pipeline["Text and event preparation<br/>background pipeline"]
  node_scheduler{{"Scheduler<br/>background runtime<br/>[scheduler.py]"}}
  node_postgres[("PostgreSQL<br/>external persistence")]
end

subgraph group_shared["Shared UI"]
  node_shared_ui["Shared navigation and dialogs<br/>UI components<br/>[navbar.py]"]
  node_financial_view["Financial statement view<br/>UI component"]
  node_price_chart["Price chart<br/>UI component<br/>[price_chart.py]"]
  node_chart_js["Chart asset<br/>browser asset<br/>[chart.js]"]
  node_metric_cards["Metric cards<br/>UI component<br/>[metric_cards.py]"]
end

node_config -->|"configures"| node_app
node_app -->|"routes"| node_landing
node_app -->|"routes"| node_selection
node_app -->|"routes"| node_ticker
node_app -->|"routes"| node_compare
node_app -->|"routes"| node_recommend
node_selection -->|"composes"| node_select_controls
node_selection -->|"searches through"| node_search_state
node_selection -->|"uses"| node_ticker_board
node_ticker -->|"drives"| node_ticker_state
node_ticker_state -->|"uses"| node_financial_state
node_financial_state -->|"normalizes with"| node_statement_prep
node_statement_prep -->|"feeds"| node_instrument_compute
node_instrument_compute -->|"provides metrics"| node_ticker_state
node_ticker -->|"renders"| node_financial_view
node_ticker -->|"renders"| node_price_chart
node_price_chart -->|"uses"| node_chart_js
node_compare -->|"composes"| node_compare_controls
node_compare -->|"updates"| node_comparison_state
node_compare -->|"manages selections"| node_cart_state
node_comparison_state -->|"renders metrics"| node_metric_cards
node_recommend -->|"manages"| node_framework_state
node_data_access -->|"queries"| node_postgres
node_data_access -->|"supplies raw data"| node_statement_prep
node_scheduler -->|"runs periodically"| node_content_pipeline
node_shared_ui -.->|"supports navigation"| node_landing

click node_config "https://github.com/hmdank/ourportfolios/blob/main/rxconfig.py"
click node_app "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/ourportfolios.py"
click node_landing "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/landing/index.py"
click node_selection "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/select/index.py"
click node_ticker "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/ticker_analysis/index.py"
click node_compare "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/compare/index.py"
click node_recommend "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/recommend/index.py"
click node_select_controls "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/select/filters.py"
click node_compare_controls "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/compare/controls.py"
click node_ticker_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/ticker_analysis/state.py"
click node_search_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/search_state.py"
click node_ticker_board "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/ticker_board_state.py"
click node_comparison_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/comparison_state.py"
click node_cart_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/cart_state.py"
click node_framework_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/framework_state.py"
click node_financial_state "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/financial_statement_state.py"
click node_data_access "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/load_data.py"
click node_statement_prep "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/preprocessing/financial_statements.py"
click node_instrument_compute "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/compute_instrument.py"
click node_content_pipeline "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/preprocess_texts.py"
click node_scheduler "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/scheduler.py"
click node_shared_ui "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/navbar.py"
click node_financial_view "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/financial_statement.py"
click node_price_chart "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/price_chart.py"
click node_chart_js "https://github.com/hmdank/ourportfolios/blob/main/assets/chart.js"
click node_metric_cards "https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/metric_cards.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_config,node_app toneBlue
class node_landing,node_selection,node_ticker,node_compare,node_recommend,node_select_controls,node_compare_controls toneAmber
class node_ticker_state,node_search_state,node_ticker_board,node_comparison_state,node_cart_state,node_framework_state,node_financial_state toneMint
class node_data_access,node_statement_prep,node_instrument_compute,node_content_pipeline,node_scheduler,node_postgres toneRose
class node_shared_ui,node_financial_view,node_price_chart,node_chart_js,node_metric_cards toneIndigo
```

## Components

### Reflex Runtime

- [Reflex config](https://github.com/hmdank/ourportfolios/blob/main/rxconfig.py): configuration · Local Reflex runtime configuration. · `rxconfig.py`
- [App composition](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/ourportfolios.py): Reflex app · Registers and assembles multi-page views. · `ourportfolios/ourportfolios.py`

### Page Routes

- [Landing](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/landing/index.py): route page · `ourportfolios/pages/landing/index.py`
- [Security selection](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/select/index.py): route page · `ourportfolios/pages/select/index.py`
- [Ticker analysis](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/ticker_analysis/index.py): route page · `ourportfolios/pages/ticker_analysis/index.py`
- [Comparison](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/compare/index.py): route page · `ourportfolios/pages/compare/index.py`
- [Recommendations](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/recommend/index.py): route page · `ourportfolios/pages/recommend/index.py`
- [Selection filters](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/select/filters.py): page controls · `ourportfolios/pages/select/filters.py`
- [Comparison controls](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/compare/controls.py): page controls · `ourportfolios/pages/compare/controls.py`

### Interactive State

- [Ticker state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/pages/ticker_analysis/state.py): Reflex state · Coordinates ticker analysis interactions. · `ourportfolios/pages/ticker_analysis/state.py`
- [Search state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/search_state.py): Reflex state · `ourportfolios/state/search_state.py`
- [Ticker board state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/ticker_board_state.py): Reflex state · `ourportfolios/state/ticker_board_state.py`
- [Comparison state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/comparison_state.py): Reflex state · `ourportfolios/state/comparison_state.py`
- [Portfolio cart state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/cart_state.py): Reflex state · `ourportfolios/state/cart_state.py`
- [Framework state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/framework_state.py): Reflex state · Manages recommendation framework lifecycle. · `ourportfolios/state/framework_state.py`
- [Financial statement state](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/state/financial_statement_state.py): Reflex state · Cross-cutting financial-statement handling. · `ourportfolios/state/financial_statement_state.py`

### Data & Analysis

- [Query and data loading](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/load_data.py): data access · Builds queries and loads market data outside page code. · `ourportfolios/utils/load_data.py`
- [Statement normalization](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/preprocessing/financial_statements.py): data transformation · `ourportfolios/utils/preprocessing/financial_statements.py`
- [Instrument metrics](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/compute_instrument.py): analytics · Computes instrument-level financial metrics. · `ourportfolios/utils/compute_instrument.py`
- [Text and event preparation](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/preprocess_texts.py): background pipeline · Prepares market or news-derived content for periodic work. · `ourportfolios/utils/preprocess_texts.py`
- [Scheduler](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/utils/scheduler.py): background runtime · `ourportfolios/utils/scheduler.py`
- **PostgreSQL**: external persistence · Optional database configured through .env.

### Shared UI

- [Shared navigation and dialogs](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/navbar.py): UI components · `ourportfolios/components/navbar.py`
- [Financial statement view](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/financial_statement.py): UI component · `ourportfolios/components/financial_statement.py`
- [Price chart](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/price_chart.py): UI component · Uses a charting asset for price presentation. · `ourportfolios/components/price_chart.py`
- [Chart asset](https://github.com/hmdank/ourportfolios/blob/main/assets/chart.js): browser asset · `assets/chart.js`
- [Metric cards](https://github.com/hmdank/ourportfolios/blob/main/ourportfolios/components/metric_cards.py): UI component · `ourportfolios/components/metric_cards.py`

## Connections

- Reflex config → App composition: configures
- App composition → Landing: routes
- App composition → Security selection: routes
- App composition → Ticker analysis: routes
- App composition → Comparison: routes
- App composition → Recommendations: routes
- Security selection → Selection filters: composes
- Security selection → Search state: searches through
- Security selection → Ticker board state: uses
- Ticker analysis → Ticker state: drives
- Ticker state → Financial statement state: uses
- Financial statement state → Statement normalization: normalizes with
- Statement normalization → Instrument metrics: feeds
- Instrument metrics → Ticker state: provides metrics
- Ticker analysis → Financial statement view: renders
- Ticker analysis → Price chart: renders
- Price chart → Chart asset: uses
- Comparison → Comparison controls: composes
- Comparison → Comparison state: updates
- Comparison → Portfolio cart state: manages selections
- Comparison state → Metric cards: renders metrics
- Recommendations → Framework state: manages
- Query and data loading → PostgreSQL: queries
- Query and data loading → Statement normalization: supplies raw data
- Scheduler → Text and event preparation: runs periodically
- Shared navigation and dialogs → Landing: supports navigation
