# mars-tw/anti-gambling-trader-tw architecture

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

- Interactive diagram: https://gitdiagram.com/mars-tw/anti-gambling-trader-tw
- Repository: https://github.com/mars-tw/anti-gambling-trader-tw

## Overview

反詐投資王 is a local-first trading-record analyzer and anti-scam toolkit, with a secondary strategy/scaffold generator for automated trading projects. The primary workflow is: a trader supplies records or screenshot/chat evidence; the CLI routes it through parsing and normalization; statistical and domain analyses produce a conservative verdict and report. Other documented branches cover scam-text and guru-claim checks, return forensics, risk simulation, and strategy scaffolding. Edges are grounded in the README or SOURCE INDEX references; unsampled implementation details are not inferred.

Main entry points: [`core/cli.py`](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/cli.py) (Command interface), [`core/analyzer.py`](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/analyzer.py) (Analysis coordinator), [`core/metrics/performance.py`](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/metrics/performance.py) (Performance metrics), [`core/ingest/loader.py`](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/ingest/loader.py) (Record loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entry"]
  node_cli["Command interface<br/>[cli.py]"]
  node_screenshots["Screenshot review<br/>[screenshot.py]"]
end

subgraph group_analysis["Trade analysis"]
  node_loader["Record loader<br/>[loader.py]"]
  node_trade_model["Trade records<br/>[models.py]"]
  node_market_rules["Market rules<br/>[markets.py]"]
  node_analyzer["Analysis coordinator<br/>[analyzer.py]"]
  node_performance["Performance metrics<br/>[performance.py]"]
  node_statistics["Significance tests<br/>[statistics.py]"]
  node_verdict["Verdict engine<br/>[judge.py]"]
  node_oos["Out-of-sample check<br/>[validate.py]"]
  node_tag_review["Strategy breakdown<br/>[per_tag.py]"]
  node_onboarding["Experience stage<br/>[onboarding.py]"]
  node_report["HTML report<br/>[report_html.py]"]
end

subgraph group_trust["Scam checks"]
  node_chat_scan["Chat scanner<br/>[text_scanner.py]"]
  node_guru["Guru claim check<br/>[guru_claim.py]"]
  node_forensics["Return forensics<br/>[analyzer.py]"]
  node_survivorship["Survivorship model<br/>[survivorship.py]"]
end

subgraph group_insights["Additional insights"]
  node_trend["Time trends<br/>[timeline.py]"]
  node_simulation["Risk simulation<br/>[simulate.py]"]
end

subgraph group_automation["Trading projects"]
  node_skeleton["Strategy skeleton<br/>[skeleton.py]"]
  node_scaffold["Project generator<br/>[generator.py]"]
  node_broker_catalog["Broker templates<br/>[registry.py]"]
  node_chart_catalog["Chart options<br/>[registry.py]"]
end

node_trader(("Trader"))

node_trader -->|"runs commands"| node_cli
node_cli -->|"loads records"| node_loader
node_cli -->|"routes screenshots"| node_screenshots
node_cli -->|"routes chat scans"| node_chat_scan
node_loader -->|"normalizes trades"| node_trade_model
node_loader -->|"infers markets"| node_market_rules
node_cli -->|"starts analysis"| node_analyzer
node_analyzer -->|"loads input"| node_loader
node_analyzer -->|"computes metrics"| node_performance
node_analyzer -->|"requests judgment"| node_verdict
node_analyzer -->|"validates holdout"| node_oos
node_analyzer -->|"breaks down tags"| node_tag_review
node_analyzer -->|"builds strategy"| node_skeleton
node_performance -->|"reads trades"| node_trade_model
node_performance -->|"uses market data"| node_market_rules
node_verdict -->|"uses metrics"| node_performance
node_verdict -->|"tests expectancy"| node_statistics
node_oos -->|"summarizes segments"| node_performance
node_oos -->|"tests segments"| node_statistics
node_cli -->|"checks stage"| node_onboarding
node_cli -->|"outputs report"| node_report
node_cli -->|"checks claim"| node_guru
node_guru -->|"uses probability tests"| node_statistics
node_guru -->|"models chance"| node_survivorship
node_cli -->|"runs forensics"| node_forensics
node_cli -->|"checks survivorship"| node_survivorship
node_cli -->|"requests timeline"| node_trend
node_cli -->|"runs simulation"| node_simulation
node_cli -->|"generates project"| node_scaffold
node_scaffold -->|"selects broker"| node_broker_catalog
node_scaffold -->|"selects chart"| node_chart_catalog
node_cli -->|"lists brokers"| node_broker_catalog
node_cli -->|"lists charts"| node_chart_catalog

click node_cli "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/cli.py"
click node_loader "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/ingest/loader.py"
click node_screenshots "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/ingest/screenshot.py"
click node_chat_scan "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/antiscam/text_scanner.py"
click node_trade_model "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/models.py"
click node_market_rules "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/markets.py"
click node_analyzer "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/analyzer.py"
click node_performance "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/metrics/performance.py"
click node_statistics "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/verdict/statistics.py"
click node_verdict "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/verdict/judge.py"
click node_oos "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/backtest/validate.py"
click node_tag_review "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/strategy/per_tag.py"
click node_onboarding "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/onboarding.py"
click node_report "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/report_html.py"
click node_guru "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/antiscam/guru_claim.py"
click node_forensics "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/forensics/analyzer.py"
click node_survivorship "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/survivorship.py"
click node_trend "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/trend/timeline.py"
click node_simulation "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/montecarlo/simulate.py"
click node_skeleton "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/strategy/skeleton.py"
click node_scaffold "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/scaffold/generator.py"
click node_broker_catalog "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/broker/registry.py"
click node_chart_catalog "https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/charts/registry.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_cli,node_screenshots toneBlue
class node_loader,node_trade_model,node_market_rules,node_analyzer,node_performance,node_statistics,node_verdict,node_oos,node_tag_review,node_onboarding,node_report toneAmber
class node_chat_scan,node_guru,node_forensics,node_survivorship toneMint
class node_trend,node_simulation toneRose
class node_skeleton,node_scaffold,node_broker_catalog,node_chart_catalog,node_trader toneIndigo
```

## Components

### User entry

- [Command interface](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/cli.py): `core/cli.py`
- [Screenshot review](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/ingest/screenshot.py): `core/ingest/screenshot.py`

### Trade analysis

- [Record loader](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/ingest/loader.py): `core/ingest/loader.py`
- [Trade records](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/models.py): `core/models.py`
- [Market rules](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/markets.py): `core/markets.py`
- [Analysis coordinator](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/analyzer.py): `core/analyzer.py`
- [Performance metrics](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/metrics/performance.py): `core/metrics/performance.py`
- [Significance tests](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/verdict/statistics.py): `core/verdict/statistics.py`
- [Verdict engine](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/verdict/judge.py): `core/verdict/judge.py`
- [Out-of-sample check](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/backtest/validate.py): `core/backtest/validate.py`
- [Strategy breakdown](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/strategy/per_tag.py): `core/strategy/per_tag.py`
- [Experience stage](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/onboarding.py): `core/onboarding.py`
- [HTML report](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/report_html.py): `core/report_html.py`

### Scam checks

- [Chat scanner](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/antiscam/text_scanner.py): `core/antiscam/text_scanner.py`
- [Guru claim check](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/antiscam/guru_claim.py): `core/antiscam/guru_claim.py`
- [Return forensics](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/forensics/analyzer.py): `core/forensics/analyzer.py`
- [Survivorship model](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/survivorship.py): `core/survivorship.py`

### Additional insights

- [Time trends](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/trend/timeline.py): `core/trend/timeline.py`
- [Risk simulation](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/montecarlo/simulate.py): `core/montecarlo/simulate.py`

### Trading projects

- [Strategy skeleton](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/strategy/skeleton.py): `core/strategy/skeleton.py`
- [Project generator](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/scaffold/generator.py): `core/scaffold/generator.py`
- [Broker templates](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/broker/registry.py): `core/broker/registry.py`
- [Chart options](https://github.com/mars-tw/anti-gambling-trader-tw/blob/main/core/charts/registry.py): `core/charts/registry.py`

### Other components

- **Trader**

## Connections

- Trader → Command interface: runs commands
- Command interface → Record loader: loads records (evidence: `core/cli.py`)
- Command interface → Screenshot review: routes screenshots (evidence: `core/cli.py`)
- Command interface → Chat scanner: routes chat scans (evidence: `core/cli.py`)
- Record loader → Trade records: normalizes trades (evidence: `core/ingest/loader.py`)
- Record loader → Market rules: infers markets (evidence: `core/ingest/loader.py`)
- Command interface → Analysis coordinator: starts analysis (evidence: `core/cli.py`)
- Analysis coordinator → Record loader: loads input (evidence: `core/analyzer.py`)
- Analysis coordinator → Performance metrics: computes metrics (evidence: `core/analyzer.py`)
- Analysis coordinator → Verdict engine: requests judgment (evidence: `core/analyzer.py`)
- Analysis coordinator → Out-of-sample check: validates holdout (evidence: `core/analyzer.py`)
- Analysis coordinator → Strategy breakdown: breaks down tags (evidence: `core/analyzer.py`)
- Analysis coordinator → Strategy skeleton: builds strategy (evidence: `core/analyzer.py`)
- Performance metrics → Trade records: reads trades (evidence: `core/metrics/performance.py`)
- Performance metrics → Market rules: uses market data (evidence: `core/metrics/performance.py`)
- Verdict engine → Performance metrics: uses metrics (evidence: `core/verdict/judge.py`)
- Verdict engine → Significance tests: tests expectancy (evidence: `core/verdict/judge.py`)
- Out-of-sample check → Performance metrics: summarizes segments (evidence: `core/backtest/validate.py`)
- Out-of-sample check → Significance tests: tests segments (evidence: `core/backtest/validate.py`)
- Command interface → Experience stage: checks stage (evidence: `core/cli.py`)
- Command interface → HTML report: outputs report (evidence: `core/cli.py`)
- Command interface → Guru claim check: checks claim (evidence: `core/cli.py`)
- Guru claim check → Significance tests: uses probability tests (evidence: `core/antiscam/guru_claim.py`)
- Guru claim check → Survivorship model: models chance (evidence: `core/antiscam/guru_claim.py`)
- Command interface → Return forensics: runs forensics (evidence: `core/cli.py`)
- Command interface → Survivorship model: checks survivorship (evidence: `core/cli.py`)
- Command interface → Time trends: requests timeline (evidence: `core/cli.py`)
- Command interface → Risk simulation: runs simulation (evidence: `core/cli.py`)
- Command interface → Project generator: generates project (evidence: `core/cli.py`)
- Project generator → Broker templates: selects broker (evidence: `core/scaffold/generator.py`)
- Project generator → Chart options: selects chart (evidence: `core/scaffold/generator.py`)
- Command interface → Broker templates: lists brokers (evidence: `core/cli.py`)
- Command interface → Chart options: lists charts (evidence: `core/cli.py`)
