# gotwic-scanner/castle_scanner architecture

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

- Interactive diagram: https://gitdiagram.com/gotwic-scanner/castle_scanner
- Repository: https://github.com/gotwic-scanner/castle_scanner

## Overview

GOTWiC Scanner is a desktop tool for scanning game kingdoms, viewing castle/truce observations, and looking up castle power. The main workflow runs from GUI scan controls through the scanner’s live game-protocol tracking to saved snapshots and GUI results; manual power retrieval updates saved records and can trigger optional reporting or upload. Separate modules support protocol analysis, licensing, and updates. Some implementation details are unsampled, so the graph omits uncertain call links.

Main entry points: [`gotwic_gui.py`](https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_gui.py) (Scanner GUI), [`gotwic_scanner_v2_2.py`](https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_scanner_v2_2.py) (Kingdom scanner), [`live_truce_scanner_v5.py`](https://github.com/gotwic-scanner/castle_scanner/blob/main/live_truce_scanner_v5.py) (Protocol tracker v5), [`power_storage.py`](https://github.com/gotwic-scanner/castle_scanner/blob/main/power_storage.py) (Power persistence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Desktop application"]
  node_gui["Scanner GUI<br/>[gotwic_gui.py]"]
  node_power_detector["Power lookup"]
  node_timing["Lookup timing<br/>[power_timing.py]"]
end

subgraph group_scan["Scanning and protocol"]
  node_scanner["Kingdom scanner"]
  node_live6["Live tracker v6"]
  node_live5["Protocol tracker v5"]
  node_event_decoder["Bubble event decoder"]
  node_coordinate_extractor["Coordinate extractor"]
end

subgraph group_data["Snapshots and reporting"]
  node_csv_migration["CSV migration<br/>[csv_storage.py]"]
  node_power_storage["Power persistence<br/>[power_storage.py]"]
  node_discord["Discord reports<br/>[discord_webhook.py]"]
  node_web_upload["Website upload<br/>[web_upload.py]"]
  node_csv_snapshots[("CSV snapshots")]
  node_sql_store[("SQL database")]
end

subgraph group_support["Access and updates"]
  node_license["License validation<br/>[license_client.py]"]
  node_startup["Startup checks<br/>[startup.py]"]
  node_updater["Application updater<br/>[updater.py]"]
end

node_user(("Scanner user"))
node_game(("Game client"))
node_discord_service(("Discord service"))
node_license_service(("License service"))

node_user -->|"configures scans"| node_gui
node_gui -->|"starts scans"| node_scanner
node_scanner -->|"controls and reads"| node_game
node_scanner -->|"uses tracker"| node_live6
node_live6 -->|"extends tracker"| node_live5
node_live5 -->|"uses decoder"| node_event_decoder
node_live5 -->|"uses extractor"| node_coordinate_extractor
node_scanner -->|"uses storage helper"| node_csv_migration
node_scanner -->|"exports snapshots"| node_csv_snapshots
node_gui -->|"uses persistence"| node_power_storage
node_power_storage -->|"updates snapshot"| node_csv_snapshots
node_power_storage -.->|"updates SQL"| node_sql_store
node_gui -->|"queues reports"| node_discord
node_gui -->|"queues uploads"| node_web_upload
node_discord -->|"filters castles"| node_scanner
node_discord -.->|"posts reports"| node_discord_service
node_gui -->|"checks license"| node_license
node_license -.->|"validates key"| node_license_service
node_gui -.->|"runs startup checks"| node_startup
node_gui -.->|"uses updater"| node_updater
node_power_detector -->|"uses timings"| node_timing

click node_gui "https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_gui.py"
click node_scanner "https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_scanner_v2_2.py"
click node_live6 "https://github.com/gotwic-scanner/castle_scanner/blob/main/live_truce_scanner_v6.py"
click node_live5 "https://github.com/gotwic-scanner/castle_scanner/blob/main/live_truce_scanner_v5.py"
click node_event_decoder "https://github.com/gotwic-scanner/castle_scanner/blob/main/decode_bubble_events.py"
click node_coordinate_extractor "https://github.com/gotwic-scanner/castle_scanner/blob/main/extract_coordinates_from_protocol.py"
click node_power_detector "https://github.com/gotwic-scanner/castle_scanner/blob/main/castle_power_detector.py"
click node_timing "https://github.com/gotwic-scanner/castle_scanner/blob/main/power_timing.py"
click node_csv_migration "https://github.com/gotwic-scanner/castle_scanner/blob/main/csv_storage.py"
click node_power_storage "https://github.com/gotwic-scanner/castle_scanner/blob/main/power_storage.py"
click node_discord "https://github.com/gotwic-scanner/castle_scanner/blob/main/discord_webhook.py"
click node_web_upload "https://github.com/gotwic-scanner/castle_scanner/blob/main/web_upload.py"
click node_license "https://github.com/gotwic-scanner/castle_scanner/blob/main/license_client.py"
click node_startup "https://github.com/gotwic-scanner/castle_scanner/blob/main/startup.py"
click node_updater "https://github.com/gotwic-scanner/castle_scanner/blob/main/updater.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_gui,node_power_detector,node_timing,node_user,node_game toneBlue
class node_scanner,node_live6,node_live5,node_event_decoder,node_coordinate_extractor toneAmber
class node_csv_migration,node_power_storage,node_discord,node_web_upload,node_csv_snapshots,node_sql_store toneMint
class node_license,node_startup,node_updater toneRose
class node_discord_service,node_license_service toneIndigo
```

## Components

### Desktop application

- [Scanner GUI](https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_gui.py): `gotwic_gui.py`
- [Power lookup](https://github.com/gotwic-scanner/castle_scanner/blob/main/castle_power_detector.py): `castle_power_detector.py`
- [Lookup timing](https://github.com/gotwic-scanner/castle_scanner/blob/main/power_timing.py): `power_timing.py`

### Scanning and protocol

- [Kingdom scanner](https://github.com/gotwic-scanner/castle_scanner/blob/main/gotwic_scanner_v2_2.py): `gotwic_scanner_v2_2.py`
- [Live tracker v6](https://github.com/gotwic-scanner/castle_scanner/blob/main/live_truce_scanner_v6.py): `live_truce_scanner_v6.py`
- [Protocol tracker v5](https://github.com/gotwic-scanner/castle_scanner/blob/main/live_truce_scanner_v5.py): `live_truce_scanner_v5.py`
- [Bubble event decoder](https://github.com/gotwic-scanner/castle_scanner/blob/main/decode_bubble_events.py): `decode_bubble_events.py`
- [Coordinate extractor](https://github.com/gotwic-scanner/castle_scanner/blob/main/extract_coordinates_from_protocol.py): `extract_coordinates_from_protocol.py`

### Snapshots and reporting

- [CSV migration](https://github.com/gotwic-scanner/castle_scanner/blob/main/csv_storage.py): `csv_storage.py`
- [Power persistence](https://github.com/gotwic-scanner/castle_scanner/blob/main/power_storage.py): `power_storage.py`
- [Discord reports](https://github.com/gotwic-scanner/castle_scanner/blob/main/discord_webhook.py): `discord_webhook.py`
- [Website upload](https://github.com/gotwic-scanner/castle_scanner/blob/main/web_upload.py): `web_upload.py`
- **CSV snapshots**
- **SQL database**

### Access and updates

- [License validation](https://github.com/gotwic-scanner/castle_scanner/blob/main/license_client.py): `license_client.py`
- [Startup checks](https://github.com/gotwic-scanner/castle_scanner/blob/main/startup.py): `startup.py`
- [Application updater](https://github.com/gotwic-scanner/castle_scanner/blob/main/updater.py): `updater.py`

### Other components

- **Scanner user**
- **Game client**
- **Discord service**
- **License service**

## Connections

- Scanner user → Scanner GUI: configures scans (evidence: `README.md`)
- Scanner GUI → Kingdom scanner: starts scans (evidence: `gotwic_gui.py`)
- Kingdom scanner → Game client: controls and reads (evidence: `gotwic_scanner_v2_2.py`)
- Kingdom scanner → Live tracker v6: uses tracker (evidence: `gotwic_scanner_v2_2.py`)
- Live tracker v6 → Protocol tracker v5: extends tracker (evidence: `live_truce_scanner_v6.py`)
- Protocol tracker v5 → Bubble event decoder: uses decoder (evidence: `live_truce_scanner_v5.py`)
- Protocol tracker v5 → Coordinate extractor: uses extractor (evidence: `live_truce_scanner_v5.py`)
- Kingdom scanner → CSV migration: uses storage helper (evidence: `gotwic_scanner_v2_2.py`)
- Kingdom scanner → CSV snapshots: exports snapshots (evidence: `gotwic_scanner_v2_2.py`)
- Scanner GUI → Power persistence: uses persistence (evidence: `gotwic_gui.py`)
- Power persistence → CSV snapshots: updates snapshot (evidence: `power_storage.py`)
- Power persistence → SQL database: updates SQL
- Scanner GUI → Discord reports: queues reports (evidence: `gotwic_gui.py`)
- Scanner GUI → Website upload: queues uploads (evidence: `gotwic_gui.py`)
- Discord reports → Kingdom scanner: filters castles (evidence: `discord_webhook.py`)
- Discord reports → Discord service: posts reports
- Scanner GUI → License validation: checks license (evidence: `gotwic_gui.py`)
- License validation → License service: validates key
- Scanner GUI → Startup checks: runs startup checks
- Scanner GUI → Application updater: uses updater
- Power lookup → Lookup timing: uses timings (evidence: `castle_power_detector.py`)
