# ishan-pngbeep/blue-peak-capital architecture

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

- Interactive diagram: https://gitdiagram.com/ishan-pngbeep/blue-peak-capital
- Repository: https://github.com/ishan-pngbeep/blue-peak-capital

## Overview

1. **Repository shape**
   - This is a split frontend/backend market-intelligence app.
   - The main user-facing artifact is a single-page HTML dashboard (`index.html` at the repo root, plus a `frontend/index.html` copy in the tree).
   - The server side is a small Python FastAPI service in `backend/`.

2. **Frontend boundary**
   - The browser layer is plain HTML/CSS/JavaScript, not a SPA framework.
   - It owns search input, tab switching, chart rendering, and visual presentation of the AI output.
   - Its primary integration point is a `POST /api/search` call to the backend, with CORS enabled so a GitHub Pages-hosted frontend can talk to a Railway-hosted API.

3. **Backend orchestration layer**
   - `backend/main.py` is the central orchestration point.
   - It receives the user’s keyword, coordinates data collection, sends the assembled context to the LLM, and returns structured JSON to the UI.
   - It also exposes lighter helper endpoints like prices, macro data, and a waitlist write path.

4. **Data ingestion subsystem**
   - `backend/data_sources.py` is the fan-out layer to external market sources.
   - It fetches from NewsAPI, yFinance, CoinGecko, FRED, and the Fear & Greed index.
   - These calls run in parallel and are designed to degrade gracefully: one failing source does not abort the whole request.

5. **AI synthesis subsystem**
   - `backend/analyzer.py` is the LLM adapter.
   - It converts the merged market data into a prompt, instructs Claude to act as a financial analyst, and requires a strict JSON response.
   - This is the key transformation boundary: raw market data becomes a structured intelligence report.

6. **Core end-to-end data flow**
   - User enters a keyword in the dashboard.
   - Frontend posts it to `POST /api/search`.
   - Backend fetches live data from multiple APIs in parallel.
   - Backend passes the merged payload to Claude.
   - Claude returns a structured market thesis.
   - Frontend renders the result into cards, ripple-chain visuals, charts, and macro indicators.

7. **Response contract**
   - The system is built around a fixed JSON schema from Claude, including sector, trend, confidence, drivers, risks, impacted companies, ripple chain, and forward outlook.
   - That contract is important because the frontend is not just dumping text; it expects machine-readable fields to drive multiple visual components.

8. **Supplementary API endpoints**
   - `GET /api/prices` and `GET /api/macro` support background market widgets and persistent navbar indicators.
   - `POST /api/waitlist` stores email addresses in Supabase, which is separate from the intelligence request path.

9. **Runtime and deployment**
   - Backend runtime is Python 3.11 with FastAPI/Uvicorn.
   - Frontend is static and intended for GitHub Pages.
   - Backend hosting is Railway, with API keys and service URLs injected through environment variables rather than shipped to the browser.

10. **External systems that materially affect architecture**
   - Anthropic Claude is the central AI dependency and the expensive part of the request path.
   - NewsAPI, yFinance, CoinGecko, FRED, and Fear & Greed are the market data inputs.
   - Redis is used as a cache layer to reduce repeated synthesis latency.
   - Supabase provides persistent storage for waitlist/user data.

11. **Diagram-worthy boundaries**
   - Browser vs. API server is the primary trust and network boundary.
   - Inside the backend, there is a clear split between ingestion (`data_sources.py`), orchestration (`main.py`), and synthesis (`analyzer.py`).
   - External APIs are all downstream dependencies of the ingestion layer; Claude is downstream of the merged data payload, not of the browser.

12. **Failure and latency characteristics**
   - The design assumes slow external calls and compensates with parallel fetching and caching.
   - Typical latency is dominated by third-party APIs and the Claude call, not by local computation.
   - The frontend therefore waits on a single aggregated response rather than streaming partial results.

