# anhkhoa-ledinh/protected-m architecture

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

- Interactive diagram: https://gitdiagram.com/anhkhoa-ledinh/protected-m
- Repository: https://github.com/anhkhoa-ledinh/protected-m

## Overview

Protected M is a glasses-free, head-coupled 3D bug-hunt game, with HCPD also usable as a standalone display engine. Players sign in, select a level and photo, bake depth layers, equip a loadout, then hunt depth-occluded bugs using webcam head tracking and mouse shots. The graph preserves photo processing, tracking/projection, gameplay, UI, shared-album, and online PvP/server capabilities. Relationships are grounded mainly in the README and indexed references; unsampled implementation details are not inferred.

Main entry points: [`src/engine/app.py`](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/app.py) (Game orchestrator), [`src/engine/tracking_worker.py`](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/tracking_worker.py) (Tracking worker), [`src/content/depth_worker.py`](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/depth_worker.py) (Bake worker), [`src/net/client.py`](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/net/client.py) (PvP client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application and UI"]
  node_entry["Application entry<br/>[main.py]"]
  node_orchestrator["Game orchestrator<br/>[app.py]"]
  node_routes["UI routing<br/>[v3_routes.py]"]
  node_ui_flow["UI flow state<br/>[v3_flow.py]"]
end

subgraph group_vision["Tracking and display"]
  node_camera["Webcam capture<br/>[capture.py]"]
  node_tracking_worker["Tracking worker<br/>[tracking_worker.py]"]
  node_head_pose["Head pose solve<br/>[head_pose.py]"]
  node_calibration["Face calibration<br/>[calibration.py]"]
  node_pose_filter["Pose filtering<br/>[pipeline.py]"]
  node_pose_bus["Pose distribution<br/>[pose_bus.py]"]
  node_webcam_preview["Webcam preview<br/>[webcam_preview.py]"]
end

subgraph group_content["Photo and scene content"]
  node_photo["Photo input<br/>[image_source.py]"]
  node_bake_worker["Bake worker<br/>[depth_worker.py]"]
  node_depth_model["Depth estimation<br/>[depth_estimator.py]"]
  node_layer_pipeline["Layer and fill processing"]
  node_baked_content[("Baked scene content<br/>[persistence.py]")]
  node_shared_album["Shared photo album<br/>[shared_album.py]"]
end

subgraph group_game["Gameplay"]
  node_prop_game["Hidden bug placement<br/>[prop_game.py]"]
  node_match["Match rules and state<br/>[match.py]"]
  node_levels["Level definitions<br/>[levels.py]"]
  node_renderer["3D scene rendering<br/>[renderer.py]"]
end

subgraph group_online["Accounts and online"]
  node_account["Local accounts<br/>[service.py]"]
  node_rules["Shared account rules<br/>[account_rules.py]"]
  node_net_client["PvP client<br/>[client.py]"]
  node_protocol["Network protocol<br/>[protocol.py]"]
  node_server["Central server<br/>[app.py]"]
  node_handlers["Server request handlers<br/>[handlers.py]"]
  node_server_store[("Server data store<br/>[store.py]")]
end

node_player(("Player"))

node_player -->|"starts game"| node_entry
node_entry -->|"launches"| node_orchestrator
node_orchestrator -->|"handles UI actions"| node_routes
node_routes -->|"updates screen state"| node_ui_flow
node_player -->|"chooses photo and acts"| node_orchestrator
node_orchestrator -.->|"starts capture"| node_camera
node_tracking_worker -->|"reads frames"| node_camera
node_tracking_worker -->|"solves pose"| node_head_pose
node_head_pose -->|"uses scale calibration"| node_calibration
node_tracking_worker -->|"filters pose"| node_pose_filter
node_tracking_worker -->|"publishes pose"| node_pose_bus
node_tracking_worker -->|"provides preview"| node_webcam_preview
node_orchestrator -->|"starts photo bake"| node_bake_worker
node_bake_worker -->|"estimates depth"| node_depth_model
node_bake_worker -.->|"builds depth layers"| node_layer_pipeline
node_bake_worker -.->|"caches baked result"| node_baked_content
node_orchestrator -->|"requests album photos"| node_shared_album
node_shared_album -->|"supplies photo"| node_photo
node_orchestrator -->|"creates hidden bugs"| node_prop_game
node_prop_game -->|"uses level settings"| node_levels
node_orchestrator -->|"updates match"| node_match
node_match -->|"uses level rules"| node_levels
node_orchestrator -.->|"renders 3D hunt"| node_renderer
node_player -->|"signs in"| node_account
node_account -->|"applies account rules"| node_rules
node_orchestrator -->|"uses PvP services"| node_net_client
node_net_client -->|"encodes messages"| node_protocol
node_net_client -.->|"exchanges requests"| node_server
node_server -->|"dispatches requests"| node_handlers
node_handlers -->|"reads and writes"| node_server_store
node_server -->|"frames messages"| node_protocol

click node_entry "https://github.com/anhkhoa-ledinh/protected-m/blob/main/main.py"
click node_orchestrator "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/app.py"
click node_routes "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/ui_album/v3_routes.py"
click node_ui_flow "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/ui_album/v3_flow.py"
click node_camera "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/camera/capture.py"
click node_tracking_worker "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/tracking_worker.py"
click node_head_pose "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/pose/head_pose.py"
click node_calibration "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/pose/calibration.py"
click node_pose_filter "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/filters/pipeline.py"
click node_pose_bus "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/pose_bus.py"
click node_webcam_preview "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/renderer/webcam_preview.py"
click node_photo "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/image_source.py"
click node_bake_worker "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/depth_worker.py"
click node_depth_model "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/depth_estimator.py"
click node_layer_pipeline "https://github.com/anhkhoa-ledinh/protected-m/tree/main/src/content"
click node_baked_content "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/persistence.py"
click node_shared_album "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/shared_album.py"
click node_prop_game "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/prop_game.py"
click node_match "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/game/match.py"
click node_levels "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/game/levels.py"
click node_renderer "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/renderer/renderer.py"
click node_account "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/account/service.py"
click node_rules "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/shared/account_rules.py"
click node_net_client "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/net/client.py"
click node_protocol "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/net/protocol.py"
click node_server "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/app.py"
click node_handlers "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/handlers.py"
click node_server_store "https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/store.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_orchestrator,node_routes,node_ui_flow toneBlue
class node_camera,node_tracking_worker,node_head_pose,node_calibration,node_pose_filter,node_pose_bus,node_webcam_preview toneAmber
class node_photo,node_bake_worker,node_depth_model,node_layer_pipeline,node_baked_content,node_shared_album toneMint
class node_prop_game,node_match,node_levels,node_renderer toneRose
class node_account,node_rules,node_net_client,node_protocol,node_server,node_handlers,node_server_store,node_player toneIndigo
```

## Components

### Application and UI

- [Application entry](https://github.com/anhkhoa-ledinh/protected-m/blob/main/main.py): `main.py`
- [Game orchestrator](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/app.py): `src/engine/app.py`
- [UI routing](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/ui_album/v3_routes.py): `src/ui_album/v3_routes.py`
- [UI flow state](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/ui_album/v3_flow.py): `src/ui_album/v3_flow.py`

### Tracking and display

- [Webcam capture](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/camera/capture.py): `src/camera/capture.py`
- [Tracking worker](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/tracking_worker.py): `src/engine/tracking_worker.py`
- [Head pose solve](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/pose/head_pose.py): `src/pose/head_pose.py`
- [Face calibration](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/pose/calibration.py): `src/pose/calibration.py`
- [Pose filtering](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/filters/pipeline.py): `src/filters/pipeline.py`
- [Pose distribution](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/engine/pose_bus.py): `src/engine/pose_bus.py`
- [Webcam preview](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/renderer/webcam_preview.py): `src/renderer/webcam_preview.py`

### Photo and scene content

- [Photo input](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/image_source.py): `src/content/image_source.py`
- [Bake worker](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/depth_worker.py): `src/content/depth_worker.py`
- [Depth estimation](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/depth_estimator.py): `src/content/depth_estimator.py`
- [Layer and fill processing](https://github.com/anhkhoa-ledinh/protected-m/tree/main/src/content): `src/content`
- [Baked scene content](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/persistence.py): `src/content/persistence.py`
- [Shared photo album](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/shared_album.py): `src/content/shared_album.py`

### Gameplay

- [Hidden bug placement](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/content/prop_game.py): `src/content/prop_game.py`
- [Match rules and state](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/game/match.py): `src/game/match.py`
- [Level definitions](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/game/levels.py): `src/game/levels.py`
- [3D scene rendering](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/renderer/renderer.py): `src/renderer/renderer.py`

### Accounts and online

- [Local accounts](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/account/service.py): `src/account/service.py`
- [Shared account rules](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/shared/account_rules.py): `src/shared/account_rules.py`
- [PvP client](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/net/client.py): `src/net/client.py`
- [Network protocol](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/net/protocol.py): `src/net/protocol.py`
- [Central server](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/app.py): `src/server/app.py`
- [Server request handlers](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/handlers.py): `src/server/handlers.py`
- [Server data store](https://github.com/anhkhoa-ledinh/protected-m/blob/main/src/server/store.py): `src/server/store.py`

### Other components

- **Player**

## Connections

- Player → Application entry: starts game
- Application entry → Game orchestrator: launches (evidence: `main.py`)
- Game orchestrator → UI routing: handles UI actions (evidence: `src/engine/app.py`)
- UI routing → UI flow state: updates screen state (evidence: `src/ui_album/v3_routes.py`)
- Player → Game orchestrator: chooses photo and acts
- Game orchestrator → Webcam capture: starts capture (evidence: `src/engine/app.py`)
- Tracking worker → Webcam capture: reads frames (evidence: `src/engine/tracking_worker.py`)
- Tracking worker → Head pose solve: solves pose (evidence: `src/engine/tracking_worker.py`)
- Head pose solve → Face calibration: uses scale calibration (evidence: `src/pose/head_pose.py`)
- Tracking worker → Pose filtering: filters pose (evidence: `src/engine/tracking_worker.py`)
- Tracking worker → Pose distribution: publishes pose (evidence: `src/engine/tracking_worker.py`)
- Tracking worker → Webcam preview: provides preview (evidence: `src/engine/tracking_worker.py`)
- Game orchestrator → Bake worker: starts photo bake (evidence: `src/engine/app.py`)
- Bake worker → Depth estimation: estimates depth (evidence: `src/content/depth_worker.py`)
- Bake worker → Layer and fill processing: builds depth layers (evidence: `src/content/depth_worker.py`)
- Bake worker → Baked scene content: caches baked result
- Game orchestrator → Shared photo album: requests album photos (evidence: `src/engine/app.py`)
- Shared photo album → Photo input: supplies photo (evidence: `src/content/shared_album.py`)
- Game orchestrator → Hidden bug placement: creates hidden bugs (evidence: `src/engine/app.py`)
- Hidden bug placement → Level definitions: uses level settings (evidence: `src/content/prop_game.py`)
- Game orchestrator → Match rules and state: updates match (evidence: `src/engine/app.py`)
- Match rules and state → Level definitions: uses level rules (evidence: `src/game/match.py`)
- Game orchestrator → 3D scene rendering: renders 3D hunt
- Player → Local accounts: signs in
- Local accounts → Shared account rules: applies account rules (evidence: `src/account/service.py`)
- Game orchestrator → PvP client: uses PvP services (evidence: `src/engine/app.py`)
- PvP client → Network protocol: encodes messages (evidence: `src/net/client.py`)
- PvP client → Central server: exchanges requests
- Central server → Server request handlers: dispatches requests (evidence: `src/server/app.py`)
- Server request handlers → Server data store: reads and writes (evidence: `src/server/handlers.py`)
- Central server → Network protocol: frames messages (evidence: `src/server/app.py`)
