# nightcrackle/sipra architecture

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

- Interactive diagram: https://gitdiagram.com/nightcrackle/sipra
- Repository: https://github.com/nightcrackle/sipra

## Overview

#### Purpose and entry points
Sipra is a local-first desktop audio-stem separator and mixing workspace. It accepts local audio or optional YouTube downloads, separates tracks with Demucs, analyzes metadata, stores a local library, and supports playback and export. Electron starts at `electron/main.ts`; the React renderer starts at `src/main.tsx` and `src/App.tsx`; the Python core is also independently runnable through `python/sipra_core/__main__.py`.

#### Electron process boundary and IPC
Electron’s main process owns filesystem access, persistent state, job lifecycle, runtime installation, and the Python sidecar. The renderer is deliberately constrained through preload-exposed IPC; shared contracts keep both sides aligned.
- `electron/main.ts`
- `electron/preload.ts`
- `electron/ipc/register.ts`
- `shared/ipc.ts`
- `electron/ipc/sanitise.ts`

Control flow is renderer action → typed IPC → main-process service → sidecar/filesystem → IPC events/results back to renderer. IPC sanitization is a trust boundary between UI-provided values and local OS operations.

#### Python audio-core sidecar
The Python package provides the command protocol/server used by Electron and CLI entry points. It performs ingest, separation, waveform generation, audio analysis, and mix rendering. `server.py` and `protocol.py` form the persistent sidecar command/event boundary; NDJSON-related contracts are shared with TypeScript.
- `python/sipra_core/server.py`
- `python/sipra_core/protocol.py`
- `python/sipra_core/__main__.py`
- `shared/ndjson.ts`

The core runs locally using PyTorch/Demucs, librosa, and pyloudnorm. Model weights are downloaded on first use; optional `yt-dlp` is the only link-ingest dependency/network path.

#### Separation, ingest, and analysis pipeline
A source enters via local import or optional YouTube ingest, then is decoded and passed to a pluggable separation engine. The resulting named stems feed waveform generation, metadata analysis, and workspace/library records. The engine interface isolates Demucs so another model can replace it without changing callers.
- `python/sipra_core/ingest/local.py`
- `python/sipra_core/ingest/youtube.py`
- `python/sipra_core/separation.py`
- `python/sipra_core/engines/base.py`
- `python/sipra_core/engines/demucs_engine.py`
- `python/sipra_core/analysis/analyze.py`

#### Runtime and job orchestration
The main process installs and validates the Python runtime, selects CPU versus CUDA dependencies, launches/restarts the sidecar, and manages cancellable long-running jobs. Cancellation may restart the sidecar to recover from stalled native calls; workspace/library state remains separate.
- `electron/services/runtime.ts`
- `electron/services/sidecar.ts`
- `electron/services/jobs.ts`
- `python/requirements/torch-cpu.txt`
- `python/requirements/torch-cuda.txt`

#### Local persistence and media ownership
All user content is local. Library/workspace services organize imported sources, generated stems, metadata, folders, trash retention, and application settings through JSON-backed storage. Media service mediates file operations rather than exposing arbitrary filesystem access to the renderer.
- `electron/services/library.ts`
- `electron/services/workspace.ts`
- `electron/services/media.ts`
- `electron/services/jsonStore.ts`
- `electron/services/settings.ts`
- `shared/library.ts`

#### Renderer workspace, playback, and export
React state drives library navigation, job visibility, runtime setup, and the stem workspace. Browser-side audio playback handles synchronized stem gain, mute/solo/selection backing level, looping, metering, and viewport behavior. Export parameters are sent to the core, where mixdown renders WAV, FLAC, or MP3.
- `src/state/store.ts`
- `src/components/Workspace.tsx`
- `src/audio/StemPlayer.ts`
- `src/components/WaveformCanvas.tsx`
- `src/components/ExportDialog.tsx`
- `python/sipra_core/mixdown.py`

