# takumashin/pa-agent architecture

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

- Interactive diagram: https://gitdiagram.com/takumashin/pa-agent
- Repository: https://github.com/takumashin/pa-agent

## Overview

PA Agent is a price-action analysis application with Web and desktop interfaces. The main workflow is to select a market and timeframe, obtain candle data, submit an analysis, and view the resulting diagnosis, decision, and chart annotations. Its documented capabilities also include chat commands for quick analysis and bar-by-bar tracking, editable decision trees, and extensible skills. The graph emphasizes the Web entry point and shared analysis components; some subsystem links rely on README descriptions or SOURCE INDEX references rather than inspected implementation excerpts.

Main entry points: [`pa_agent/orchestrator/two_stage.py`](https://github.com/takumashin/pa-agent/blob/main/pa_agent/orchestrator/two_stage.py) (Two-stage analysis), [`pa_agent/web/app.py`](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/app.py) (FastAPI app), [`pa_agent/web/routes/agent_chat.py`](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/agent_chat.py) (Agent chat API), [`pa_agent/app_context.py`](https://github.com/takumashin/pa-agent/blob/main/pa_agent/app_context.py) (App context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_web_app["FastAPI app<br/>[app.py]"]
  node_agent_chat["Agent chat API<br/>[agent_chat.py]"]
  node_analysis_api["Analysis API<br/>[analysis.py]"]
  node_chart_api["Chart API<br/>[chart.py]"]
  node_tree_api["Decision tree API<br/>[decision_tree.py]"]
  node_sessions[("Conversation sessions<br/>[session_manager.py]")]
end

subgraph group_analysis["Analysis and AI"]
  node_app_context["App context<br/>[app_context.py]"]
  node_orchestrator["Two-stage analysis<br/>[two_stage.py]"]
  node_prompt["Prompt assembly"]
  node_ai_client["AI client<br/>[deepseek_client.py]"]
  node_validator["JSON validation<br/>[json_validator.py]"]
  node_tree_engine["Decision tree engine<br/>[decision_tree.py]"]
  node_router["Strategy routing<br/>[router.py]"]
  node_skills["Extensible skills<br/>[registry.py]"]
  node_agent_tools["Charting AI tools<br/>[agent_tools.py]"]
  node_quick_chat["Free chat<br/>[free_chat.py]"]
end

subgraph group_market["Market data"]
  node_data_source["Market data sources<br/>[base.py]"]
  node_kline_buffer["Candle buffer<br/>[kline_buffer.py]"]
  node_candle_frame["Candle frames<br/>[base.py]"]
  node_chart_view["Live chart<br/>[chart_widget.py]"]
end

subgraph group_domain["Trading domain"]
  node_records[("Analysis records<br/>[pending_writer.py]")]
  node_experience[("Experience library")]
  node_settings[("Settings and secrets<br/>[settings.py]")]
  node_tree_projects[("Decision tree projects<br/>[project.py]")]
end

subgraph group_desktop["Desktop interface"]
  node_desktop["Desktop workbench<br/>[main_window.py]"]
end

node_trader(("Trader"))
node_browser(("Web client"))
node_external_ai{{"DeepSeek-compatible API"}}
node_market_provider{{"Market data provider"}}

node_trader -->|"uses"| node_browser
node_browser -->|"requests"| node_web_app
node_web_app -->|"bootstraps"| node_app_context
node_web_app -->|"registers"| node_agent_chat
node_web_app -->|"registers"| node_analysis_api
node_web_app -->|"registers"| node_chart_api
node_web_app -->|"registers"| node_tree_api
node_agent_chat -->|"uses tools"| node_agent_tools
node_agent_chat -->|"loads skills"| node_skills
node_agent_chat -.->|"persists chats"| node_sessions
node_analysis_api -.->|"starts analysis"| node_orchestrator
node_app_context -->|"connects source"| node_data_source
node_app_context -->|"creates buffer"| node_kline_buffer
node_app_context -.->|"configures client"| node_ai_client
node_data_source -.->|"fetches candles"| node_market_provider
node_kline_buffer -->|"holds bars"| node_candle_frame
node_orchestrator -->|"assembles prompts"| node_prompt
node_orchestrator -->|"requests analysis"| node_ai_client
node_ai_client -->|"sends prompts"| node_external_ai
node_orchestrator -->|"validates output"| node_validator
node_orchestrator -->|"routes strategies"| node_router
node_orchestrator -->|"uses decision tree"| node_tree_engine
node_orchestrator -->|"loads experience"| node_experience
node_orchestrator -->|"writes results"| node_records
node_prompt -->|"formats candles"| node_candle_frame
node_agent_tools -.->|"draws annotations"| node_chart_view
node_tree_api -.->|"edits projects"| node_tree_projects
node_web_app -.->|"loads configuration"| node_settings
node_trader -->|"uses"| node_desktop
node_desktop -->|"runs analysis"| node_orchestrator
node_desktop -.->|"shows chart"| node_chart_view
node_trader -->|"requests chat"| node_quick_chat
node_quick_chat -->|"requests response"| node_ai_client
node_quick_chat -->|"builds context"| node_prompt

click node_web_app "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/app.py"
click node_agent_chat "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/agent_chat.py"
click node_analysis_api "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/analysis.py"
click node_chart_api "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/chart.py"
click node_tree_api "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/decision_tree.py"
click node_sessions "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/session_manager.py"
click node_app_context "https://github.com/takumashin/pa-agent/blob/main/pa_agent/app_context.py"
click node_orchestrator "https://github.com/takumashin/pa-agent/blob/main/pa_agent/orchestrator/two_stage.py"
click node_prompt "https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/prompt_assembler.py"
click node_ai_client "https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/deepseek_client.py"
click node_validator "https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/json_validator.py"
click node_tree_engine "https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/decision_tree.py"
click node_router "https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/router.py"
click node_skills "https://github.com/takumashin/pa-agent/blob/main/pa_agent/skills/registry.py"
click node_agent_tools "https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/agent_tools.py"
click node_data_source "https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/base.py"
click node_kline_buffer "https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/kline_buffer.py"
click node_candle_frame "https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/base.py"
click node_chart_view "https://github.com/takumashin/pa-agent/blob/main/pa_agent/gui/chart_widget.py"
click node_records "https://github.com/takumashin/pa-agent/blob/main/pa_agent/records/pending_writer.py"
click node_experience "https://github.com/takumashin/pa-agent/blob/main/pa_agent/records/experience_reader.py"
click node_settings "https://github.com/takumashin/pa-agent/blob/main/pa_agent/config/settings.py"
click node_tree_projects "https://github.com/takumashin/pa-agent/blob/main/pa_agent/dtree/project.py"
click node_desktop "https://github.com/takumashin/pa-agent/blob/main/pa_agent/gui/main_window.py"
click node_quick_chat "https://github.com/takumashin/pa-agent/blob/main/pa_agent/orchestrator/free_chat.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_web_app,node_agent_chat,node_analysis_api,node_chart_api,node_tree_api,node_sessions,node_browser toneBlue
class node_app_context,node_orchestrator,node_prompt,node_ai_client,node_validator,node_tree_engine,node_router,node_skills,node_agent_tools,node_quick_chat toneAmber
class node_data_source,node_kline_buffer,node_candle_frame,node_chart_view,node_external_ai toneMint
class node_records,node_experience,node_settings,node_tree_projects toneRose
class node_desktop,node_trader,node_market_provider toneIndigo
```

## Components

### Web application

- [FastAPI app](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/app.py): `pa_agent/web/app.py`
- [Agent chat API](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/agent_chat.py): `pa_agent/web/routes/agent_chat.py`
- [Analysis API](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/analysis.py): `pa_agent/web/routes/analysis.py`
- [Chart API](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/chart.py): `pa_agent/web/routes/chart.py`
- [Decision tree API](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/routes/decision_tree.py): `pa_agent/web/routes/decision_tree.py`
- [Conversation sessions](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/session_manager.py): `pa_agent/web/session_manager.py`

### Analysis and AI

- [App context](https://github.com/takumashin/pa-agent/blob/main/pa_agent/app_context.py): `pa_agent/app_context.py`
- [Two-stage analysis](https://github.com/takumashin/pa-agent/blob/main/pa_agent/orchestrator/two_stage.py): `pa_agent/orchestrator/two_stage.py`
- [Prompt assembly](https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/prompt_assembler.py): `pa_agent/ai/prompt_assembler.py`
- [AI client](https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/deepseek_client.py): `pa_agent/ai/deepseek_client.py`
- [JSON validation](https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/json_validator.py): `pa_agent/ai/json_validator.py`
- [Decision tree engine](https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/decision_tree.py): `pa_agent/ai/decision_tree.py`
- [Strategy routing](https://github.com/takumashin/pa-agent/blob/main/pa_agent/ai/router.py): `pa_agent/ai/router.py`
- [Extensible skills](https://github.com/takumashin/pa-agent/blob/main/pa_agent/skills/registry.py): `pa_agent/skills/registry.py`
- [Charting AI tools](https://github.com/takumashin/pa-agent/blob/main/pa_agent/web/agent_tools.py): `pa_agent/web/agent_tools.py`
- [Free chat](https://github.com/takumashin/pa-agent/blob/main/pa_agent/orchestrator/free_chat.py): `pa_agent/orchestrator/free_chat.py`

### Market data

- [Market data sources](https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/base.py): `pa_agent/data/base.py`
- [Candle buffer](https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/kline_buffer.py): `pa_agent/data/kline_buffer.py`
- [Candle frames](https://github.com/takumashin/pa-agent/blob/main/pa_agent/data/base.py): `pa_agent/data/base.py`
- [Live chart](https://github.com/takumashin/pa-agent/blob/main/pa_agent/gui/chart_widget.py): `pa_agent/gui/chart_widget.py`

### Trading domain

- [Analysis records](https://github.com/takumashin/pa-agent/blob/main/pa_agent/records/pending_writer.py): `pa_agent/records/pending_writer.py`
- [Experience library](https://github.com/takumashin/pa-agent/blob/main/pa_agent/records/experience_reader.py): `pa_agent/records/experience_reader.py`
- [Settings and secrets](https://github.com/takumashin/pa-agent/blob/main/pa_agent/config/settings.py): `pa_agent/config/settings.py`
- [Decision tree projects](https://github.com/takumashin/pa-agent/blob/main/pa_agent/dtree/project.py): `pa_agent/dtree/project.py`

### Desktop interface

- [Desktop workbench](https://github.com/takumashin/pa-agent/blob/main/pa_agent/gui/main_window.py): `pa_agent/gui/main_window.py`

### Other components

- **Trader**
- **Web client**
- **DeepSeek-compatible API**
- **Market data provider**

## Connections

- Trader → Web client: uses
- Web client → FastAPI app: requests (evidence: `pa_agent/web/app.py`)
- FastAPI app → App context: bootstraps (evidence: `pa_agent/web/app.py`)
- FastAPI app → Agent chat API: registers (evidence: `pa_agent/web/app.py`)
- FastAPI app → Analysis API: registers (evidence: `pa_agent/web/app.py`)
- FastAPI app → Chart API: registers (evidence: `pa_agent/web/app.py`)
- FastAPI app → Decision tree API: registers (evidence: `pa_agent/web/app.py`)
- Agent chat API → Charting AI tools: uses tools (evidence: `pa_agent/web/routes/agent_chat.py`)
- Agent chat API → Extensible skills: loads skills (evidence: `pa_agent/web/routes/agent_chat.py`)
- Agent chat API → Conversation sessions: persists chats
- Analysis API → Two-stage analysis: starts analysis
- App context → Market data sources: connects source (evidence: `pa_agent/app_context.py`)
- App context → Candle buffer: creates buffer (evidence: `pa_agent/app_context.py`)
- App context → AI client: configures client (evidence: `pa_agent/app_context.py`)
- Market data sources → Market data provider: fetches candles
- Candle buffer → Candle frames: holds bars (evidence: `pa_agent/data/kline_buffer.py`)
- Two-stage analysis → Prompt assembly: assembles prompts (evidence: `pa_agent/orchestrator/two_stage.py`)
- Two-stage analysis → AI client: requests analysis (evidence: `pa_agent/orchestrator/two_stage.py`)
- AI client → DeepSeek-compatible API: sends prompts (evidence: `pa_agent/ai/deepseek_client.py`)
- Two-stage analysis → JSON validation: validates output (evidence: `pa_agent/orchestrator/two_stage.py`)
- Two-stage analysis → Strategy routing: routes strategies (evidence: `pa_agent/orchestrator/two_stage.py`)
- Two-stage analysis → Decision tree engine: uses decision tree (evidence: `pa_agent/orchestrator/two_stage.py`)
- Two-stage analysis → Experience library: loads experience (evidence: `pa_agent/orchestrator/two_stage.py`)
- Two-stage analysis → Analysis records: writes results (evidence: `pa_agent/orchestrator/two_stage.py`)
- Prompt assembly → Candle frames: formats candles (evidence: `pa_agent/ai/prompt_assembler.py`)
- Charting AI tools → Live chart: draws annotations
- Decision tree API → Decision tree projects: edits projects
- FastAPI app → Settings and secrets: loads configuration
- Trader → Desktop workbench: uses
- Desktop workbench → Two-stage analysis: runs analysis (evidence: `pa_agent/gui/main_window.py`)
- Desktop workbench → Live chart: shows chart (evidence: `pa_agent/gui/main_window.py`)
- Trader → Free chat: requests chat
- Free chat → AI client: requests response (evidence: `pa_agent/orchestrator/free_chat.py`)
- Free chat → Prompt assembly: builds context (evidence: `pa_agent/orchestrator/free_chat.py`)
