# sebhernandezamoros/mimidi architecture

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

- Interactive diagram: https://gitdiagram.com/sebhernandezamoros/mimidi
- Repository: https://github.com/sebhernandezamoros/mimidi

## Overview

1. **Overall shape**
   - MiMIDI is a mobile-first music lab built as a layered TypeScript/React app.
   - The repository is organized by musical capability, not by UI framework: audio, MIDI, projects, plugins, transport, editing, performance, and sampling are the main boundaries.

2. **Top-level application shell**
   - `src/main.tsx`, `src/App.tsx`, and `src/app/*` define the app bootstrap, routing, theme, navigation, and shell layout.
   - `AppShell`, `appRoutes`, `appNavigation`, `appTheme`, and `appI18n` centralize cross-cutting concerns so individual feature screens stay focused.

3. **Feature screens as presentation layer**
   - Most user-facing behavior lives under `src/features/*` as screens and workspace components: edit, perform, project, catalog, plugins, settings, sampler, lab, tutorial, MIDI event log, piano preview, timeline preview, transport, and SMC pad.
   - These components are primarily orchestration and UI; they call into application use-cases and engine services rather than containing synthesis or persistence logic.

4. **Application layer for coordination**
   - `src/application/use-cases/*` contains the action-oriented business workflows: note playback, arpeggiator playback, sequencer steps, sample import/export, recording mic input, project import/export, bundle/audio export, and file saving.
   - This layer is the bridge between UI intent and engine capabilities, keeping feature components thin and making side effects explicit.

5. **Audio engine boundary**
   - `src/engine/audio/*` is the core sound subsystem: synthesis models, instrument catalog, mathematical instruments, sample handling, offline rendering, and WAV encoding.
   - The README’s constraint is reflected here: the core is synth-based, with samples treated as a separate model rather than the default sound source.
   - `audioEngine.ts` and `offlineAudioRenderer.ts` are the main runtime/rendering services; `wavEncoder.ts` handles export formatting.

6. **MIDI and timing model**
   - `src/engine/midi/*` holds musical event primitives and playback logic: notes, MIDI-style events, and arpeggiator behavior.
   - These modules represent musical intent and sequencing, distinct from audio generation, which is important for features like recording, timeline playback, and step triggering.

7. **Project and sample persistence**
   - `src/engine/project/*` and `src/engine/audio/sampleStorage.ts` / `sampleModel.ts` handle persistent project state and sample data.
   - The README indicates local persistence via IndexedDB; the engine layer is where long-lived project/sample state is modeled and stored.

8. **Plugin system as a major architectural boundary**
   - `src/engine/plugins/*` is a complete subsystem: plugin model, registry, loader, API, internal plugins, and external plugin storage.
   - Plugins are first-class extensions, not ad hoc UI add-ons. The API exposes audio, project, transport, clip/session storage, and UI notifications to plugin workspaces.
   - There are two plugin types reflected in the code and README: **instrument packs** and **React workspaces**.

9. **Plugin runtime and hosting**
   - `PluginWorkspaceHost` and the plugins feature screens provide the runtime shell that mounts external plugin UIs inside the app.
   - `public/mimidi-plugin-sdk.d.ts` is the typed boundary contract for plugin authors.
   - `public/demo-plugins/*` contains source and built examples, and `scripts/build-mimod.mjs` / `scripts/build-plugin.mjs` create distributable `.mimod` archives.

10. **Lab as the plugin-centered working area**
   - The `features/lab` area is the central workspace for plugin usage, instrument selection, playback, recording, and project control.
   - It ties together lab project state, instrument catalog access, recording session state, playback, and plugin-driven actions.

11. **Editor, perform, sampler, and timeline workflows**
   - `features/edit` and `features/timeline` focus on composing and arranging musical events.
   - `features/perform` and `features/piano` support live playing and instrument interaction.
   - `features/audio-sampler`, `features/sampler`, and `features/smc-pad` provide sample and percussion workflows.
   - These are separate surfaces over the same underlying engine and project state, not separate apps.

12. **User feedback and stateful UX**
   - `features/history`, `features/tutorial`, `features/midi-events`, and reusable components like dialogs and error boundaries support undo/redo, onboarding, event inspection, and fault isolation.
   - This suggests the app is state-heavy and interaction-driven, with UI state layered on top of engine state.

13. **Infrastructure and tooling**
   - The app uses React 19, TypeScript, and Vite for the main product.
   - Esbuild powers plugin bundling; fflate/ZIP-based `.mimod` packaging and IndexedDB-backed plugin storage are part of the plugin infrastructure.
   - Tests exist for project history and plugin model/registry/storage, showing those boundaries are meant to be stable.

