# indiebubbler/metro architecture

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

- Interactive diagram: https://gitdiagram.com/indiebubbler/metro
- Repository: https://github.com/indiebubbler/metro

## Overview

##### Main Components
- User Interface (Frontend): The React application (most files in the “src” directory) displays an interactive UI with components for control panels (MixerPanel, ModePanel, TrackView, etc.), editing modals (EditPresetModal, SavePresetModal, ImportDialog), and visualizations (Vis, SimpleVis, SvgClock).
- Audio Engine: Integration with Tone.js (as highlighted in the README) which drives the metronome, drum machine sounds, polyrhythms, and instrument switching.
- Assets: The “public” directory contains static assets – HTML files, audio samples (organized by different instrument kits like Basic Drum Kit, Electrokit, Tabla, Yamaha RX5, and Metronome), manifest, and configuration files.
- Localization & Configuration: The “src/localization” directory with files for different languages (e.g., Polish and Italian) indicates built-in internationalization support.
- Hosting & Deployment: Files like firebase.json, .firebaserc, and GitHub Actions workflows point to Firebase hosting with automated deployment pipelines.
- Persistent/State Data: Although this is a front-end application that uses browser storage (saving presets locally via import/export functionality), the architecture should include this data management layer.

##### Relationships and Interactions
- UI components interact with the Audio Engine (Tone.js) by capturing user input (e.g., BPM adjustments, instrument selection, starting/stopping playback) and triggering sound events through Tone.js.
- Several components (like PresetsManager, ImportDialog, and SavePresetModal) interact with browser storage to persist user configurations.
- Localization components provide data and text strings to the UI components to support multilingual interfaces.
- Deployment and build tools are indirectly wired into the project; although not part of runtime architecture, they affect how the code is built and hosted (Firebase hosting, GitHub workflows).

##### Architectural Patterns and Design Principles
- Component-Based Architecture: The React app is organized into many small, reusable components (as seen in the “src/components” directory).
- Separation of Concerns: The UI presentation, business logic, and sound/audio processing (using Tone.js) are kept in clearly defined modules.
- Declarative UI and State Management: Through React, the app dynamically updates in response to user input, likely managing state via React state/hooks.
- Progressive Enhancement: The project supports multiple environments – desktops, smartphones, tablets, and possibly SmartTVs.

##### Technologies, Frameworks, and Libraries
- ReactJS: for building the complex user interface.
- Tone.js: as the core audio library to handle sound synthesis, metronome timings, and building the drum machine.
- Firebase: for hosting (as evidenced by firebase.json and GitHub CI for deployment).
- GitHub Workflows: to manage automated deployment processes.
- Web Audio API: implicitly used through Tone.js.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    User("User"):::user

    %% Browser (Client) Subgraph
    subgraph "Browser (Client)"
        subgraph "UI Layer"
            UIComponents("UI Components (src/components)"):::ui
            ControlPanels("Control Panels (MixerPanel,ModePanel,TrackView)"):::ui
            UIComponents -->|"Contains"| ControlPanels

            subgraph "Audio Engine"
                SoundMachine("SoundMachine.jsx"):::audio
                SoundMachineInstrument("SoundMachineInstrument.jsx"):::audio
                SoundMachine -->|"SelectInstrument"| SoundMachineInstrument
            end
            ControlPanels -->|"SendSoundCommand"| SoundMachine

            subgraph "Presets"
                PresetsManager("PresetsManager.jsx"):::persistence
                EditPresetModal("EditPresetModal.jsx"):::persistence
                SavePresetModal("SavePresetModal.jsx"):::persistence
                ImportDialog("ImportDialog.jsx"):::persistence
                %% Connecting presets components together (logical grouping)
                PresetsManager --- EditPresetModal
                PresetsManager --- SavePresetModal
                PresetsManager --- ImportDialog
            end
            UIComponents -->|"ManagePresets"| Presets
        end

        Localization("Localization (src/localization)"):::localization
        Assets("Static Assets (index.html,manifest.json,audio)"):::assets
        BrowserStorage("BrowserStorage(LocalPresets)"):::persistence

        %% Interactions within Browser
        UIComponents -->|"FetchTranslations"| Localization
        UIComponents -->|"LoadAssets"| Assets
        Presets -->|"PersistPresets"| BrowserStorage
    end

    %% External Deployment Infrastructure
    subgraph "Deployment Infrastructure"
        Developer("Developer"):::user
        CICD("CI/CD Pipeline (.github/workflows)"):::deployment
        Firebase("Firebase Hosting (firebase.json,.firebaserc)"):::deployment
        Developer -->|"PushCode"| CICD
        CICD -->|"Deploy"| Firebase
    end

    %% User Interaction Flow
    User -->|"UserInput"| UIComponents

    %% Class Definitions for Styling
    classDef user fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef ui fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef audio fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef assets fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef localization fill:#DA70D6,stroke:#333,stroke-width:2px;
    classDef deployment fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef persistence fill:#FFA07A,stroke:#333,stroke-width:2px;

    %% Click Events
    click UIComponents "https://github.com/indiebubbler/metro/tree/master/src/components"
    click SoundMachine "https://github.com/indiebubbler/metro/blob/master/src/components/SoundMachine.jsx"
    click SoundMachineInstrument "https://github.com/indiebubbler/metro/blob/master/src/components/SoundMachineInstrument.jsx"
    click PresetsManager "https://github.com/indiebubbler/metro/blob/master/src/components/PresetsManager.jsx"
    click EditPresetModal "https://github.com/indiebubbler/metro/blob/master/src/components/EditPresetModal.jsx"
    click SavePresetModal "https://github.com/indiebubbler/metro/blob/master/src/components/SavePresetModal.jsx"
    click ImportDialog "https://github.com/indiebubbler/metro/blob/master/src/components/ImportDialog.jsx"
    click Localization "https://github.com/indiebubbler/metro/tree/master/src/localization"
    click Assets "https://github.com/indiebubbler/metro/blob/master/public/index.html"
    click CICD "https://github.com/indiebubbler/metro/tree/master/.github/workflows"
    click Firebase "https://github.com/indiebubbler/metro/blob/master/firebase.json"
```
