# dyci2/somax2 architecture

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

- Interactive diagram: https://gitdiagram.com/dyci2/somax2
- Repository: https://github.com/dyci2/somax2

## Overview

Somax 2 is a Max-and-Python system for real-time musical improvisation and composition. A musician supplies MIDI or audio context through Max; the Python runtime manages agents, corpus memory, queries, and scheduling, then produces musical output for Max. Separate corpus-building and classification stages prepare event memories and labels, while features and transforms provide an internal representation and adaptation layer. The README documents multi-agent interaction, manual controls, and a Max library API. Some subsystem links are documented rather than visible in sampled call sites; those are marked dashed.

Main entry points: [`python/somax/somax/runtime/agent.py`](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/agent.py) (Agents), [`python/somax/somax_server.py`](https://github.com/dyci2/somax2/blob/master/python/somax/somax_server.py) (OSC Server), [`python/somax/somax/classification/classifier.py`](https://github.com/dyci2/somax2/blob/master/python/somax/somax/classification/classifier.py) (Classifiers), [`python/somax/somax/corpus_builder/corpus_builder.py`](https://github.com/dyci2/somax2/blob/master/python/somax/somax/corpus_builder/corpus_builder.py) (Corpus Builder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Max Interface"]
  node_max["Max Application"]
  node_maxjs["Max JavaScript"]
  node_server["OSC Server<br/>[somax_server.py]"]
end

subgraph group_memory["Corpus Memory"]
  node_builder["Corpus Builder<br/>[corpus_builder.py]"]
  node_updater["Corpus Updater"]
  node_corpus[("Corpus Memory<br/>[corpus.py]")]
  node_event["Corpus Events<br/>[corpus_event.py]"]
end

subgraph group_generation["Improvisation Runtime"]
  node_agent["Agents<br/>[agent.py]"]
  node_query["Corpus Query"]
  node_player["Player<br/>[player.py]"]
  node_scheduler["Scheduling Handler"]
  node_schedule["Event Scheduler<br/>[scheduler.py]"]
end

subgraph group_analysis["Analysis Model"]
  node_classifier["Classifiers<br/>[classifier.py]"]
  node_features["Feature Analysis<br/>[feature.py]"]
  node_transforms["Event Transforms<br/>[transforms.py]"]
  node_labels["Corpus Labels<br/>[label.py]"]
end

node_musician(("Musician"))

node_musician -.->|"performs into"| node_max
node_max -.->|"controls by OSC"| node_server
node_server -->|"configures"| node_agent
node_server -->|"starts builds"| node_builder
node_server -->|"starts updates"| node_updater
node_agent -->|"configures"| node_builder
node_builder -->|"creates memory"| node_corpus
node_builder -->|"constructs events"| node_event
node_corpus -.->|"stores events"| node_event
node_agent -->|"loads memory"| node_corpus
node_agent -.->|"uses queries"| node_query
node_agent -->|"configures classification"| node_classifier
node_classifier -->|"classifies features"| node_features
node_classifier -->|"selects transforms"| node_transforms
node_classifier -.->|"produces labels"| node_labels
node_agent -.->|"configures scheduling"| node_scheduler
node_scheduler -->|"adds events"| node_schedule
node_scheduler -.->|"schedules events"| node_event
node_agent -.->|"controls playback"| node_player
node_player -.->|"outputs music"| node_max
node_max -.->|"uses helpers"| node_maxjs

click node_maxjs "https://github.com/dyci2/somax2/blob/master/max/somax/javascript/computeMemoryPitchClass.js"
click node_server "https://github.com/dyci2/somax2/blob/master/python/somax/somax_server.py"
click node_builder "https://github.com/dyci2/somax2/blob/master/python/somax/somax/corpus_builder/corpus_builder.py"
click node_updater "https://github.com/dyci2/somax2/blob/master/python/somax/somax/corpus_builder/threaded_corpus_updater.py"
click node_corpus "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus.py"
click node_event "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus_event.py"
click node_agent "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/agent.py"
click node_query "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus_query_manager.py"
click node_player "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/player.py"
click node_scheduler "https://github.com/dyci2/somax2/blob/master/python/somax/somax/scheduler/scheduling_handler.py"
click node_schedule "https://github.com/dyci2/somax2/blob/master/python/somax/somax/scheduler/scheduler.py"
click node_classifier "https://github.com/dyci2/somax2/blob/master/python/somax/somax/classification/classifier.py"
click node_features "https://github.com/dyci2/somax2/blob/master/python/somax/somax/features/feature.py"
click node_transforms "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/transforms.py"
click node_labels "https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/label.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_max,node_maxjs,node_server toneBlue
class node_builder,node_updater,node_corpus,node_event toneAmber
class node_agent,node_query,node_player,node_scheduler,node_schedule toneMint
class node_classifier,node_features,node_transforms,node_labels toneRose
class node_musician toneIndigo
```

## Components

### Max Interface

- **Max Application**
- [Max JavaScript](https://github.com/dyci2/somax2/blob/master/max/somax/javascript/computeMemoryPitchClass.js): `max/somax/javascript/computeMemoryPitchClass.js`
- [OSC Server](https://github.com/dyci2/somax2/blob/master/python/somax/somax_server.py): `python/somax/somax_server.py`

### Corpus Memory

- [Corpus Builder](https://github.com/dyci2/somax2/blob/master/python/somax/somax/corpus_builder/corpus_builder.py): `python/somax/somax/corpus_builder/corpus_builder.py`
- [Corpus Updater](https://github.com/dyci2/somax2/blob/master/python/somax/somax/corpus_builder/threaded_corpus_updater.py): `python/somax/somax/corpus_builder/threaded_corpus_updater.py`
- [Corpus Memory](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus.py): `python/somax/somax/runtime/corpus.py`
- [Corpus Events](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus_event.py): `python/somax/somax/runtime/corpus_event.py`

### Improvisation Runtime

- [Agents](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/agent.py): `python/somax/somax/runtime/agent.py`
- [Corpus Query](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/corpus_query_manager.py): `python/somax/somax/runtime/corpus_query_manager.py`
- [Player](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/player.py): `python/somax/somax/runtime/player.py`
- [Scheduling Handler](https://github.com/dyci2/somax2/blob/master/python/somax/somax/scheduler/scheduling_handler.py): `python/somax/somax/scheduler/scheduling_handler.py`
- [Event Scheduler](https://github.com/dyci2/somax2/blob/master/python/somax/somax/scheduler/scheduler.py): `python/somax/somax/scheduler/scheduler.py`

### Analysis Model

- [Classifiers](https://github.com/dyci2/somax2/blob/master/python/somax/somax/classification/classifier.py): `python/somax/somax/classification/classifier.py`
- [Feature Analysis](https://github.com/dyci2/somax2/blob/master/python/somax/somax/features/feature.py): `python/somax/somax/features/feature.py`
- [Event Transforms](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/transforms.py): `python/somax/somax/runtime/transforms.py`
- [Corpus Labels](https://github.com/dyci2/somax2/blob/master/python/somax/somax/runtime/label.py): `python/somax/somax/runtime/label.py`

### Other components

- **Musician**

## Connections

- Musician → Max Application: performs into
- Max Application → OSC Server: controls by OSC
- OSC Server → Agents: configures (evidence: `python/somax/somax_server.py`)
- OSC Server → Corpus Builder: starts builds (evidence: `python/somax/somax_server.py`)
- OSC Server → Corpus Updater: starts updates (evidence: `python/somax/somax_server.py`)
- Agents → Corpus Builder: configures (evidence: `python/somax/somax/runtime/agent.py`)
- Corpus Builder → Corpus Memory: creates memory (evidence: `python/somax/somax/corpus_builder/corpus_builder.py`)
- Corpus Builder → Corpus Events: constructs events (evidence: `python/somax/somax/corpus_builder/corpus_builder.py`)
- Corpus Memory → Corpus Events: stores events (evidence: `python/somax/somax/runtime/corpus.py`)
- Agents → Corpus Memory: loads memory (evidence: `python/somax/somax/runtime/agent.py`)
- Agents → Corpus Query: uses queries (evidence: `python/somax/somax/runtime/agent.py`)
- Agents → Classifiers: configures classification (evidence: `python/somax/somax/runtime/agent.py`)
- Classifiers → Feature Analysis: classifies features (evidence: `python/somax/somax/classification/classifier.py`)
- Classifiers → Event Transforms: selects transforms (evidence: `python/somax/somax/classification/classifier.py`)
- Classifiers → Corpus Labels: produces labels (evidence: `python/somax/somax/classification/classifier.py`)
- Agents → Scheduling Handler: configures scheduling (evidence: `python/somax/somax/runtime/agent.py`)
- Scheduling Handler → Event Scheduler: adds events (evidence: `python/somax/somax/scheduler/scheduling_handler.py`)
- Scheduling Handler → Corpus Events: schedules events (evidence: `python/somax/somax/scheduler/scheduling_handler.py`)
- Agents → Player: controls playback (evidence: `python/somax/somax/runtime/agent.py`)
- Player → Max Application: outputs music
- Max Application → Max JavaScript: uses helpers