14. **Data flow to capture in an architecture diagram**
   - User action in a feature screen → application use-case → engine audio/MIDI/project subsystem → persistence or audio output.
   - Plugin install/import → plugin storage/registry/loader → plugin workspace host or instrument catalog → runtime API callbacks.
   - Project export/import and WAV export are terminal flows that leave the app boundary as files.

15. **What is most important to draw**
   - A diagram should emphasize the separation between:
     - presentation screens,
     - use-case coordination,
     - core audio/MIDI/project engines,
     - plugin runtime/storage,
     - and file/persistence/export boundaries.
   - The main architectural idea is that React is only the shell; musical behavior lives in engine and plugin subsystems.

Main entry points: [`src/app/appRoutes.ts`](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appRoutes.ts) (Routes), [`src/app/AppShell.tsx`](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/AppShell.tsx) (Shell), [`src/features/lab/LabApp.tsx`](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/lab/LabApp.tsx) (Lab), [`src/application/use-cases/playNote.ts`](https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/playNote.ts) (Play Note)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app_shell["App Shell"]
  node_main_tsx["main.tsx<br/>bootstrap<br/>[main.tsx]"]
  node_app_tsx["App<br/>root component<br/>[App.tsx]"]
  node_app_shell_tsx["Shell<br/>[AppShell.tsx]"]
  node_app_routes["Routes<br/>navigation map<br/>[appRoutes.ts]"]
  node_app_navigation["Navigation<br/>menu model<br/>[appNavigation.ts]"]
  node_app_theme["Theme<br/>styling system<br/>[appTheme.ts]"]
end

subgraph group_presentation["Presentation"]
  node_lab_app["Lab<br/>workspace screen<br/>[LabApp.tsx]"]
  node_edit_screen["Edit<br/>[EditScreen.tsx]"]
  node_perform_screen["Perform<br/>live screen<br/>[PerformScreen.tsx]"]
  node_plugins_screen["Plugins<br/>plugin screen<br/>[PluginsScreen.tsx]"]
  node_project_screen["Project<br/>[ProjectScreen.tsx]"]
  node_timeline_preview["Timeline<br/>arrangement view"]
end

subgraph group_application["Application"]
  node_play_note_uc["Play Note<br/>use-case<br/>[playNote.ts]"]
  node_record_mic_uc["Record Mic<br/>use-case<br/>[recordMicSample.ts]"]
  node_import_project_uc["Import Project<br/>use-case"]
  node_export_audio_uc["Export Audio<br/>use-case"]
end

subgraph group_engine["Engine"]
  node_audio_engine["Audio Engine<br/>sound core<br/>[audioEngine.ts]"]
  node_offline_renderer["Renderer<br/>offline render"]
  node_midi_events["MIDI Events<br/>event model<br/>[events.ts]"]
  node_project_store[("Project Store<br/>project persistence<br/>[projectStorage.ts]")]
end

subgraph group_plugins["Plugins"]
  node_plugin_host["Host<br/>runtime shell"]
  node_plugin_registry["Registry<br/>plugin catalog<br/>[pluginRegistry.ts]"]
  node_plugin_loader["Loader<br/>plugin runtime<br/>[pluginLoader.ts]"]
  node_plugin_storage[("Plugin Storage<br/>plugin persistence")]
  node_plugin_api["Plugin API<br/>SDK boundary<br/>[pluginApi.ts]"]
  node_sdk_dts["SDK Types<br/>authoring contract"]
  node_build_plugin["Build Plugin<br/>tooling<br/>[build-plugin.mjs]"]
end

node_main_tsx -->|"boots"| node_app_tsx
node_app_tsx -->|"composes"| node_app_shell_tsx
node_app_shell_tsx -->|"uses"| node_app_routes
node_app_shell_tsx -->|"uses"| node_app_navigation
node_app_shell_tsx -->|"applies"| node_app_theme
node_app_shell_tsx -->|"opens"| node_lab_app
node_app_routes -->|"routes"| node_edit_screen
node_app_routes -->|"routes"| node_perform_screen
node_app_routes -->|"routes"| node_plugins_screen
node_app_routes -->|"routes"| node_project_screen
node_app_routes -->|"routes"| node_timeline_preview
node_lab_app -->|"triggers"| node_play_note_uc
node_lab_app -->|"triggers"| node_record_mic_uc
node_lab_app -->|"queries"| node_plugin_registry
node_play_note_uc -->|"creates"| node_midi_events
node_play_note_uc -->|"plays"| node_audio_engine
node_record_mic_uc -->|"captures"| node_audio_engine
node_import_project_uc -->|"loads"| node_project_store
node_export_audio_uc -->|"renders"| node_offline_renderer
node_offline_renderer -->|"depends on"| node_audio_engine
node_project_screen -->|"manages"| node_project_store
node_plugins_screen -->|"mounts"| node_plugin_host
node_plugin_host -->|"exposes"| node_plugin_api
node_plugin_registry -->|"uses"| node_plugin_loader
node_plugin_registry -->|"persists"| node_plugin_storage
node_plugin_api -->|"contracts"| node_sdk_dts
node_build_plugin -.->|"packages"| node_sdk_dts