Main entry points: [`backend/data_sources.py`](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/data_sources.py) (Data fan-out), [`backend/main.py`](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py) (Orchestrator), [`backend/analyzer.py`](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/analyzer.py) (LLM adapter), [`index.html`](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/index.html) (Dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_root_dashboard["Dashboard<br/>static html<br/>[index.html]"]
  node_frontend_copy["UI copy<br/>static html<br/>[index.html]"]
  node_ui_logic["Client logic<br/>vanilla js"]
  node_api_client["API client<br/>browser fetch"]
end

subgraph group_backend["Backend"]
  node_api_app["API app<br/>FastAPI service<br/>[main.py]"]
  node_request_orchestrator["Orchestrator<br/>workflow<br/>[main.py]"]
  node_search_endpoint["Search API<br/>route<br/>[main.py]"]
  node_support_endpoints["Helper APIs<br/>route set<br/>[main.py]"]
  node_data_fanout["Data fan-out<br/>fetch layer<br/>[data_sources.py]"]
  node_analysis_adapter["LLM adapter<br/>prompting<br/>[analyzer.py]"]
end

subgraph group_external["External systems"]
  node_newsapi[("NewsAPI<br/>news source")]
  node_yfinance[("yFinance<br/>market data")]
  node_coingecko[("CoinGecko<br/>crypto data")]
  node_fred[("FRED<br/>macro data")]
  node_fear_greed[("Fear & Greed<br/>sentiment data")]
  node_claude{{"Claude<br/>llm"}}
  node_redis[("Redis<br/>cache")]
  node_supabase[("Supabase<br/>storage")]
end

node_root_dashboard -->|"runs"| node_ui_logic
node_frontend_copy -.->|"mirrors"| node_ui_logic
node_ui_logic -->|"uses"| node_api_client
node_api_client -->|"POST /api/search"| node_search_endpoint
node_api_client -->|"GET/POST helpers"| node_support_endpoints
node_search_endpoint -->|"delegates"| node_request_orchestrator
node_request_orchestrator -->|"collects data"| node_data_fanout
node_request_orchestrator -->|"synthesizes"| node_analysis_adapter
node_request_orchestrator -->|"caches"| node_redis
node_data_fanout -->|"queries"| node_newsapi
node_data_fanout -->|"queries"| node_yfinance
node_data_fanout -->|"queries"| node_coingecko
node_data_fanout -->|"queries"| node_fred
node_data_fanout -->|"queries"| node_fear_greed
node_analysis_adapter -->|"LLM call"| node_claude
node_support_endpoints -->|"writes"| node_supabase
node_request_orchestrator -.->|"served by"| node_api_app

click node_root_dashboard "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/index.html"
click node_frontend_copy "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/frontend/index.html"
click node_api_app "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py"
click node_request_orchestrator "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py"
click node_search_endpoint "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py"
click node_support_endpoints "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py"
click node_data_fanout "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/data_sources.py"
click node_analysis_adapter "https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/analyzer.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_root_dashboard,node_frontend_copy,node_ui_logic,node_api_client toneBlue
class node_api_app,node_request_orchestrator,node_search_endpoint,node_support_endpoints,node_data_fanout,node_analysis_adapter toneAmber
class node_newsapi,node_yfinance,node_coingecko,node_fred,node_fear_greed,node_claude,node_redis,node_supabase toneMint
```

## Components

### Frontend

Static browser dashboard and UI logic

- [Dashboard](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/index.html): static html · Single-page market intelligence UI entrypoint · `index.html`
- [UI copy](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/frontend/index.html): static html · Secondary dashboard copy in the frontend folder · `frontend/index.html`
- **Client logic**: vanilla js · Handles search, tab switching, charts, and rendering of structured analysis
- **API client**: browser fetch · Posts search requests and loads supporting market widgets

### Backend

Python API and orchestration layer

- [API app](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py): FastAPI service · Backend entrypoint serving search, prices, macro, and waitlist routes · `backend/main.py`
- [Orchestrator](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py): workflow · Coordinates request handling, data collection, caching, and response assembly · `backend/main.py`
- [Search API](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py): route · Main intelligence endpoint for keyword-driven analysis · `backend/main.py`
- [Helper APIs](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/main.py): route set · Prices, macro data, and waitlist write paths · `backend/main.py`
- [Data fan-out](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/data_sources.py): fetch layer · Parallel market-source collection with graceful degradation · `backend/data_sources.py`
- [LLM adapter](https://github.com/ishan-pngbeep/blue-peak-capital/blob/master/backend/analyzer.py): prompting · Builds analyst prompt and enforces strict JSON market-thesis output · `backend/analyzer.py`

### External systems

Downstream APIs, AI, cache, and storage

- **NewsAPI**: news source · News and article input for market context
- **yFinance**: market data · Equity and price-series input
- **CoinGecko**: crypto data · Cryptocurrency market input
- **FRED**: macro data · Macroeconomic series input
- **Fear & Greed**: sentiment data · Market sentiment input
- **Claude**: llm · Generates structured financial analysis from merged market data
- **Redis**: cache · Caches repeated synthesis and reduces latency
- **Supabase**: storage · Persists waitlist and user data

## Connections

- Dashboard → Client logic: runs · Browser loads and executes dashboard logic
- UI copy → Client logic: mirrors · Alternate static entry serving the same UI behavior
- Client logic → API client: uses · UI actions trigger API requests
- API client → Search API: POST /api/search · Primary keyword analysis request
- API client → Helper APIs: GET/POST helpers · Loads widget data and submits waitlist entries
- Search API → Orchestrator: delegates · Request handling is coordinated centrally
- Orchestrator → Data fan-out: collects data · Fetches live market context in parallel
- Orchestrator → LLM adapter: synthesizes · Sends merged payload for structured analysis
- Orchestrator → Redis: caches · Uses cache to reduce repeated synthesis latency
- Data fan-out → NewsAPI: queries · Retrieves news context
- Data fan-out → yFinance: queries · Retrieves price and ticker data
- Data fan-out → CoinGecko: queries · Retrieves crypto market data
- Data fan-out → FRED: queries · Retrieves macro series
- Data fan-out → Fear & Greed: queries · Retrieves sentiment index
- LLM adapter → Claude: LLM call · Requests analyst-style JSON synthesis
- Helper APIs → Supabase: writes · Stores waitlist submissions
- Orchestrator → API app: served by · Routes are exposed by the FastAPI application
