# rosemarycox5334-debug/pa_agent architecture

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

- Interactive diagram: https://gitdiagram.com/rosemarycox5334-debug/pa_agent
- Repository: https://github.com/rosemarycox5334-debug/pa_agent

## Overview

PA Agent is a desktop Price Action analysis assistant: traders select a market feed and request analysis; the app fetches bars, builds a snapshot, runs a two-stage market diagnosis and trade-decision workflow, then presents the result. The graph also shows documented incremental tracking, interactive decision visualization, follow-up chat, experience lookup, and record persistence. Main wiring and several workers are sampled; broader stage and capability links follow the README and module layout, so uncertain internal call details are omitted.

Main entry points: [`pa_agent/orchestrator/two_stage.py`](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/two_stage.py) (Two-stage analysis), [`pa_agent/gui/main_window.py`](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/main_window.py) (Main window), [`pa_agent/data/factory.py`](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/data/factory.py) (Data-source factory), [`pa_agent/ai/client_factory.py`](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/client_factory.py) (AI client routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop app"]
  node_entry["Application entry<br/>[main.py]"]
  node_context["App wiring<br/>[app_context.py]"]
  node_window["Main window<br/>[main_window.py]"]
end

subgraph group_market["Market data"]
  node_fetch["Snapshot fetch<br/>[snapshot_worker.py]"]
  node_sources["Data-source factory<br/>[factory.py]"]
  node_refresh["Data refresh loop<br/>[refresh_loop.py]"]
end

subgraph group_analysis["AI analysis"]
  node_prep["Snapshot preparation"]
  node_twostage["Two-stage analysis<br/>[two_stage.py]"]
  node_prompts["Prompt assembly"]
  node_routing["Strategy routing<br/>[router.py]"]
  node_ai["AI client routing<br/>[client_factory.py]"]
  node_validation["Response validation<br/>[json_validator.py]"]
  node_retry["Validation retry"]
  node_chat["Follow-up chat<br/>[free_chat.py]"]
end

subgraph group_results["Results and history"]
  node_display["Analysis views<br/>[decision_panel.py]"]
  node_decisiontree["Decision tree view"]
  node_future["Future trend view"]
  node_history[("Analysis history")]
  node_pending[("Pending records<br/>[pending_writer.py]")]
  node_experience["Experience lookup"]
end

subgraph group_services["External services"]
  node_marketfeeds{{"Market data providers"}}
  node_models{{"LLM providers"}}
end

node_trader(("Trader"))

node_trader -->|"launches"| node_entry
node_entry -->|"bootstraps"| node_context
node_entry -->|"opens"| node_window
node_context -->|"creates source"| node_sources
node_context -->|"creates client"| node_ai
node_window -->|"requests bars"| node_fetch
node_fetch -->|"fetches snapshot"| node_sources
node_sources -->|"retrieves bars"| node_marketfeeds
node_fetch -->|"returns bars"| node_prep
node_prep -->|"looks up base"| node_history
node_window -->|"starts analysis"| node_twostage
node_twostage -->|"assembles prompts"| node_prompts
node_twostage -->|"routes strategy"| node_routing
node_twostage -->|"requests analysis"| node_ai
node_ai -->|"streams completion"| node_models
node_twostage -->|"validates response"| node_validation
node_twostage -->|"retries failures"| node_retry
node_twostage -->|"loads examples"| node_experience
node_twostage -->|"writes analysis"| node_pending
node_twostage -->|"records outcome"| node_history
node_twostage -->|"returns analysis"| node_display
node_display -->|"shows decision flow"| node_decisiontree
node_display -->|"shows forecast"| node_future
node_window -->|"starts follow-up"| node_chat
node_chat -->|"requests reply"| node_ai
node_chat -->|"persists conversation"| node_history
node_refresh -->|"refreshes data"| node_sources

click node_entry "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/main.py"
click node_context "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/app_context.py"
click node_window "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/main_window.py"
click node_fetch "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/snapshot_worker.py"
click node_sources "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/data/factory.py"
click node_prep "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/analysis_prep_worker.py"
click node_twostage "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/two_stage.py"
click node_prompts "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/prompt_assembler.py"
click node_routing "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/router.py"
click node_ai "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/client_factory.py"
click node_validation "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/json_validator.py"
click node_retry "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/validation_retry.py"
click node_display "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/decision_panel.py"
click node_decisiontree "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/decision_tree_panel.py"
click node_future "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/future_trend_panel.py"
click node_chat "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/free_chat.py"
click node_history "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/analysis_history.py"
click node_pending "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/pending_writer.py"
click node_experience "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/experience_reader.py"
click node_refresh "https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/data/refresh_loop.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_entry,node_context,node_window toneBlue
class node_fetch,node_sources,node_refresh toneAmber
class node_prep,node_twostage,node_prompts,node_routing,node_ai,node_validation,node_retry,node_chat toneMint
class node_display,node_decisiontree,node_future,node_history,node_pending,node_experience toneRose
class node_marketfeeds,node_models,node_trader toneIndigo
```

## Components

### Desktop app

- [Application entry](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/main.py): `pa_agent/main.py`
- [App wiring](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/app_context.py): `pa_agent/app_context.py`
- [Main window](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/main_window.py): `pa_agent/gui/main_window.py`

### Market data

- [Snapshot fetch](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/snapshot_worker.py): `pa_agent/gui/snapshot_worker.py`
- [Data-source factory](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/data/factory.py): `pa_agent/data/factory.py`
- [Data refresh loop](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/data/refresh_loop.py): `pa_agent/data/refresh_loop.py`

### AI analysis

- [Snapshot preparation](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/analysis_prep_worker.py): `pa_agent/gui/analysis_prep_worker.py`
- [Two-stage analysis](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/two_stage.py): `pa_agent/orchestrator/two_stage.py`
- [Prompt assembly](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/prompt_assembler.py): `pa_agent/ai/prompt_assembler.py`
- [Strategy routing](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/router.py): `pa_agent/ai/router.py`
- [AI client routing](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/client_factory.py): `pa_agent/ai/client_factory.py`
- [Response validation](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/ai/json_validator.py): `pa_agent/ai/json_validator.py`
- [Validation retry](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/validation_retry.py): `pa_agent/orchestrator/validation_retry.py`
- [Follow-up chat](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/orchestrator/free_chat.py): `pa_agent/orchestrator/free_chat.py`

### Results and history

- [Analysis views](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/decision_panel.py): `pa_agent/gui/decision_panel.py`
- [Decision tree view](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/decision_tree_panel.py): `pa_agent/gui/decision_tree_panel.py`
- [Future trend view](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/gui/future_trend_panel.py): `pa_agent/gui/future_trend_panel.py`
- [Analysis history](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/analysis_history.py): `pa_agent/records/analysis_history.py`
- [Pending records](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/pending_writer.py): `pa_agent/records/pending_writer.py`
- [Experience lookup](https://github.com/rosemarycox5334-debug/pa_agent/blob/main/pa_agent/records/experience_reader.py): `pa_agent/records/experience_reader.py`

### External services

- **Market data providers**
- **LLM providers**

### Other components

- **Trader**

## Connections

- Trader → Application entry: launches
- Application entry → App wiring: bootstraps
- Application entry → Main window: opens
- App wiring → Data-source factory: creates source
- App wiring → AI client routing: creates client
- Main window → Snapshot fetch: requests bars
- Snapshot fetch → Data-source factory: fetches snapshot
- Data-source factory → Market data providers: retrieves bars
- Snapshot fetch → Snapshot preparation: returns bars
- Snapshot preparation → Analysis history: looks up base
- Main window → Two-stage analysis: starts analysis
- Two-stage analysis → Prompt assembly: assembles prompts
- Two-stage analysis → Strategy routing: routes strategy
- Two-stage analysis → AI client routing: requests analysis
- AI client routing → LLM providers: streams completion
- Two-stage analysis → Response validation: validates response
- Two-stage analysis → Validation retry: retries failures
- Two-stage analysis → Experience lookup: loads examples
- Two-stage analysis → Pending records: writes analysis
- Two-stage analysis → Analysis history: records outcome
- Two-stage analysis → Analysis views: returns analysis
- Analysis views → Decision tree view: shows decision flow
- Analysis views → Future trend view: shows forecast
- Main window → Follow-up chat: starts follow-up
- Follow-up chat → AI client routing: requests reply
- Follow-up chat → Analysis history: persists conversation
- Data refresh loop → Data-source factory: refreshes data
