How nightcrackle/sipra works
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: register.ts Typed IPC router · sidecar.ts Sidecar manager · server.py Command server · library.ts Library & workspace
Components 21
Electron main
Owns privileged local operations and sidecar lifecycle.
- Electron entry
electron/main.ts - Typed IPC router · Sanitizes UI inputs before privileged operations.
electron/ipc/register.ts - Preload bridge
electron/preload.ts - IPC contracts
shared/ipc.ts - Runtime manager · Installs Python and selects CPU or CUDA dependencies.
electron/services/runtime.ts - Sidecar manager · Launches and restarts the Python command server.
electron/services/sidecar.ts - Job manager · Coordinates cancellable long-running work.
electron/services/jobs.ts - Media service · Mediates renderer-requested media file operations.
electron/services/media.ts - Library & workspace · Organizes sources, stems, metadata, folders, and trash.
electron/services/library.ts
React renderer
- Renderer app
src/App.tsx - UI state store · Tracks library, jobs, runtime setup, and workspace state.
src/state/store.ts - Stem player · Synchronizes stem playback, mix controls, metering, and looping.
src/audio/StemPlayer.ts - Export dialog
src/components/ExportDialog.tsx
Python audio core
Independently runnable local processing sidecar.
- Python CLI entry
python/sipra_core/__main__.py - Command server · Persistent command and event boundary for Electron.
python/sipra_core/server.py - NDJSON contracts
shared/ndjson.ts - Source ingest · Imports local files or optionally downloads YouTube sources.
python/sipra_core/ingest/local.py - Separation engine · Uses a replaceable interface with Demucs as the implementation.
python/sipra_core/separation.py - Analysis & waveforms · Generates waveform and metadata outputs for stems.
python/sipra_core/analysis/analyze.py - Mix renderer · Renders WAV, FLAC, or MP3 mixdowns.
python/sipra_core/mixdown.py
Local data
- JSON local store
electron/services/jsonStore.ts
Connections 27
- 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