# hkustdial/deepear architecture

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

- Interactive diagram: https://gitdiagram.com/hkustdial/deepear
- Repository: https://github.com/hkustdial/deepear

## Overview

1. **What this repo is**
   DeepEar is a two-part system: a Python research/workflow engine that turns news into investment logic chains, and a React dashboard that visualizes runs, signals, charts, and comparisons.

2. **Primary execution entry points**
   The main offline/CLI workflow starts in `src/main_flow.py`. The web-facing runtime starts in `dashboard/server.py`, which serves the dashboard and exposes backend endpoints. There is also a skill-mode entry via `skills/deepear/scripts/server.py`.

3. **Core workflow shape**
   The central pipeline is intentionally staged: user intent is interpreted first, then hot topics are discovered, then financial logic is validated, then forecasting is applied, and finally a report is generated. This is the main data flow an architecture diagram should show.

4. **Agent layer**
   `src/agents/` contains the specialized reasoning stages: `intent_agent.py`, `trend_agent.py`, `fin_agent.py`, `forecast_agent.py`, and `report_agent.py`. These agents are the main semantic boundary in the system; they consume structured inputs from prior stages and emit progressively more structured analysis.

5. **Data acquisition and domain tooling**
   `src/tools/` and `src/utils/` provide the external-data and helper boundary around the agents. The repository explicitly supports news, stock, sentiment, and search tooling, plus hybrid retrieval (`hybrid_search.py`) and content extraction. These tools are the main bridge to live market/news sources.

6. **Forecasting subsystem**
   Prediction is separate from pure LLM reasoning. `src/utils/predictor/` and `src/utils/kronos_predictor.py` wrap a custom Kronos-based time-series model, with a prebuilt checkpoint in `src/exports/models/`. The forecast stage combines news-aware embeddings with time-series modeling rather than relying only on textual analysis.

7. **Structured schemas and signal quality**
   `src/schema/` defines the structured contract for analysis output, including ISQ templates and schema models. This matters because later stages depend on stable structured artifacts, not free-form text, to compare runs and render signals consistently.

8. **Report generation and output artifacts**
   The reporting layer turns analysis into final deliverables such as Markdown/HTML reports and chart-rich summaries. Supporting utilities like `md_to_html.py`, `visualizer.py`, and `scripts/inline_charts.py` indicate that report rendering is a first-class output pipeline, not just a final text dump.

9. **Dashboard subsystem**
   `dashboard/frontend/` is a separate Vite + React + TypeScript app. It includes run monitoring, comparison views, signal cards, history panels, hot-news panels, chart modals, and an ISQ radar, which suggests the UI is optimized for observing workflow state and comparing multiple runs over time.

10. **Dashboard backend and persistence**
   `dashboard/db.py`, `dashboard/models.py`, and `dashboard/integration.py` form the backend side of the UI. The dashboard likely persists users, runs, and related metadata in a local database, and `useWebSocket.ts` in the frontend shows that real-time status/log streaming is part of the design.

11. **State management and reliability**
   The workflow engine uses checkpointing and resumability via `src/utils/checkpointing.py`, with shared logging and JSON helpers in `src/utils/logging_setup.py` and `json_utils.py`. This means long research runs are treated as resumable stateful jobs rather than one-shot requests.

12. **Configuration boundaries**
   Runtime behavior is controlled by `.env` plus profile files in `config/` such as `default.json`, `macro.json`, `risk.json`, and `short_term.json`. That implies the same pipeline can be tuned for different research styles or risk regimes without changing code.

13. **Agent-skill packaging**
   `skills/deepear/` wraps the system as a reusable agent skill. In architecture terms, this is an alternate interface layer that exposes the same backend workflow to external agent runtimes through a small skill server.

14. **Automation and deployment**
   `.github/workflows/lite-cron.yml` and `vercel.json` show that the project has lightweight scheduled automation and a hosted dashboard deployment path. Those are supporting infrastructure, not core logic, but they matter if you are drawing the full system boundary.

