# ilyamiro/stewart architecture

> Architecture diagram of the GitHub repository ilyamiro/stewart, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ilyamiro/stewart
- Repository: https://github.com/ilyamiro/stewart

## Overview

##### Project type and purpose
- Stewart is a desktop-based, local voice assistant written in Python.
- It integrates a local speech-to-text (STT) engine (Vosk models), a local text-to-speech (TTS) engine (SileroTTS via the voicesynth library), a tree-based command dispatcher, a plugin framework for actions, a simple GUI, and an optional HTTP API for external integrations.

##### File structure
- Top-level application entry: main.py
- “api/”: REST or WebSocket endpoints (app.py) plus scenario and event models
- “app/”: core application bootstrap and orchestration (app/app.py)
- “audio/”:
- input/: microphone capture & STT logic (recognition.py) with embedded Vosk and Silero models
- tts/: speech synthesis logic (synthesis.py)
- “config/”: YAML configuration for languages and general parameters
- “data/”: static assets (images, sounds, constants)
- “gui/”: simple animation and UI hooks (animation.py)
- “logs/”: logging setup and initializers
- “modules/”: standalone utility modules (e.g., words2num)
- “plugins/”:
- core/: built-in actions, events and media handlers
- custom/: user-provided integrations (ADB, battery, weather, gestures, Taskwarrior, etc.)
- gpt/: ChatGPT integration
- “utils/”: shared classes (type definitions), language packs, system utilities
- “scripts/”: ancillary build/test/deployment helpers
- requirements.txt & version.txt

##### Extract key insights from the README
- Local-only voice models for STT and TTS
- Tree-based command handling with >99% accuracy for predefined commands
- Linux only, personal-use project
- Fast, efficient plugin-driven action execution

a. Main components
- Audio Input Capture (microphone)
- STT Engine (Vosk + Silero utils)
- Core Dispatcher (main.py → app/app.py → api.tree & api.events)
- Scenario/Command Tree (api/scenarios.py + api/tree.py)
- Plugin Framework (plugins/core, plugins/custom, plugins/gpt)
- Utility Modules (modules/words2num, utils/)
- TTS Engine (SileroTTS via audio/tts/synthesis.py)
- GUI Layer (gui/animation.py)
- API Layer (api/app.py)
- Configuration & Data Store (config/, data/)
- Logging Subsystem (logs/)
- External Services (ADB, Weather API, Taskwarrior, GPT endpoint)

b. Relationships and data flow
1. User speaks → Audio Input Capture
2. Raw audio → STT Engine → Text
3. Text → Core Dispatcher → Scenario/Command Tree
4. Command Node → Plugin Framework
– Core plugins for built-in actions (media playback, system events)
– Custom plugins for external integrations
– GPT plugin for AI responses
5. Plugin produces either:
– Action execution (e.g., shell command via utils.system)
– TTS request (text for speech synthesis)
6. Text → TTS Engine → Audio Output (speaker)
7. Throughout:
– GUI Layer receives events to drive animations/status
– API Layer exposes endpoints that invoke Core Dispatcher/Plugins
– Configuration and Data provide static parameters, language packs, model paths
– Logging Subsystem records each step

c. Architectural patterns and principles
- Layered architecture separating input, processing, output
- Plugin pattern for extensibility (core vs. custom vs. GPT)
- Tree-based command routing for clear command→handler mapping
- Single responsibility modules (words2num, utils.system, config loader)
- Local-first AI (no remote STT/TTS calls, except GPT plugin if configured)

