# sous-labs/songe architecture

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

- Interactive diagram: https://gitdiagram.com/sous-labs/songe
- Repository: https://github.com/sous-labs/songe

## Overview

Songe is a local-model training engine that proxies agent traffic and learns from recorded conversations during idle time. The main path is agent requests through the proxy to a local model server; recorded interactions become lessons and practice scenes, which train and evaluate a LoRA candidate before serving it only when it improves on the user’s own conversations. Quick Dreams, model/server integration, idle scheduling, and optional cloud learning are separate capabilities. The graph uses README workflow statements and source-index references; several implementation links are therefore documented rather than verified from excerpts.

Main entry points: [`src/songe/schedule.py`](https://github.com/sous-labs/songe/blob/main/src/songe/schedule.py) (Idle scheduler), [`src/songe/backends/torch.py`](https://github.com/sous-labs/songe/blob/main/src/songe/backends/torch.py) (LoRA training), [`src/songe/proxy.py`](https://github.com/sous-labs/songe/blob/main/src/songe/proxy.py) (OpenAI proxy), [`src/songe/log.py`](https://github.com/sous-labs/songe/blob/main/src/songe/log.py) (Conversation records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_serving["Local serving"]
  node_proxy["OpenAI proxy<br/>[proxy.py]"]
  node_model_server["Model servers"]
  node_model_discovery["Model discovery<br/>[discovery.py]"]
  node_model_registry["Model registry<br/>[registry.py]"]
  node_conversation_store[("Conversation records<br/>[log.py]")]
end

subgraph group_learning["Learning cycle"]
  node_reading["Lesson extraction"]
  node_lessons["Lesson selection<br/>[lessons.py]"]
  node_practice["Practice scenes<br/>[pool.py]"]
  node_training["LoRA training<br/>[torch.py]"]
  node_calibration["Capacity calibration<br/>[calibrate.py]"]
  node_candidate[("Candidate artifacts<br/>[storage.py]")]
  node_evaluation["Candidate checking<br/>[worker.py]"]
  node_activation["Version activation<br/>[swap.py]"]
end

subgraph group_operations["Runtime operations"]
  node_scheduler["Idle scheduler<br/>[schedule.py]"]
  node_memory_guard["Memory guard<br/>[memory.py]"]
  node_upstream_protection["Server protection<br/>[protection.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_experience["User experience"]
  node_quick_dream["Quick Dream<br/>[quick.py]"]
  node_dashboard["Dashboard<br/>[next.js]"]
end

subgraph group_optional["Optional cloud"]
  node_cloud_learning["Cloud learning"]
end

node_agent(("Agent"))
node_cloud_service["Chosen cloud model"]

node_agent -->|"sends requests"| node_proxy
node_proxy -->|"forwards traffic"| node_model_server
node_proxy -->|"records interactions"| node_conversation_store
node_conversation_store -->|"provides conversations"| node_reading
node_reading -->|"extracts lessons"| node_lessons
node_lessons -->|"informs practice"| node_practice
node_practice -->|"trains on scenes"| node_training
node_calibration -->|"sizes training"| node_training
node_training -->|"produces adapter"| node_candidate
node_candidate -->|"supplies candidate"| node_evaluation
node_evaluation -->|"approves better version"| node_activation
node_scheduler -->|"starts idle work"| node_calibration
node_scheduler -->|"runs during idle"| node_training
node_memory_guard -.->|"constrains work"| node_scheduler
node_activation -.->|"updates served version"| node_model_registry
node_model_discovery -->|"identifies models"| node_model_registry
node_upstream_protection -->|"protects model weights"| node_model_server
node_config -->|"configures runtime"| node_scheduler
node_agent -.->|"requests preferences"| node_quick_dream
node_dashboard -->|"requests a Dream"| node_scheduler
node_cloud_learning -.->|"asks nightly"| node_cloud_service

click node_proxy "https://github.com/sous-labs/songe/blob/main/src/songe/proxy.py"
click node_model_server "https://github.com/sous-labs/songe/tree/main/src/songe/upstream"
click node_model_discovery "https://github.com/sous-labs/songe/blob/main/src/songe/models/discovery.py"
click node_model_registry "https://github.com/sous-labs/songe/blob/main/src/songe/models/registry.py"
click node_conversation_store "https://github.com/sous-labs/songe/blob/main/src/songe/log.py"
click node_reading "https://github.com/sous-labs/songe/tree/main/src/songe/reading"
click node_lessons "https://github.com/sous-labs/songe/blob/main/src/songe/sleep/lessons.py"
click node_practice "https://github.com/sous-labs/songe/blob/main/src/songe/practice/pool.py"
click node_training "https://github.com/sous-labs/songe/blob/main/src/songe/backends/torch.py"
click node_calibration "https://github.com/sous-labs/songe/blob/main/src/songe/sleep/calibrate.py"
click node_candidate "https://github.com/sous-labs/songe/blob/main/src/songe/artifacts/storage.py"
click node_evaluation "https://github.com/sous-labs/songe/blob/main/src/songe/sleep/worker.py"
click node_activation "https://github.com/sous-labs/songe/blob/main/src/songe/sleep/swap.py"
click node_scheduler "https://github.com/sous-labs/songe/blob/main/src/songe/schedule.py"
click node_memory_guard "https://github.com/sous-labs/songe/blob/main/src/songe/memory.py"
click node_upstream_protection "https://github.com/sous-labs/songe/blob/main/src/songe/upstream/protection.py"
click node_config "https://github.com/sous-labs/songe/blob/main/src/songe/config.py"
click node_quick_dream "https://github.com/sous-labs/songe/blob/main/src/songe/quick.py"
click node_dashboard "https://github.com/sous-labs/songe/blob/main/src/songe/ui/next.js"
click node_cloud_learning "https://github.com/sous-labs/songe/tree/main/src/songe/cloud"

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_proxy,node_model_server,node_model_discovery,node_model_registry,node_conversation_store toneBlue
class node_reading,node_lessons,node_practice,node_training,node_calibration,node_candidate,node_evaluation,node_activation toneAmber
class node_scheduler,node_memory_guard,node_upstream_protection,node_config toneMint
class node_quick_dream,node_dashboard toneRose
class node_cloud_learning,node_agent,node_cloud_service toneIndigo
```

## Components

### Local serving

- [OpenAI proxy](https://github.com/sous-labs/songe/blob/main/src/songe/proxy.py): `src/songe/proxy.py`
- [Model servers](https://github.com/sous-labs/songe/tree/main/src/songe/upstream): `src/songe/upstream`
- [Model discovery](https://github.com/sous-labs/songe/blob/main/src/songe/models/discovery.py): `src/songe/models/discovery.py`
- [Model registry](https://github.com/sous-labs/songe/blob/main/src/songe/models/registry.py): `src/songe/models/registry.py`
- [Conversation records](https://github.com/sous-labs/songe/blob/main/src/songe/log.py): `src/songe/log.py`

### Learning cycle

- [Lesson extraction](https://github.com/sous-labs/songe/tree/main/src/songe/reading): `src/songe/reading`
- [Lesson selection](https://github.com/sous-labs/songe/blob/main/src/songe/sleep/lessons.py): `src/songe/sleep/lessons.py`
- [Practice scenes](https://github.com/sous-labs/songe/blob/main/src/songe/practice/pool.py): `src/songe/practice/pool.py`
- [LoRA training](https://github.com/sous-labs/songe/blob/main/src/songe/backends/torch.py): `src/songe/backends/torch.py`
- [Capacity calibration](https://github.com/sous-labs/songe/blob/main/src/songe/sleep/calibrate.py): `src/songe/sleep/calibrate.py`
- [Candidate artifacts](https://github.com/sous-labs/songe/blob/main/src/songe/artifacts/storage.py): `src/songe/artifacts/storage.py`
- [Candidate checking](https://github.com/sous-labs/songe/blob/main/src/songe/sleep/worker.py): `src/songe/sleep/worker.py`
- [Version activation](https://github.com/sous-labs/songe/blob/main/src/songe/sleep/swap.py): `src/songe/sleep/swap.py`

### Runtime operations

- [Idle scheduler](https://github.com/sous-labs/songe/blob/main/src/songe/schedule.py): `src/songe/schedule.py`
- [Memory guard](https://github.com/sous-labs/songe/blob/main/src/songe/memory.py): `src/songe/memory.py`
- [Server protection](https://github.com/sous-labs/songe/blob/main/src/songe/upstream/protection.py): `src/songe/upstream/protection.py`
- [Runtime configuration](https://github.com/sous-labs/songe/blob/main/src/songe/config.py): `src/songe/config.py`

### User experience

- [Quick Dream](https://github.com/sous-labs/songe/blob/main/src/songe/quick.py): `src/songe/quick.py`
- [Dashboard](https://github.com/sous-labs/songe/blob/main/src/songe/ui/next.js): `src/songe/ui/next.js`

### Optional cloud

- [Cloud learning](https://github.com/sous-labs/songe/tree/main/src/songe/cloud): `src/songe/cloud`

### Other components

- **Agent**
- **Chosen cloud model**

## Connections

- Agent → OpenAI proxy: sends requests (evidence: `README.md`)
- OpenAI proxy → Model servers: forwards traffic (evidence: `README.md`)
- OpenAI proxy → Conversation records: records interactions (evidence: `README.md`)
- Conversation records → Lesson extraction: provides conversations (evidence: `README.md`)
- Lesson extraction → Lesson selection: extracts lessons (evidence: `README.md`)
- Lesson selection → Practice scenes: informs practice (evidence: `README.md`)
- Practice scenes → LoRA training: trains on scenes (evidence: `README.md`)
- Capacity calibration → LoRA training: sizes training (evidence: `README.md`)
- LoRA training → Candidate artifacts: produces adapter (evidence: `README.md`)
- Candidate artifacts → Candidate checking: supplies candidate (evidence: `README.md`)
- Candidate checking → Version activation: approves better version (evidence: `README.md`)
- Idle scheduler → Capacity calibration: starts idle work (evidence: `README.md`)
- Idle scheduler → LoRA training: runs during idle (evidence: `README.md`)
- Memory guard → Idle scheduler: constrains work (evidence: `src/songe/schedule.py`)
- Version activation → Model registry: updates served version
- Model discovery → Model registry: identifies models (evidence: `src/songe/models/registry.py`)
- Server protection → Model servers: protects model weights (evidence: `src/songe/artifacts/storage.py`)
- Runtime configuration → Idle scheduler: configures runtime (evidence: `src/songe/schedule.py`)
- Agent → Quick Dream: requests preferences
- Dashboard → Idle scheduler: requests a Dream (evidence: `README.md`)
- Cloud learning → Chosen cloud model: asks nightly (evidence: `README.md`)