Main entry points: [`src/main_flow.py`](https://github.com/hkustdial/deepear/blob/main/src/main_flow.py) (Main flow), [`src/tools/toolkits.py`](https://github.com/hkustdial/deepear/blob/main/src/tools/toolkits.py) (Toolkits), [`dashboard/server.py`](https://github.com/hkustdial/deepear/blob/main/dashboard/server.py) (Dashboard server), [`src/agents/intent_agent.py`](https://github.com/hkustdial/deepear/blob/main/src/agents/intent_agent.py) (Intent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core pipeline"]
  node_main_flow["Main flow<br/>workflow entry<br/>[main_flow.py]"]
  node_intent_agent["Intent<br/>agent stage<br/>[intent_agent.py]"]
  node_trend_agent["Trends<br/>agent stage<br/>[trend_agent.py]"]
  node_fin_agent["Finance<br/>agent stage<br/>[fin_agent.py]"]
  node_forecast_agent["Forecast<br/>agent stage<br/>[forecast_agent.py]"]
  node_report_agent["Report<br/>agent stage<br/>[report_agent.py]"]
end

subgraph group_data["Data and utilities"]
  node_toolkits["Toolkits<br/>tool boundary<br/>[toolkits.py]"]
  node_market_tools["Market tools<br/>data access<br/>[news_tools.py]"]
  node_hybrid_search["Hybrid search<br/>retrieval<br/>[hybrid_search.py]"]
  node_content_extractor["Extractor<br/>ingestion"]
  node_schema["Schemas<br/>structured contract<br/>[models.py]"]
  node_checkpointing["Checkpointing<br/>state mgmt<br/>[checkpointing.py]"]
  node_kronos_predictor["Kronos<br/>forecast model"]
  node_model_ckpt[("Model checkpoint<br/>weights artifact")]
end

subgraph group_dashboard["Dashboard system"]
  node_dashboard_server["Dashboard server<br/>web backend<br/>[server.py]"]
  node_dashboard_db[("Dashboard DB<br/>persistence<br/>[db.py]")]
  node_dashboard_frontend["React UI<br/>web app<br/>[App.tsx]"]
  node_websocket["Live updates<br/>realtime client<br/>[useWebSocket.ts]"]
end

subgraph group_integration["Packaging and ops"]
  node_skill_server["Skill server<br/>skill entry<br/>[server.py]"]
  node_cron["Lite cron<br/>automation<br/>[lite-cron.yml]"]
  node_vercel["Deploy config<br/>deployment<br/>[vercel.json]"]
end

node_main_flow -->|"starts with"| node_intent_agent
node_intent_agent -->|"feeds"| node_trend_agent
node_trend_agent -->|"feeds"| node_fin_agent
node_fin_agent -->|"feeds"| node_forecast_agent
node_forecast_agent -->|"feeds"| node_report_agent
node_main_flow -->|"uses"| node_toolkits
node_toolkits -->|"includes"| node_market_tools
node_toolkits -->|"includes"| node_hybrid_search
node_toolkits -->|"includes"| node_content_extractor
node_intent_agent -->|"writes"| node_schema
node_trend_agent -->|"writes"| node_schema
node_fin_agent -->|"writes"| node_schema
node_forecast_agent -->|"uses"| node_kronos_predictor
node_kronos_predictor -->|"loads"| node_model_ckpt
node_main_flow -->|"persists"| node_checkpointing
node_report_agent -->|"publishes"| node_dashboard_server
node_dashboard_server -->|"stores"| node_dashboard_db
node_dashboard_server -->|"serves"| node_dashboard_frontend
node_dashboard_frontend -->|"subscribes"| node_websocket
node_skill_server -->|"wraps"| node_main_flow
node_cron -->|"triggers"| node_main_flow
node_vercel -->|"deploys"| node_dashboard_server

click node_main_flow "https://github.com/hkustdial/deepear/blob/main/src/main_flow.py"
click node_intent_agent "https://github.com/hkustdial/deepear/blob/main/src/agents/intent_agent.py"
click node_trend_agent "https://github.com/hkustdial/deepear/blob/main/src/agents/trend_agent.py"
click node_fin_agent "https://github.com/hkustdial/deepear/blob/main/src/agents/fin_agent.py"
click node_forecast_agent "https://github.com/hkustdial/deepear/blob/main/src/agents/forecast_agent.py"
click node_report_agent "https://github.com/hkustdial/deepear/blob/main/src/agents/report_agent.py"
click node_toolkits "https://github.com/hkustdial/deepear/blob/main/src/tools/toolkits.py"
click node_market_tools "https://github.com/hkustdial/deepear/blob/main/src/utils/news_tools.py"
click node_hybrid_search "https://github.com/hkustdial/deepear/blob/main/src/utils/hybrid_search.py"
click node_content_extractor "https://github.com/hkustdial/deepear/blob/main/src/utils/content_extractor.py"
click node_schema "https://github.com/hkustdial/deepear/blob/main/src/schema/models.py"
click node_checkpointing "https://github.com/hkustdial/deepear/blob/main/src/utils/checkpointing.py"
click node_kronos_predictor "https://github.com/hkustdial/deepear/blob/main/src/utils/kronos_predictor.py"
click node_model_ckpt "https://github.com/hkustdial/deepear/blob/main/src/exports/models/kronos_news_v1_20260101_0015.pt"
click node_dashboard_server "https://github.com/hkustdial/deepear/blob/main/dashboard/server.py"
click node_dashboard_db "https://github.com/hkustdial/deepear/blob/main/dashboard/db.py"
click node_dashboard_frontend "https://github.com/hkustdial/deepear/blob/main/dashboard/frontend/src/App.tsx"
click node_websocket "https://github.com/hkustdial/deepear/blob/main/dashboard/frontend/src/useWebSocket.ts"
click node_skill_server "https://github.com/hkustdial/deepear/blob/main/skills/deepear/scripts/server.py"
click node_cron "https://github.com/hkustdial/deepear/blob/main/.github/workflows/lite-cron.yml"
click node_vercel "https://github.com/hkustdial/deepear/blob/main/vercel.json"

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_main_flow,node_intent_agent,node_trend_agent,node_fin_agent,node_forecast_agent,node_report_agent toneBlue
class node_toolkits,node_market_tools,node_hybrid_search,node_content_extractor,node_schema,node_checkpointing,node_kronos_predictor,node_model_ckpt toneAmber
class node_dashboard_server,node_dashboard_db,node_dashboard_frontend,node_websocket toneMint
class node_skill_server,node_cron,node_vercel toneRose
```

## Components

### Core pipeline

Offline workflow engine and agent stages that turn news into structured investment analysis.

- [Main flow](https://github.com/hkustdial/deepear/blob/main/src/main_flow.py): workflow entry · CLI/offline entry point that orchestrates the staged research pipeline. · `src/main_flow.py`
- [Intent](https://github.com/hkustdial/deepear/blob/main/src/agents/intent_agent.py): agent stage · Interprets user intent and initializes the analysis path. · `src/agents/intent_agent.py`
- [Trends](https://github.com/hkustdial/deepear/blob/main/src/agents/trend_agent.py): agent stage · Discovers hot topics and market-relevant trend signals. · `src/agents/trend_agent.py`
- [Finance](https://github.com/hkustdial/deepear/blob/main/src/agents/fin_agent.py): agent stage · Validates financial logic and grounds the analysis in market context. · `src/agents/fin_agent.py`
- [Forecast](https://github.com/hkustdial/deepear/blob/main/src/agents/forecast_agent.py): agent stage · Combines structured signals with time-series prediction. · `src/agents/forecast_agent.py`
- [Report](https://github.com/hkustdial/deepear/blob/main/src/agents/report_agent.py): agent stage · Turns analysis into final narrative and structured deliverables. · `src/agents/report_agent.py`

### Data and utilities

External-data access, extraction, checkpointing, schema, and forecasting support.

- [Toolkits](https://github.com/hkustdial/deepear/blob/main/src/tools/toolkits.py): tool boundary · Central registry or assembly point for agent-facing tools. · `src/tools/toolkits.py`
- [Market tools](https://github.com/hkustdial/deepear/blob/main/src/utils/news_tools.py): data access · News, stock, sentiment, and search interfaces that connect the pipeline to live sources. · `src/utils/news_tools.py`
- [Hybrid search](https://github.com/hkustdial/deepear/blob/main/src/utils/hybrid_search.py): retrieval · Blends retrieval across sources for relevant evidence gathering. · `src/utils/hybrid_search.py`
- [Extractor](https://github.com/hkustdial/deepear/blob/main/src/utils/content_extractor.py): ingestion · Normalizes and extracts usable content from external sources. · `src/utils/content_extractor.py`
- [Schemas](https://github.com/hkustdial/deepear/blob/main/src/schema/models.py): structured contract · Defines ISQ templates and model contracts for stable analysis artifacts. · `src/schema/models.py`
- [Checkpointing](https://github.com/hkustdial/deepear/blob/main/src/utils/checkpointing.py): state mgmt · Supports resumable long-running runs and persisted workflow state. · `src/utils/checkpointing.py`
- [Kronos](https://github.com/hkustdial/deepear/blob/main/src/utils/kronos_predictor.py): forecast model · Wraps the custom time-series predictor used in the forecast stage. · `src/utils/kronos_predictor.py`
- [Model checkpoint](https://github.com/hkustdial/deepear/blob/main/src/exports/models/kronos_news_v1_20260101_0015.pt): weights artifact · Prebuilt Kronos model weights used by the predictor stack. · `src/exports/models/kronos_news_v1_20260101_0015.pt`

### Dashboard system

Web UI, backend, and persistence for run monitoring and comparison.

- [Dashboard server](https://github.com/hkustdial/deepear/blob/main/dashboard/server.py): web backend · Serves the dashboard and exposes backend endpoints. · `dashboard/server.py`
- [Dashboard DB](https://github.com/hkustdial/deepear/blob/main/dashboard/db.py): persistence · Local database layer for users, runs, and related metadata. · `dashboard/db.py`
- [React UI](https://github.com/hkustdial/deepear/blob/main/dashboard/frontend/src/App.tsx): web app · Vite + React + TypeScript frontend for monitoring, comparison, and reports. · `dashboard/frontend/src/App.tsx`
- [Live updates](https://github.com/hkustdial/deepear/blob/main/dashboard/frontend/src/useWebSocket.ts): realtime client · WebSocket-driven run status and log streaming in the frontend. · `dashboard/frontend/src/useWebSocket.ts`

### Packaging and ops

Skill wrapper, scheduled automation, and deployment glue.

- [Skill server](https://github.com/hkustdial/deepear/blob/main/skills/deepear/scripts/server.py): skill entry · Alternate entry point that exposes the workflow as a reusable agent skill. · `skills/deepear/scripts/server.py`
- [Lite cron](https://github.com/hkustdial/deepear/blob/main/.github/workflows/lite-cron.yml): automation · Scheduled workflow automation for lightweight recurring runs. · `.github/workflows/lite-cron.yml`
- [Deploy config](https://github.com/hkustdial/deepear/blob/main/vercel.json): deployment · Hosted deployment configuration for the dashboard runtime. · `vercel.json`

## Connections

- Main flow → Intent: starts with · Main workflow begins by interpreting intent.
- Intent → Trends: feeds · Intent output seeds topic discovery.
- Trends → Finance: feeds · Trend evidence is validated financially.
- Finance → Forecast: feeds · Structured financial signals inform forecasting.
- Forecast → Report: feeds · Prediction outputs are turned into the report.
- Main flow → Toolkits: uses · Workflow stages are assembled around shared tools.
- Toolkits → Market tools: includes · Tool assembly exposes market and news access.
- Toolkits → Hybrid search: includes · Retrieval support is part of the shared tool boundary.
- Toolkits → Extractor: includes · External content is extracted and normalized through tooling.
- Intent → Schemas: writes · Stages emit structured contracts rather than free text alone.
- Trends → Schemas: writes · Trend analysis is serialized into stable artifacts.
- Finance → Schemas: writes · Financial validation produces structured output.
- Forecast → Kronos: uses · Forecast stage invokes the time-series predictor.
- Kronos → Model checkpoint: loads · Predictor depends on the packaged model weights.
- Main flow → Checkpointing: persists · Long runs can be resumed from checkpoints.
- Report → Dashboard server: publishes · Final analysis is exposed to the web dashboard.
- Dashboard server → Dashboard DB: stores · Backend persists run and user metadata.
- Dashboard server → React UI: serves · Backend pairs with the interactive UI.
- React UI → Live updates: subscribes · UI receives live run progress and logs.
- Skill server → Main flow: wraps · Skill mode reuses the core workflow.
- Lite cron → Main flow: triggers · Scheduled automation invokes the workflow.
- Deploy config → Dashboard server: deploys · Deployment configuration targets the dashboard runtime.
