# gautham2529/musicforge architecture

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

- Interactive diagram: https://gitdiagram.com/gautham2529/musicforge
- Repository: https://github.com/gautham2529/musicforge

## Overview

MusicForge is a procedural music-generation engine. The principal workflow starts in `main.py`, which creates a `Song`; `Song.generate()` builds harmony, melody, bass, and preview drum patterns, while `Song.export()` uses the arrangement to place section-specific drums and eligible melody or bass before saving MIDI. The graph also preserves documented theory, arranger, effects, and AI capabilities. Effects and AI are described as under development; their runtime wiring is not established by the excerpts, so no connections are asserted for them.

Main entry points: [`song.py`](https://github.com/gautham2529/musicforge/blob/main/song.py) (Song coordinator), [`main.py`](https://github.com/gautham2529/musicforge/blob/main/main.py) (CLI entry), [`melody/melody.py`](https://github.com/gautham2529/musicforge/blob/main/melody/melody.py) (Melody generator), [`bass/bass.py`](https://github.com/gautham2529/musicforge/blob/main/bass/bass.py) (Bass generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Song workflow"]
  node_cli["CLI entry<br/>[main.py]"]
  node_song["Song coordinator<br/>[song.py]"]
end

subgraph group_theory["Music theory"]
  node_scales["Scale generator<br/>[scales.py]"]
  node_chords["Chord generator<br/>[chords.py]"]
  node_progressions["Progression generator<br/>[progression.py]"]
end

subgraph group_composition["Music generation"]
  node_melody["Melody generator<br/>[melody.py]"]
  node_motifs["Motif library<br/>[motifs.py]"]
  node_arp["Arpeggiator<br/>[arp.py]"]
  node_bass["Bass generator<br/>[bass.py]"]
  node_groove["Groove patterns<br/>[groove.py]"]
  node_drums["Drum generators"]
  node_drum_patterns["Drum pattern library<br/>[patterns.py]"]
end

subgraph group_arrangement["Arrangement and export"]
  node_structure["Song structure<br/>[structure.py]"]
  node_sections["Section definitions"]
  node_midi["MIDI exporter<br/>[midi_export.py]"]
end

subgraph group_extensions["Optional extensions"]
  node_velocity["Velocity effects<br/>[velocity.py]"]
  node_humanize["Humanization<br/>[humanize.py]"]
  node_swing["Swing engine<br/>[swing.py]"]
  node_ai_generator["AI composer<br/>[generator.py]"]
  node_ai_trainer["AI trainer<br/>[trainer.py]"]
end

node_user(("User"))
node_daw(("MIDI-compatible DAW"))

node_user -->|"runs"| node_cli
node_cli -->|"creates"| node_song
node_song -->|"generates scale"| node_scales
node_song -->|"generates chords"| node_chords
node_song -->|"generates progression"| node_progressions
node_song -->|"generates melody"| node_melody
node_song -->|"generates bass"| node_bass
node_song -->|"generates patterns"| node_drums
node_melody -->|"uses"| node_motifs
node_bass -->|"initializes"| node_groove
node_drums -->|"selects patterns"| node_drum_patterns
node_song -->|"creates"| node_structure
node_structure -->|"instantiates sections"| node_sections
node_song -->|"adds tracks and saves"| node_midi
node_midi -->|"imports MIDI"| node_daw

click node_cli "https://github.com/gautham2529/musicforge/blob/main/main.py"
click node_song "https://github.com/gautham2529/musicforge/blob/main/song.py"
click node_scales "https://github.com/gautham2529/musicforge/blob/main/harmony/scales.py"
click node_chords "https://github.com/gautham2529/musicforge/blob/main/harmony/chords.py"
click node_progressions "https://github.com/gautham2529/musicforge/blob/main/harmony/progression.py"
click node_melody "https://github.com/gautham2529/musicforge/blob/main/melody/melody.py"
click node_motifs "https://github.com/gautham2529/musicforge/blob/main/melody/motifs.py"
click node_arp "https://github.com/gautham2529/musicforge/blob/main/melody/arp.py"
click node_bass "https://github.com/gautham2529/musicforge/blob/main/bass/bass.py"
click node_groove "https://github.com/gautham2529/musicforge/blob/main/bass/groove.py"
click node_drums "https://github.com/gautham2529/musicforge/tree/main/drums"
click node_drum_patterns "https://github.com/gautham2529/musicforge/blob/main/drums/patterns.py"
click node_structure "https://github.com/gautham2529/musicforge/blob/main/arranger/structure.py"
click node_sections "https://github.com/gautham2529/musicforge/tree/main/arranger"
click node_midi "https://github.com/gautham2529/musicforge/blob/main/midi_export.py"
click node_velocity "https://github.com/gautham2529/musicforge/blob/main/effects/velocity.py"
click node_humanize "https://github.com/gautham2529/musicforge/blob/main/effects/humanize.py"
click node_swing "https://github.com/gautham2529/musicforge/blob/main/effects/swing.py"
click node_ai_generator "https://github.com/gautham2529/musicforge/blob/main/ai/generator.py"
click node_ai_trainer "https://github.com/gautham2529/musicforge/blob/main/ai/trainer.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_cli,node_song,node_user toneBlue
class node_scales,node_chords,node_progressions toneAmber
class node_melody,node_motifs,node_arp,node_bass,node_groove,node_drums,node_drum_patterns toneMint
class node_structure,node_sections,node_midi toneRose
class node_velocity,node_humanize,node_swing,node_ai_generator,node_ai_trainer,node_daw toneIndigo
```

## Components

### Song workflow

- [CLI entry](https://github.com/gautham2529/musicforge/blob/main/main.py): `main.py`
- [Song coordinator](https://github.com/gautham2529/musicforge/blob/main/song.py): `song.py`

### Music theory

- [Scale generator](https://github.com/gautham2529/musicforge/blob/main/harmony/scales.py): `harmony/scales.py`
- [Chord generator](https://github.com/gautham2529/musicforge/blob/main/harmony/chords.py): `harmony/chords.py`
- [Progression generator](https://github.com/gautham2529/musicforge/blob/main/harmony/progression.py): `harmony/progression.py`

### Music generation

- [Melody generator](https://github.com/gautham2529/musicforge/blob/main/melody/melody.py): `melody/melody.py`
- [Motif library](https://github.com/gautham2529/musicforge/blob/main/melody/motifs.py): `melody/motifs.py`
- [Arpeggiator](https://github.com/gautham2529/musicforge/blob/main/melody/arp.py): `melody/arp.py`
- [Bass generator](https://github.com/gautham2529/musicforge/blob/main/bass/bass.py): `bass/bass.py`
- [Groove patterns](https://github.com/gautham2529/musicforge/blob/main/bass/groove.py): `bass/groove.py`
- [Drum generators](https://github.com/gautham2529/musicforge/tree/main/drums): `drums`
- [Drum pattern library](https://github.com/gautham2529/musicforge/blob/main/drums/patterns.py): `drums/patterns.py`

### Arrangement and export

- [Song structure](https://github.com/gautham2529/musicforge/blob/main/arranger/structure.py): `arranger/structure.py`
- [Section definitions](https://github.com/gautham2529/musicforge/tree/main/arranger): `arranger`
- [MIDI exporter](https://github.com/gautham2529/musicforge/blob/main/midi_export.py): `midi_export.py`

### Optional extensions

- [Velocity effects](https://github.com/gautham2529/musicforge/blob/main/effects/velocity.py): `effects/velocity.py`
- [Humanization](https://github.com/gautham2529/musicforge/blob/main/effects/humanize.py): `effects/humanize.py`
- [Swing engine](https://github.com/gautham2529/musicforge/blob/main/effects/swing.py): `effects/swing.py`
- [AI composer](https://github.com/gautham2529/musicforge/blob/main/ai/generator.py): `ai/generator.py`
- [AI trainer](https://github.com/gautham2529/musicforge/blob/main/ai/trainer.py): `ai/trainer.py`

### Other components

- **User**
- **MIDI-compatible DAW**

## Connections

- User → CLI entry: runs (evidence: `README.md`)
- CLI entry → Song coordinator: creates (evidence: `main.py`)
- Song coordinator → Scale generator: generates scale (evidence: `song.py`)
- Song coordinator → Chord generator: generates chords (evidence: `song.py`)
- Song coordinator → Progression generator: generates progression (evidence: `song.py`)
- Song coordinator → Melody generator: generates melody (evidence: `song.py`)
- Song coordinator → Bass generator: generates bass (evidence: `song.py`)
- Song coordinator → Drum generators: generates patterns (evidence: `song.py`)
- Melody generator → Motif library: uses (evidence: `melody/melody.py`)
- Bass generator → Groove patterns: initializes (evidence: `bass/bass.py`)
- Drum generators → Drum pattern library: selects patterns (evidence: `drums/snare.py`)
- Song coordinator → Song structure: creates (evidence: `song.py`)
- Song structure → Section definitions: instantiates sections (evidence: `arranger/structure.py`)
- Song coordinator → MIDI exporter: adds tracks and saves (evidence: `song.py`)
- MIDI exporter → MIDI-compatible DAW: imports MIDI (evidence: `README.md`)
