# tylerhat/hatfield_financial architecture

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

- Interactive diagram: https://gitdiagram.com/tylerhat/hatfield_financial
- Repository: https://github.com/tylerhat/hatfield_financial

## Overview

Hatfield Financial is a React financial-analysis dashboard backed by a Flask API. Users authenticate, inspect a stock’s market and company data, explore recommendations and strategies, and manage watchlists or custom ETF portfolios. The repository also supports Markov regime analysis and historical portfolio backtests. The graph follows documented routes and the sampled React, auth, feature, and Lambda code; several route implementations were not sampled, so their internal wiring is intentionally left broad.

Main entry points: [`Frontend/src/App.js`](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/App.js) (Dashboard app), [`Backend/routes/recommendations.py`](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/recommendations.py) (Recommendation routes), [`Backend/data_fetcher.py`](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/data_fetcher.py) (Market data fetch), [`Backend/services/custom_etf/walk_forward.py`](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/walk_forward.py) (Walk-forward backtest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Dashboard"]
  node_dashboard["Dashboard app<br/>[App.js]"]
  node_authui["Sign-in UI<br/>[AuthPage.js]"]
  node_frontendauth["Auth context<br/>[AuthContext.js]"]
  node_frontendapi["API client<br/>[api.js]"]
  node_stockviews["Stock views<br/>[StockChart.js]"]
  node_recommendationui["Recommendations UI<br/>[Recommendations.js]"]
  node_etfui["ETF dashboard<br/>[CustomEtfPanel.js]"]
end

subgraph group_api["API"]
  node_flask["Flask API<br/>[app.py]"]
  node_authroutes["Auth routes<br/>[auth_routes.py]"]
  node_stockroutes["Stock data routes<br/>[stock_data.py]"]
  node_inforoutes["Stock info routes<br/>[stock_info.py]"]
  node_recroutes["Recommendation routes<br/>[recommendations.py]"]
  node_markovroutes["Markov routes<br/>[markov.py]"]
  node_backtestroutes["Backtest routes<br/>[backtest.py]"]
  node_useroutes["User data routes<br/>[user_data.py]"]
  node_customroutes["Custom ETF routes<br/>[custom_etf.py]"]
  node_strategyroutes["Strategy routes"]
end

subgraph group_investment["Investment analysis"]
  node_fetcher["Market data fetch<br/>[data_fetcher.py]"]
  node_features["Price features<br/>[row_features.py]"]
  node_markovanalyze["Regime analysis<br/>[analyze.py]"]
  node_recommendationdata["Recommendation data<br/>[recommendations.py]"]
end

subgraph group_portfolio["Custom ETFs"]
  node_rebalance["Rebalance engine<br/>[rebalance_core.py]"]
  node_simulator["Portfolio simulator<br/>[simulator.py]"]
  node_walkforward["Walk-forward backtest<br/>[walk_forward.py]"]
end

subgraph group_identity["Identity and state"]
  node_database[("Application database<br/>[models.py]")]
  node_recommendationcache[("Recommendation cache<br/>[cache.py]")]
end

subgraph group_jobs["Scheduled jobs"]
  node_rebalancelambda["Rebalance trigger"]
  node_precompute["Recommendation precompute<br/>[lambda_handler.py]"]
end

node_investor(("Investor"))
node_marketprovider(("Market data provider"))
node_scheduler(("EventBridge scheduler"))
node_objectstore[("S3 object store")]

node_investor -->|"uses"| node_dashboard
node_dashboard -->|"shows"| node_authui
node_authui -->|"submits credentials"| node_frontendauth
node_frontendauth -->|"sends requests"| node_frontendapi
node_dashboard -->|"requests data"| node_frontendapi
node_frontendapi -->|"HTTP API"| node_flask
node_flask -->|"registers routes"| node_authroutes
node_authroutes -->|"reads and writes users"| node_database
node_dashboard -->|"renders analysis"| node_stockviews
node_dashboard -->|"renders recommendations"| node_recommendationui
node_dashboard -->|"renders portfolios"| node_etfui
node_stockroutes -->|"fetches market data"| node_fetcher
node_inforoutes -->|"fetches stock info"| node_fetcher
node_recroutes -->|"fetches prices"| node_fetcher
node_recroutes -->|"computes features"| node_features
node_recroutes -->|"computes regimes"| node_markovanalyze
node_recroutes -->|"reads and writes"| node_recommendationcache
node_markovroutes -->|"analyzes regimes"| node_markovanalyze
node_strategyroutes -->|"uses market data"| node_fetcher
node_customroutes -->|"runs rebalance"| node_rebalance
node_customroutes -->|"runs simulations"| node_simulator
node_backtestroutes -->|"runs backtest"| node_walkforward
node_walkforward -->|"builds historical features"| node_features
node_walkforward -->|"replays decisions"| node_rebalance
node_useroutes -->|"reads and writes"| node_database
node_scheduler -.->|"triggers"| node_rebalancelambda
node_rebalancelambda -.->|"requests rebalance"| node_customroutes
node_scheduler -.->|"triggers"| node_precompute
node_precompute -.->|"fetches recommendation data"| node_recroutes
node_precompute -.->|"writes results"| node_objectstore

click node_dashboard "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/App.js"
click node_authui "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/AuthPage.js"
click node_frontendauth "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/AuthContext.js"
click node_frontendapi "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/api.js"
click node_stockviews "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/StockChart.js"
click node_recommendationui "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/Recommendations.js"
click node_etfui "https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/CustomEtfPanel.js"
click node_flask "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/app.py"
click node_authroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/auth_routes.py"
click node_stockroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/stock_data.py"
click node_inforoutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/stock_info.py"
click node_recroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/recommendations.py"
click node_markovroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/markov.py"
click node_backtestroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/backtest.py"
click node_useroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/user_data.py"
click node_customroutes "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/custom_etf.py"
click node_strategyroutes "https://github.com/tylerhat/hatfield_financial/tree/main/Backend/routes/strategies"
click node_fetcher "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/data_fetcher.py"
click node_features "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/row_features.py"
click node_markovanalyze "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/markov/analyze.py"
click node_recommendationdata "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/recommendations.py"
click node_rebalance "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/rebalance_core.py"
click node_simulator "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/simulator.py"
click node_walkforward "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/walk_forward.py"
click node_database "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/models.py"
click node_recommendationcache "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/cache.py"
click node_rebalancelambda "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/lambda_rebalance_handler.py"
click node_precompute "https://github.com/tylerhat/hatfield_financial/blob/main/Backend/lambda_handler.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_dashboard,node_authui,node_frontendauth,node_frontendapi,node_stockviews,node_recommendationui,node_etfui toneBlue
class node_flask,node_authroutes,node_stockroutes,node_inforoutes,node_recroutes,node_markovroutes,node_backtestroutes,node_useroutes,node_customroutes,node_strategyroutes,node_objectstore toneAmber
class node_fetcher,node_features,node_markovanalyze,node_recommendationdata toneMint
class node_rebalance,node_simulator,node_walkforward,node_scheduler toneRose
class node_database,node_recommendationcache,node_investor,node_marketprovider toneIndigo
class node_rebalancelambda,node_precompute toneTeal
```

## Components

### Dashboard

- [Dashboard app](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/App.js): `Frontend/src/App.js`
- [Sign-in UI](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/AuthPage.js): `Frontend/src/components/AuthPage.js`
- [Auth context](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/AuthContext.js): `Frontend/src/AuthContext.js`
- [API client](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/api.js): `Frontend/src/api.js`
- [Stock views](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/StockChart.js): `Frontend/src/components/StockChart.js`
- [Recommendations UI](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/Recommendations.js): `Frontend/src/components/Recommendations.js`
- [ETF dashboard](https://github.com/tylerhat/hatfield_financial/blob/main/Frontend/src/components/CustomEtfPanel.js): `Frontend/src/components/CustomEtfPanel.js`

### API

- [Flask API](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/app.py): `Backend/app.py`
- [Auth routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/auth_routes.py): `Backend/routes/auth_routes.py`
- [Stock data routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/stock_data.py): `Backend/routes/stock_data.py`
- [Stock info routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/stock_info.py): `Backend/routes/stock_info.py`
- [Recommendation routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/recommendations.py): `Backend/routes/recommendations.py`
- [Markov routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/markov.py): `Backend/routes/markov.py`
- [Backtest routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/backtest.py): `Backend/routes/backtest.py`
- [User data routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/user_data.py): `Backend/routes/user_data.py`
- [Custom ETF routes](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/custom_etf.py): `Backend/routes/custom_etf.py`
- [Strategy routes](https://github.com/tylerhat/hatfield_financial/tree/main/Backend/routes/strategies): `Backend/routes/strategies`

### Investment analysis

- [Market data fetch](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/data_fetcher.py): `Backend/data_fetcher.py`
- [Price features](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/row_features.py): `Backend/services/row_features.py`
- [Regime analysis](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/markov/analyze.py): `Backend/services/markov/analyze.py`
- [Recommendation data](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/routes/recommendations.py): `Backend/routes/recommendations.py`

### Custom ETFs

- [Rebalance engine](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/rebalance_core.py): `Backend/services/custom_etf/rebalance_core.py`
- [Portfolio simulator](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/simulator.py): `Backend/services/custom_etf/simulator.py`
- [Walk-forward backtest](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/services/custom_etf/walk_forward.py): `Backend/services/custom_etf/walk_forward.py`

### Identity and state

- [Application database](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/models.py): `Backend/models.py`
- [Recommendation cache](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/cache.py): `Backend/cache.py`

### Scheduled jobs

- [Rebalance trigger](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/lambda_rebalance_handler.py): `Backend/lambda_rebalance_handler.py`
- [Recommendation precompute](https://github.com/tylerhat/hatfield_financial/blob/main/Backend/lambda_handler.py): `Backend/lambda_handler.py`

### Other components

- **Investor**
- **Market data provider**
- **EventBridge scheduler**
- **S3 object store**

## Connections

- Investor → Dashboard app: uses
- Dashboard app → Sign-in UI: shows
- Sign-in UI → Auth context: submits credentials
- Auth context → API client: sends requests
- Dashboard app → API client: requests data
- API client → Flask API: HTTP API
- Flask API → Auth routes: registers routes
- Auth routes → Application database: reads and writes users
- Dashboard app → Stock views: renders analysis
- Dashboard app → Recommendations UI: renders recommendations
- Dashboard app → ETF dashboard: renders portfolios
- Stock data routes → Market data fetch: fetches market data
- Stock info routes → Market data fetch: fetches stock info
- Recommendation routes → Market data fetch: fetches prices
- Recommendation routes → Price features: computes features
- Recommendation routes → Regime analysis: computes regimes
- Recommendation routes → Recommendation cache: reads and writes
- Markov routes → Regime analysis: analyzes regimes
- Strategy routes → Market data fetch: uses market data
- Custom ETF routes → Rebalance engine: runs rebalance
- Custom ETF routes → Portfolio simulator: runs simulations
- Backtest routes → Walk-forward backtest: runs backtest
- Walk-forward backtest → Price features: builds historical features
- Walk-forward backtest → Rebalance engine: replays decisions
- User data routes → Application database: reads and writes
- EventBridge scheduler → Rebalance trigger: triggers
- Rebalance trigger → Custom ETF routes: requests rebalance
- EventBridge scheduler → Recommendation precompute: triggers
- Recommendation precompute → Recommendation routes: fetches recommendation data
- Recommendation precompute → S3 object store: writes results