#### Packaging and deployment
The shipped product is a Windows Electron application bundling the JS app and managed Python runtime/binaries. Development uses Vite plus Electron; production packaging is configured separately.
- `electron-builder.yml`
- `vite.config.ts`
- `scripts/dev.mjs`
- `scripts/fetch-binaries.mjs`
- `python/pyproject.toml`

Main entry points: [`electron/ipc/register.ts`](https://github.com/nightcrackle/sipra/blob/main/electron/ipc/register.ts) (Typed IPC router), [`electron/services/sidecar.ts`](https://github.com/nightcrackle/sipra/blob/main/electron/services/sidecar.ts) (Sidecar manager), [`python/sipra_core/server.py`](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/server.py) (Command server), [`electron/services/library.ts`](https://github.com/nightcrackle/sipra/blob/main/electron/services/library.ts) (Library & workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_electron["Electron main"]
  node_electron_main["Electron entry<br/>main process<br/>[main.ts]"]
  node_ipc["Typed IPC router<br/>IPC boundary<br/>[register.ts]"]
  node_preload["Preload bridge<br/>renderer bridge<br/>[preload.ts]"]
  node_ipc_contracts["IPC contracts<br/>shared types<br/>[ipc.ts]"]
  node_runtime["Runtime manager<br/>runtime service<br/>[runtime.ts]"]
  node_sidecar["Sidecar manager<br/>process service<br/>[sidecar.ts]"]
  node_jobs["Job manager<br/>job service<br/>[jobs.ts]"]
  node_media["Media service<br/>file service<br/>[media.ts]"]
  node_library_workspace["Library &amp; workspace<br/>state services<br/>[library.ts]"]
end

subgraph group_renderer["React renderer"]
  node_renderer_app["Renderer app<br/>React application<br/>[App.tsx]"]
  node_renderer_store["UI state store<br/>React state<br/>[store.ts]"]
  node_stem_player["Stem player<br/>browser audio<br/>[StemPlayer.ts]"]
  node_export_dialog["Export dialog<br/>React feature<br/>[ExportDialog.tsx]"]
end

subgraph group_python["Python audio core"]
  node_python_cli["Python CLI entry<br/>CLI entry point<br/>[__main__.py]"]
  node_python_server["Command server<br/>sidecar protocol<br/>[server.py]"]
  node_ndjson["NDJSON contracts<br/>shared protocol<br/>[ndjson.ts]"]
  node_ingest["Source ingest<br/>audio pipeline<br/>[local.py]"]
  node_separation["Separation engine<br/>pluggable engine<br/>[separation.py]"]
  node_analysis["Analysis &amp; waveforms<br/>audio pipeline<br/>[analyze.py]"]
  node_mixdown["Mix renderer<br/>audio export<br/>[mixdown.py]"]
end

subgraph group_storage["Local data"]
  node_json_store[("JSON local store<br/>persistence<br/>[jsonStore.ts]")]
end

node_electron_main -->|"registers"| node_ipc
node_electron_main -->|"initializes"| node_runtime
node_electron_main -->|"owns"| node_sidecar
node_preload -->|"invokes"| node_ipc
node_ipc_contracts -->|"types"| node_preload
node_ipc_contracts -->|"types"| node_ipc
node_renderer_app -->|"uses"| node_renderer_store
node_renderer_app -->|"uses IPC"| node_preload
node_renderer_store -->|"drives"| node_stem_player
node_export_dialog -->|"submits export"| node_preload
node_ipc -->|"starts and cancels"| node_jobs
node_ipc -->|"requests files"| node_media
node_ipc -->|"updates state"| node_library_workspace
node_jobs -->|"dispatches work"| node_sidecar
node_runtime -->|"provisions runtime"| node_sidecar
node_sidecar -->|"NDJSON commands/events"| node_python_server
node_ndjson -->|"defines protocol"| node_sidecar
node_ndjson -->|"defines protocol"| node_python_server
node_python_cli -->|"runs protocol"| node_python_server
node_python_server -->|"processes sources"| node_ingest
node_ingest -->|"decoded audio"| node_separation
node_separation -->|"named stems"| node_analysis
node_python_server -->|"renders exports"| node_mixdown
node_library_workspace -->|"persists records"| node_json_store
node_media -->|"manages owned media"| node_library_workspace
node_analysis -->|"stores stem metadata"| node_library_workspace
node_sidecar -->|"returns job results"| node_library_workspace

click node_electron_main "https://github.com/nightcrackle/sipra/blob/main/electron/main.ts"
click node_ipc "https://github.com/nightcrackle/sipra/blob/main/electron/ipc/register.ts"
click node_preload "https://github.com/nightcrackle/sipra/blob/main/electron/preload.ts"
click node_ipc_contracts "https://github.com/nightcrackle/sipra/blob/main/shared/ipc.ts"
click node_runtime "https://github.com/nightcrackle/sipra/blob/main/electron/services/runtime.ts"
click node_sidecar "https://github.com/nightcrackle/sipra/blob/main/electron/services/sidecar.ts"
click node_jobs "https://github.com/nightcrackle/sipra/blob/main/electron/services/jobs.ts"
click node_media "https://github.com/nightcrackle/sipra/blob/main/electron/services/media.ts"
click node_library_workspace "https://github.com/nightcrackle/sipra/blob/main/electron/services/library.ts"
click node_json_store "https://github.com/nightcrackle/sipra/blob/main/electron/services/jsonStore.ts"
click node_renderer_app "https://github.com/nightcrackle/sipra/blob/main/src/App.tsx"
click node_renderer_store "https://github.com/nightcrackle/sipra/blob/main/src/state/store.ts"
click node_stem_player "https://github.com/nightcrackle/sipra/blob/main/src/audio/StemPlayer.ts"
click node_export_dialog "https://github.com/nightcrackle/sipra/blob/main/src/components/ExportDialog.tsx"
click node_python_cli "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/__main__.py"
click node_python_server "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/server.py"
click node_ndjson "https://github.com/nightcrackle/sipra/blob/main/shared/ndjson.ts"
click node_ingest "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/ingest/local.py"
click node_separation "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/separation.py"
click node_analysis "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/analysis/analyze.py"
click node_mixdown "https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/mixdown.py"

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_electron_main,node_ipc,node_preload,node_ipc_contracts,node_runtime,node_sidecar,node_jobs,node_media,node_library_workspace toneBlue
class node_renderer_app,node_renderer_store,node_stem_player,node_export_dialog toneAmber
class node_python_cli,node_python_server,node_ndjson,node_ingest,node_separation,node_analysis,node_mixdown toneMint
class node_json_store toneRose
```

## Components

### Electron main

Owns privileged local operations and sidecar lifecycle.

- [Electron entry](https://github.com/nightcrackle/sipra/blob/main/electron/main.ts): main process · `electron/main.ts`
- [Typed IPC router](https://github.com/nightcrackle/sipra/blob/main/electron/ipc/register.ts): IPC boundary · Sanitizes UI inputs before privileged operations. · `electron/ipc/register.ts`
- [Preload bridge](https://github.com/nightcrackle/sipra/blob/main/electron/preload.ts): renderer bridge · `electron/preload.ts`
- [IPC contracts](https://github.com/nightcrackle/sipra/blob/main/shared/ipc.ts): shared types · `shared/ipc.ts`
- [Runtime manager](https://github.com/nightcrackle/sipra/blob/main/electron/services/runtime.ts): runtime service · Installs Python and selects CPU or CUDA dependencies. · `electron/services/runtime.ts`
- [Sidecar manager](https://github.com/nightcrackle/sipra/blob/main/electron/services/sidecar.ts): process service · Launches and restarts the Python command server. · `electron/services/sidecar.ts`
- [Job manager](https://github.com/nightcrackle/sipra/blob/main/electron/services/jobs.ts): job service · Coordinates cancellable long-running work. · `electron/services/jobs.ts`
- [Media service](https://github.com/nightcrackle/sipra/blob/main/electron/services/media.ts): file service · Mediates renderer-requested media file operations. · `electron/services/media.ts`
- [Library & workspace](https://github.com/nightcrackle/sipra/blob/main/electron/services/library.ts): state services · Organizes sources, stems, metadata, folders, and trash. · `electron/services/library.ts`

### React renderer

- [Renderer app](https://github.com/nightcrackle/sipra/blob/main/src/App.tsx): React application · `src/App.tsx`
- [UI state store](https://github.com/nightcrackle/sipra/blob/main/src/state/store.ts): React state · Tracks library, jobs, runtime setup, and workspace state. · `src/state/store.ts`
- [Stem player](https://github.com/nightcrackle/sipra/blob/main/src/audio/StemPlayer.ts): browser audio · Synchronizes stem playback, mix controls, metering, and looping. · `src/audio/StemPlayer.ts`
- [Export dialog](https://github.com/nightcrackle/sipra/blob/main/src/components/ExportDialog.tsx): React feature · `src/components/ExportDialog.tsx`

### Python audio core

Independently runnable local processing sidecar.

- [Python CLI entry](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/__main__.py): CLI entry point · `python/sipra_core/__main__.py`
- [Command server](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/server.py): sidecar protocol · Persistent command and event boundary for Electron. · `python/sipra_core/server.py`
- [NDJSON contracts](https://github.com/nightcrackle/sipra/blob/main/shared/ndjson.ts): shared protocol · `shared/ndjson.ts`
- [Source ingest](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/ingest/local.py): audio pipeline · Imports local files or optionally downloads YouTube sources. · `python/sipra_core/ingest/local.py`
- [Separation engine](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/separation.py): pluggable engine · Uses a replaceable interface with Demucs as the implementation. · `python/sipra_core/separation.py`
- [Analysis & waveforms](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/analysis/analyze.py): audio pipeline · Generates waveform and metadata outputs for stems. · `python/sipra_core/analysis/analyze.py`
- [Mix renderer](https://github.com/nightcrackle/sipra/blob/main/python/sipra_core/mixdown.py): audio export · Renders WAV, FLAC, or MP3 mixdowns. · `python/sipra_core/mixdown.py`

### Local data

- [JSON local store](https://github.com/nightcrackle/sipra/blob/main/electron/services/jsonStore.ts): persistence · `electron/services/jsonStore.ts`

## Connections

- Electron entry → Typed IPC router: registers
- Electron entry → Runtime manager: initializes
- Electron entry → Sidecar manager: owns
- Preload bridge → Typed IPC router: invokes · Constrained renderer access to privileged operations.
- IPC contracts → Preload bridge: types
- IPC contracts → Typed IPC router: types
- Renderer app → UI state store: uses
- Renderer app → Preload bridge: uses IPC
- UI state store → Stem player: drives
- Export dialog → Preload bridge: submits export
- Typed IPC router → Job manager: starts and cancels
- Typed IPC router → Media service: requests files
- Typed IPC router → Library & workspace: updates state
- Job manager → Sidecar manager: dispatches work · May trigger restart on stalled cancellation.
- Runtime manager → Sidecar manager: provisions runtime
- Sidecar manager → Command server: NDJSON commands/events
- NDJSON contracts → Sidecar manager: defines protocol
- NDJSON contracts → Command server: defines protocol
- Python CLI entry → Command server: runs protocol
- Command server → Source ingest: processes sources
- Source ingest → Separation engine: decoded audio
- Separation engine → Analysis & waveforms: named stems
- Command server → Mix renderer: renders exports
- Library & workspace → JSON local store: persists records
- Media service → Library & workspace: manages owned media
- Analysis & waveforms → Library & workspace: stores stem metadata
- Sidecar manager → Library & workspace: returns job results