d. Key technologies and libraries
- Python 3.11
- Vosk speech-to-text models (en, ru)
- Silero TTS (via voicesynth)
- Flask or FastAPI (if used) for API layer (api/app.py)
- PyYAML for config loading
- WebSockets or HTTP for events (api/events.py)
- Logging (Python logging module via logs/setup.py)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        direction TB
        Mic["Microphone"]:::input
        Recog["Audio Input Capture\n(recognition.py)"]:::input
        STT["STT Engine\n(Vosk Models)"]:::processing
    end

    Mic -->|captures audio| Recog
    Recog -->|raw audio| STT

    click Recog "https://github.com/ilyamiro/stewart/blob/master/audio/input/recognition.py"
    click STT "https://github.com/ilyamiro/stewart/tree/master/audio/input/models/"

    %% Core Bootstrap and Processing
    subgraph "Core Processing"
        direction TB
        Main["Main Entry\n(main.py)"]:::processing
        CoreApp["Core Bootstrap\n(app/app.py)"]:::processing
        Dispatcher["Core Dispatcher"]:::processing
        ScenarioTree["Scenario/Command Tree\n(api/tree.py & api/scenarios.py)"]:::processing
    end

    STT -->|text| Main
    Main --> CoreApp
    click Main "https://github.com/ilyamiro/stewart/blob/master/main.py"
    click CoreApp "https://github.com/ilyamiro/stewart/blob/master/app/app.py"
    CoreApp -->|initializes| Dispatcher
    Dispatcher -->|routes command| ScenarioTree
    click ScenarioTree "https://github.com/ilyamiro/stewart/blob/master/api/tree.py"
    click ScenarioTree "https://github.com/ilyamiro/stewart/blob/master/api/scenarios.py"

    %% Plugin Framework
    subgraph "Plugin Framework" 
        direction TB
        CorePlugins["Core Plugins\n(plugins/core/)"]:::plugins
        CustomPlugins["Custom Plugins\n(plugins/custom/)"]:::plugins
        GPTPlugin["GPT Plugin\n(gpt.py)"]:::plugins
    end
    ScenarioTree --> CorePlugins
    ScenarioTree --> CustomPlugins
    ScenarioTree --> GPTPlugin

    click CorePlugins "https://github.com/ilyamiro/stewart/tree/master/plugins/core/"
    click CustomPlugins "https://github.com/ilyamiro/stewart/tree/master/plugins/custom/"
    click GPTPlugin "https://github.com/ilyamiro/stewart/blob/master/plugins/gpt/gpt.py"

    %% Actions and TTS
    ActionExec["Action Execution\n(utils/system.py)"]:::processing
    TTSReq["TTS Request"]:::processing
    CorePlugins --> ActionExec
    CustomPlugins --> ActionExec
    GPTPlugin --> TTSReq
    GPTPlugin --> ActionExec

    click ActionExec "https://github.com/ilyamiro/stewart/blob/master/utils/system.py"

    %% TTS Engine and Output
    subgraph "Output Layer"
        direction TB
        TTS["TTS Engine\n(synthesis.py)"]:::processing
        Speaker["Speaker\n(Audio Output)"]:::output
    end
    TTSReq --> TTS
    click TTS "https://github.com/ilyamiro/stewart/blob/master/audio/tts/synthesis.py"
    TTS -->|audio| Speaker

    %% GUI Layer
    GUI["GUI Layer\n(animation.py)"]:::output
    Dispatcher -->|status/events| GUI
    click GUI "https://github.com/ilyamiro/stewart/blob/master/gui/animation.py"

    %% API Layer
    subgraph "API Layer"
        direction TB
        APIApp["API App\n(api/app.py)"]:::processing
        Events["API Events\n(api/events.py)"]:::processing
    end
    APIApp --> Events
    Events --> Dispatcher
    click APIApp "https://github.com/ilyamiro/stewart/blob/master/api/app.py"
    click Events "https://github.com/ilyamiro/stewart/blob/master/api/events.py"

    %% Resources
    subgraph "Resources"
        direction TB
        Config["Configuration\n(config/config.yaml)"]:::resources
        Langs["Language Packs\n(config/langs/)"]:::resources
        DataConst["Constants\n(data/constants.py)"]:::resources
        DataImg["Images\n(data/images/)"]:::resources
        DataSnd["Sounds\n(data/sounds/)"]:::resources
        Modules["Words2Num Module\n(modules/words2num/)"]:::resources
        Classes["Type Definitions\n(utils/classes.py)"]:::resources
        Logs["Logging Setup\n(logs/setup.py)"]:::resources
    end

    Config --> CoreApp
    Langs --> STT
    Langs --> TTS
    DataConst --> CoreApp
    DataImg --> GUI
    DataSnd --> GUI
    Modules --> CoreApp
    Classes --> Dispatcher
    Logs --> Main

    click Config "https://github.com/ilyamiro/stewart/blob/master/config/config.yaml"
    click Langs "https://github.com/ilyamiro/stewart/tree/master/config/langs/"
    click DataConst "https://github.com/ilyamiro/stewart/blob/master/data/constants.py"
    click DataImg "https://github.com/ilyamiro/stewart/tree/master/data/images/"
    click DataSnd "https://github.com/ilyamiro/stewart/tree/master/data/sounds/"
    click Modules "https://github.com/ilyamiro/stewart/tree/master/modules/words2num/"
    click Classes "https://github.com/ilyamiro/stewart/blob/master/utils/classes.py"
    click Logs "https://github.com/ilyamiro/stewart/blob/master/logs/setup.py"

    %% External Services
    subgraph "External Services"
        direction TB
        ADB["ADB Service"]:::external
        Weather["Weather API"]:::external
        Taskwarrior["Taskwarrior CLI"]:::external
        GPTService["OpenAI GPT Endpoint"]:::external
    end

    CustomPlugins -- "invokes" --> ADB
    CustomPlugins -- "invokes" --> Weather
    CustomPlugins -- "invokes" --> Taskwarrior
    GPTPlugin -- "calls" --> GPTService

    classDef input fill:#D6EAF8,stroke:#2980B9,stroke-width:1px
    classDef processing fill:#D5F5E3,stroke:#27AE60,stroke-width:1px
    classDef output fill:#FCF3CF,stroke:#D68910,stroke-width:1px
    classDef plugins fill:#E8DAEF,stroke:#8E44AD,stroke-width:1px
    classDef resources fill:#F2F3F4,stroke:#7F8C8D,stroke-width:1px
    classDef external fill:#FDEDEC,stroke:#C0392B,stroke-width:1px,stroke-dasharray: 5 5
```