click node_main_tsx "https://github.com/sebhernandezamoros/mimidi/blob/main/src/main.tsx"
click node_app_tsx "https://github.com/sebhernandezamoros/mimidi/blob/main/src/App.tsx"
click node_app_shell_tsx "https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/AppShell.tsx"
click node_app_routes "https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appRoutes.ts"
click node_app_navigation "https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appNavigation.ts"
click node_app_theme "https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appTheme.ts"
click node_lab_app "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/lab/LabApp.tsx"
click node_edit_screen "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/edit/EditScreen.tsx"
click node_perform_screen "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/perform/PerformScreen.tsx"
click node_plugins_screen "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/plugins-view/PluginsScreen.tsx"
click node_project_screen "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/project-view/ProjectScreen.tsx"
click node_timeline_preview "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/timeline/TimelinePreview.tsx"
click node_plugin_host "https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/plugins-view/PluginWorkspaceHost.tsx"
click node_play_note_uc "https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/playNote.ts"
click node_record_mic_uc "https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/recordMicSample.ts"
click node_import_project_uc "https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/importProjectBundle.ts"
click node_export_audio_uc "https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/exportProjectAudio.ts"
click node_audio_engine "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/audio/audioEngine.ts"
click node_offline_renderer "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/audio/offlineAudioRenderer.ts"
click node_midi_events "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/midi/events.ts"
click node_project_store "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/project/projectStorage.ts"
click node_plugin_registry "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginRegistry.ts"
click node_plugin_loader "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginLoader.ts"
click node_plugin_storage "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/externalPluginStorage.ts"
click node_plugin_api "https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginApi.ts"
click node_sdk_dts "https://github.com/sebhernandezamoros/mimidi/blob/main/public/mimidi-plugin-sdk.d.ts"
click node_build_plugin "https://github.com/sebhernandezamoros/mimidi/blob/main/scripts/build-plugin.mjs"

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_main_tsx,node_app_tsx,node_app_shell_tsx,node_app_routes,node_app_navigation,node_app_theme toneBlue
class node_lab_app,node_edit_screen,node_perform_screen,node_plugins_screen,node_project_screen,node_timeline_preview toneAmber
class node_play_note_uc,node_record_mic_uc,node_import_project_uc,node_export_audio_uc toneMint
class node_audio_engine,node_offline_renderer,node_midi_events,node_project_store toneRose
class node_plugin_host,node_plugin_registry,node_plugin_loader,node_plugin_storage,node_plugin_api,node_sdk_dts,node_build_plugin toneIndigo
```

## Components

### App Shell

Bootstrap, routing, theme, and global UI concerns.

- [main.tsx](https://github.com/sebhernandezamoros/mimidi/blob/main/src/main.tsx): bootstrap · React entrypoint. · `src/main.tsx`
- [App](https://github.com/sebhernandezamoros/mimidi/blob/main/src/App.tsx): root component · Top-level app composition. · `src/App.tsx`
- [Shell](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/AppShell.tsx): layout shell · Global app layout and mode handling. · `src/app/AppShell.tsx`
- [Routes](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appRoutes.ts): navigation map · App route definitions. · `src/app/appRoutes.ts`
- [Navigation](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appNavigation.ts): menu model · Primary navigation structure. · `src/app/appNavigation.ts`
- [Theme](https://github.com/sebhernandezamoros/mimidi/blob/main/src/app/appTheme.ts): styling system · Shared theme tokens and visual mode. · `src/app/appTheme.ts`

### Presentation

Feature screens and workspaces that orchestrate user interactions.

- [Lab](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/lab/LabApp.tsx): workspace screen · Central music lab workspace. · `src/features/lab/LabApp.tsx`
- [Edit](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/edit/EditScreen.tsx): editor screen · Composition and editing surface. · `src/features/edit/EditScreen.tsx`
- [Perform](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/perform/PerformScreen.tsx): live screen · Live playing and performance surface. · `src/features/perform/PerformScreen.tsx`
- [Plugins](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/plugins-view/PluginsScreen.tsx): plugin screen · Plugin management and hosting UI. · `src/features/plugins-view/PluginsScreen.tsx`
- [Project](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/project-view/ProjectScreen.tsx): project screen · Project overview and control surface. · `src/features/project-view/ProjectScreen.tsx`
- [Timeline](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/timeline/TimelinePreview.tsx): arrangement view · Timeline and clip preview UI. · `src/features/timeline/TimelinePreview.tsx`

### Application

Use-cases that coordinate workflows between UI and engine subsystems.

- [Play Note](https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/playNote.ts): use-case · Triggers note playback. · `src/application/use-cases/playNote.ts`
- [Record Mic](https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/recordMicSample.ts): use-case · Captures microphone input into samples. · `src/application/use-cases/recordMicSample.ts`
- [Import Project](https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/importProjectBundle.ts): use-case · Loads project bundles into the app. · `src/application/use-cases/importProjectBundle.ts`
- [Export Audio](https://github.com/sebhernandezamoros/mimidi/blob/main/src/application/use-cases/exportProjectAudio.ts): use-case · Renders project audio for export. · `src/application/use-cases/exportProjectAudio.ts`

### Engine

Core audio, MIDI, project, and persistence subsystems.

- [Audio Engine](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/audio/audioEngine.ts): sound core · Runtime synthesis and sound playback services. · `src/engine/audio/audioEngine.ts`
- [Renderer](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/audio/offlineAudioRenderer.ts): offline render · Offline audio rendering pipeline. · `src/engine/audio/offlineAudioRenderer.ts`
- [MIDI Events](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/midi/events.ts): event model · Musical event primitives. · `src/engine/midi/events.ts`
- [Project Store](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/project/projectStorage.ts): project persistence · Project state storage and retrieval. · `src/engine/project/projectStorage.ts`

### Plugins

Plugin runtime, storage, API boundary, and authoring artifacts.

- [Host](https://github.com/sebhernandezamoros/mimidi/blob/main/src/features/plugins-view/PluginWorkspaceHost.tsx): runtime shell · Mounts external plugin workspaces inside the app. · `src/features/plugins-view/PluginWorkspaceHost.tsx`
- [Registry](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginRegistry.ts): plugin catalog · Tracks installed and available plugins. · `src/engine/plugins/pluginRegistry.ts`
- [Loader](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginLoader.ts): plugin runtime · Loads plugin packages into memory. · `src/engine/plugins/pluginLoader.ts`
- [Plugin Storage](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/externalPluginStorage.ts): plugin persistence · Stores external plugin packages. · `src/engine/plugins/externalPluginStorage.ts`
- [Plugin API](https://github.com/sebhernandezamoros/mimidi/blob/main/src/engine/plugins/pluginApi.ts): SDK boundary · Contract exposed to plugin workspaces. · `src/engine/plugins/pluginApi.ts`
- [SDK Types](https://github.com/sebhernandezamoros/mimidi/blob/main/public/mimidi-plugin-sdk.d.ts): authoring contract · Typed plugin SDK boundary for authors. · `public/mimidi-plugin-sdk.d.ts`
- [Build Plugin](https://github.com/sebhernandezamoros/mimidi/blob/main/scripts/build-plugin.mjs): tooling · Packages plugin distributions. · `scripts/build-plugin.mjs`

## Connections

- main.tsx → App: boots · Entry point renders the app root.
- App → Shell: composes · Root component delegates to the shell.
- Shell → Routes: uses · Shell routes screens.
- Shell → Navigation: uses · Shell exposes primary navigation.
- Shell → Theme: applies · Shell applies shared theme.
- Shell → Lab: opens · Shell can navigate to the lab workspace.
- Routes → Edit: routes · Route target for editing.
- Routes → Perform: routes · Route target for performance.
- Routes → Plugins: routes · Route target for plugin management.
- Routes → Project: routes · Route target for project control.
- Routes → Timeline: routes · Route target for timeline views.
- Lab → Play Note: triggers · Lab actions invoke playback workflows.
- Lab → Record Mic: triggers · Lab recording uses mic capture workflow.
- Lab → Registry: queries · Lab reads available instruments and plugins.
- Play Note → MIDI Events: creates · Use-case builds musical events.
- Play Note → Audio Engine: plays · Use-case sends events to sound engine.
- Record Mic → Audio Engine: captures · Mic capture depends on audio services.
- Import Project → Project Store: loads · Project import populates persisted state.
- Export Audio → Renderer: renders · Export uses offline audio rendering.
- Renderer → Audio Engine: depends on · Renderer uses core synthesis/runtime logic.
- Project → Project Store: manages · Project UI reflects stored project state.
- Plugins → Host: mounts · Plugin screen hosts external workspaces.
- Host → Plugin API: exposes · Host provides SDK callbacks and services.
- Registry → Loader: uses · Registry resolves loadable plugins.
- Registry → Plugin Storage: persists · Registry reads/writes installed packages.
- Plugin API → SDK Types: contracts · Typed public boundary for authors.
- Build Plugin → SDK Types: packages · Tooling builds distributable plugin artifacts against the SDK.
