# suprbh/tjweather architecture

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

- Interactive diagram: https://gitdiagram.com/suprbh/tjweather
- Repository: https://github.com/suprbh/tjweather

## Overview

##### Project type and purpose
- This is a Node.js “voice-enabled IoT” application running on a Raspberry Pi (specifically IBM TJBot hardware).
- Purpose: listen for spoken weather-related queries, transcribe them via Watson Speech to Text, query IBM Weather Insights, synthesize a spoken reply via Watson Text to Speech, and play it back over a speaker.

##### File structure
- Top-level files
– weather.js: main entry-point that initializes services and the voice loop
– weather_response.js: logic to call Weather Insights API and format the response
– inputdata.js: patterns or grammar definitions for parsing voice commands
– config.default.js → copy to config.js: holds credentials for Watson services & Weather API
– package.json: npm dependencies (mic, watson-developer-cloud, alsa)
– images/: illustration assets, not part of runtime
- No separate “src” or “lib” directories – code is small and flat
- No tests directory – focus is on live demo rather than CI/CD
- External infrastructure: microphone, speaker (via ALSA), Watson Speech-to-Text, Watson Text-to-Speech, IBM Weather Insights

##### README for additional insights
- The “How It Works” section outlines a linear pipeline: audio capture → STT → command parsing → weather fetch → TTS → playback
- Hardware requirements: Raspberry Pi + mic + speaker + TJBot
- Dependencies: mic npm package, Watson Developer Cloud SDK, ALSA tools

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware Layer"
        mic["Microphone (Audio Input)"]:::hardware
        speaker["Speaker (Audio Output)"]:::hardware
    end

    %% Local Application Layer
    subgraph "Local Application Layer"
        config["Configuration Store\n(config.default.js)"]:::config
        AudioCap["Audio Capture Module\n(weather.js)"]:::local
        STTClient["Speech-to-Text Client\n(weather.js)"]:::local
        Parser["Command Parser\n(inputdata.js & weather.js)"]:::local
        WeatherClient["Weather API Client\n(weather_response.js)"]:::local
        TTSClient["Text-to-Speech Client\n(weather.js)"]:::local
        Playback["Audio Playback Module\n(weather.js)"]:::local
    end

    %% Cloud Services Layer
    subgraph "Cloud Services Layer"
        STTService["Watson Speech to Text Service"]:::cloud
        TTSService["Watson Text to Speech Service"]:::cloud
        WeatherService["IBM Weather Insights API"]:::cloud
    end

    %% Project Metadata & Assets
    subgraph "Project Metadata & Assets"
        pkg["package.json"]:::config
        readme["README.md"]:::config
        images["images/"]:::config
    end

    %% Data Flow
    mic -->|"recorded WAV stream"| AudioCap
    AudioCap -->|"audio stream"| STTClient
    STTClient -->|"audio data"| STTService
    STTService -->|"text transcript"| STTClient
    STTClient -->|"transcript"| Parser
    Parser -->|"weather intent"| WeatherClient
    WeatherClient -->|"weather JSON"| WeatherService
    WeatherService -->|"weather data"| WeatherClient
    WeatherClient -->|"formatted JSON"| TTSClient
    TTSClient -->|"text"| TTSService
    TTSService -->|"audio MP3"| TTSClient
    TTSClient -->|"audio stream"| Playback
    Playback --> speaker

    %% Configuration Dependencies
    config --> STTClient
    config --> TTSClient
    config --> WeatherClient

    %% Click Events
    click config "https://github.com/suprbh/tjweather/blob/master/config.default.js"
    click AudioCap "https://github.com/suprbh/tjweather/blob/master/weather.js"
    click STTClient "https://github.com/suprbh/tjweather/blob/master/weather.js"
    click Parser "https://github.com/suprbh/tjweather/blob/master/inputdata.js"
    click WeatherClient "https://github.com/suprbh/tjweather/blob/master/weather_response.js"
    click TTSClient "https://github.com/suprbh/tjweather/blob/master/weather.js"
    click Playback "https://github.com/suprbh/tjweather/blob/master/weather.js"
    click pkg "https://github.com/suprbh/tjweather/blob/master/package.json"
    click readme "https://github.com/suprbh/tjweather/blob/master/README.md"
    click images "https://github.com/suprbh/tjweather/tree/master/images/"

    %% Styles
    classDef hardware fill:#e0ffe0,stroke:#2d862d,color:#043202
    classDef local fill:#e0f0ff,stroke:#1a4a72,color:#10253f
    classDef cloud fill:#ffe0b3,stroke:#b36b00,color:#663d00
    classDef config fill:#e0e0e0,stroke:#6e6e6e,color:#333333
```
