# iago-sepini/desenha_ai architecture

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

- Interactive diagram: https://gitdiagram.com/iago-sepini/desenha_ai
- Repository: https://github.com/iago-sepini/desenha_ai

## Overview

Desenha AI recognizes a child’s drawing from a camera, explains it through an LLM and speech, and can reproduce its outline on a CNC. The main loop also supports voice control, free-play and timed drawing challenges, plus a state-driven animated face. The README describes these as parallel recognition outputs; the sampled manager code confirms the SVG generation and LLM path. Some integrations—especially CNC execution and voice-to-face wiring—are documented but not fully visible in the sampled runtime excerpts.

Main entry points: [`main.py`](https://github.com/iago-sepini/desenha_ai/blob/main/main.py) (Application loop), [`ui/manager.py`](https://github.com/iago-sepini/desenha_ai/blob/main/ui/manager.py) (Game manager), [`vision/watcher.py`](https://github.com/iago-sepini/desenha_ai/blob/main/vision/watcher.py) (Drawing watcher), [`ai/llm.py`](https://github.com/iago-sepini/desenha_ai/blob/main/ai/llm.py) (Groq assistant)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Drawing recognition"]
  node_watcher["Drawing watcher<br/>[watcher.py]"]
  node_camera["Camera setup<br/>[config_camera.py]"]
  node_detector["Drawing detector<br/>[detector.py]"]
  node_class_names["Class names"]
  node_training["Model training<br/>[treinar.py]"]
  node_svg["SVG exporter<br/>[svg_export.py]"]
end

subgraph group_interaction["Interaction and state"]
  node_main["Application loop<br/>[main.py]"]
  node_manager["Game manager<br/>[manager.py]"]
  node_state["Shared state<br/>[state.py]"]
  node_face["Animated face<br/>[face.py]"]
  node_dialogs["CNC confirmation<br/>[dialogs.py]"]
  node_listener["Voice commands<br/>[listener.py]"]
  node_whisper["Whisper listener"]
end

subgraph group_response["AI and speech"]
  node_prompts["Prompt rules<br/>[prompts.py]"]
  node_llm["Groq assistant<br/>[llm.py]"]
  node_tts["Piper synthesis<br/>[tts.py]"]
  node_speaker["Speech playback<br/>[speaker.py]"]
  node_text_utils["Text utilities<br/>[text_utils.py]"]
end

subgraph group_machines["Physical output"]
  node_cnc["CNC controller<br/>[cnc.py]"]
end

subgraph group_support["Runtime support"]
  node_config["Runtime config<br/>[config.py]"]
  node_cache[("Answer cache<br/>[respostas.json]")]
end

node_visitor(("Visitor"))

node_visitor -->|"interacts with"| node_main
node_main -->|"starts"| node_watcher
node_watcher -->|"opens camera"| node_camera
node_watcher -->|"detects drawings"| node_detector
node_training -->|"uses categories"| node_class_names
node_watcher -->|"reports drawing"| node_manager
node_manager -->|"exports outline"| node_svg
node_manager -->|"requests description"| node_llm
node_llm -->|"builds prompt"| node_prompts
node_main -->|"starts listener"| node_listener
node_listener -.->|"sends commands"| node_main
node_main -->|"sets up playback"| node_speaker
node_speaker -->|"synthesizes speech"| node_tts
node_speaker -->|"uses utilities"| node_text_utils
node_main -->|"creates state"| node_state
node_face -->|"reads state"| node_state
node_manager -->|"updates state"| node_state
node_main -->|"starts display"| node_face
node_main -->|"creates manager"| node_manager
node_main -->|"imports dialog"| node_dialogs
node_svg -.->|"sends outline"| node_cnc
node_main -->|"loads settings"| node_config
node_llm -->|"reads and writes"| node_cache

click node_main "https://github.com/iago-sepini/desenha_ai/blob/main/main.py"
click node_watcher "https://github.com/iago-sepini/desenha_ai/blob/main/vision/watcher.py"
click node_camera "https://github.com/iago-sepini/desenha_ai/blob/main/vision/config_camera.py"
click node_detector "https://github.com/iago-sepini/desenha_ai/blob/main/vision/detector.py"
click node_class_names "https://github.com/iago-sepini/desenha_ai/blob/main/vision/classes_quickdraw.py"
click node_training "https://github.com/iago-sepini/desenha_ai/blob/main/vision/treinar.py"
click node_svg "https://github.com/iago-sepini/desenha_ai/blob/main/vision/svg_export.py"
click node_manager "https://github.com/iago-sepini/desenha_ai/blob/main/ui/manager.py"
click node_state "https://github.com/iago-sepini/desenha_ai/blob/main/server/state.py"
click node_face "https://github.com/iago-sepini/desenha_ai/blob/main/ui/face.py"
click node_dialogs "https://github.com/iago-sepini/desenha_ai/blob/main/ui/dialogs.py"
click node_prompts "https://github.com/iago-sepini/desenha_ai/blob/main/ai/prompts.py"
click node_llm "https://github.com/iago-sepini/desenha_ai/blob/main/ai/llm.py"
click node_tts "https://github.com/iago-sepini/desenha_ai/blob/main/voice/tts.py"
click node_speaker "https://github.com/iago-sepini/desenha_ai/blob/main/voice/speaker.py"
click node_text_utils "https://github.com/iago-sepini/desenha_ai/blob/main/voice/text_utils.py"
click node_listener "https://github.com/iago-sepini/desenha_ai/blob/main/voice/listener.py"
click node_whisper "https://github.com/iago-sepini/desenha_ai/blob/main/voice/listener_Whisper.py"
click node_cnc "https://github.com/iago-sepini/desenha_ai/blob/main/firmware/cnc.py"
click node_config "https://github.com/iago-sepini/desenha_ai/blob/main/config.py"
click node_cache "https://github.com/iago-sepini/desenha_ai/blob/main/data/cache/respostas.json"

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_watcher,node_camera,node_detector,node_class_names,node_training,node_svg toneBlue
class node_main,node_manager,node_state,node_face,node_dialogs,node_listener,node_whisper toneAmber
class node_prompts,node_llm,node_tts,node_speaker,node_text_utils toneMint
class node_cnc toneRose
class node_config,node_cache,node_visitor toneIndigo
```

## Components

### Drawing recognition

- [Drawing watcher](https://github.com/iago-sepini/desenha_ai/blob/main/vision/watcher.py): `vision/watcher.py`
- [Camera setup](https://github.com/iago-sepini/desenha_ai/blob/main/vision/config_camera.py): `vision/config_camera.py`
- [Drawing detector](https://github.com/iago-sepini/desenha_ai/blob/main/vision/detector.py): `vision/detector.py`
- [Class names](https://github.com/iago-sepini/desenha_ai/blob/main/vision/classes_quickdraw.py): `vision/classes_quickdraw.py`
- [Model training](https://github.com/iago-sepini/desenha_ai/blob/main/vision/treinar.py): `vision/treinar.py`
- [SVG exporter](https://github.com/iago-sepini/desenha_ai/blob/main/vision/svg_export.py): `vision/svg_export.py`

### Interaction and state

- [Application loop](https://github.com/iago-sepini/desenha_ai/blob/main/main.py): `main.py`
- [Game manager](https://github.com/iago-sepini/desenha_ai/blob/main/ui/manager.py): `ui/manager.py`
- [Shared state](https://github.com/iago-sepini/desenha_ai/blob/main/server/state.py): `server/state.py`
- [Animated face](https://github.com/iago-sepini/desenha_ai/blob/main/ui/face.py): `ui/face.py`
- [CNC confirmation](https://github.com/iago-sepini/desenha_ai/blob/main/ui/dialogs.py): `ui/dialogs.py`
- [Voice commands](https://github.com/iago-sepini/desenha_ai/blob/main/voice/listener.py): `voice/listener.py`
- [Whisper listener](https://github.com/iago-sepini/desenha_ai/blob/main/voice/listener_Whisper.py): `voice/listener_Whisper.py`

### AI and speech

- [Prompt rules](https://github.com/iago-sepini/desenha_ai/blob/main/ai/prompts.py): `ai/prompts.py`
- [Groq assistant](https://github.com/iago-sepini/desenha_ai/blob/main/ai/llm.py): `ai/llm.py`
- [Piper synthesis](https://github.com/iago-sepini/desenha_ai/blob/main/voice/tts.py): `voice/tts.py`
- [Speech playback](https://github.com/iago-sepini/desenha_ai/blob/main/voice/speaker.py): `voice/speaker.py`
- [Text utilities](https://github.com/iago-sepini/desenha_ai/blob/main/voice/text_utils.py): `voice/text_utils.py`

### Physical output

- [CNC controller](https://github.com/iago-sepini/desenha_ai/blob/main/firmware/cnc.py): `firmware/cnc.py`

### Runtime support

- [Runtime config](https://github.com/iago-sepini/desenha_ai/blob/main/config.py): `config.py`
- [Answer cache](https://github.com/iago-sepini/desenha_ai/blob/main/data/cache/respostas.json): `data/cache/respostas.json`

### Other components

- **Visitor**

## Connections

- Visitor → Application loop: interacts with (evidence: `README.md`)
- Application loop → Drawing watcher: starts (evidence: `main.py`)
- Drawing watcher → Camera setup: opens camera (evidence: `vision/watcher.py`)
- Drawing watcher → Drawing detector: detects drawings (evidence: `vision/watcher.py`)
- Model training → Class names: uses categories (evidence: `vision/treinar.py`)
- Drawing watcher → Game manager: reports drawing (evidence: `main.py`)
- Game manager → SVG exporter: exports outline (evidence: `ui/manager.py`)
- Game manager → Groq assistant: requests description (evidence: `ui/manager.py`)
- Groq assistant → Prompt rules: builds prompt (evidence: `ai/llm.py`)
- Application loop → Voice commands: starts listener (evidence: `main.py`)
- Voice commands → Application loop: sends commands (evidence: `README.md`)
- Application loop → Speech playback: sets up playback (evidence: `main.py`)
- Speech playback → Piper synthesis: synthesizes speech (evidence: `voice/speaker.py`)
- Speech playback → Text utilities: uses utilities (evidence: `voice/speaker.py`)
- Application loop → Shared state: creates state (evidence: `main.py`)
- Animated face → Shared state: reads state (evidence: `ui/face.py`)
- Game manager → Shared state: updates state (evidence: `ui/manager.py`)
- Application loop → Animated face: starts display (evidence: `main.py`)
- Application loop → Game manager: creates manager (evidence: `main.py`)
- Application loop → CNC confirmation: imports dialog (evidence: `main.py`)
- SVG exporter → CNC controller: sends outline (evidence: `README.md`)
- Application loop → Runtime config: loads settings (evidence: `main.py`)
- Groq assistant → Answer cache: reads and writes (evidence: `ai/llm.py`)
