# kojix2/moleflow architecture

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

- Interactive diagram: https://gitdiagram.com/kojix2/moleflow
- Repository: https://github.com/kojix2/moleflow

## Overview

Moleflow is a Crystal MinKNOW Read Until simulator. Its main workflow loads configuration, creates synthetic or replayed nanopore signals, and either streams them over gRPC for client actions or generates them offline; optional recording and POD5 preparation support replay workflows. The GUI edits settings and launches the CLI. The README documents these capabilities, but the sampled source excerpts are Python interoperability tests rather than Crystal runtime code, so internal call relationships are limited to documented links.

Main entry points: [`src/gui/launcher.cr`](https://github.com/kojix2/moleflow/blob/main/src/gui/launcher.cr) (GUI launcher), [`src/main.cr`](https://github.com/kojix2/moleflow/blob/main/src/main.cr) (Moleflow CLI), [`src/moleflow/source.cr`](https://github.com/kojix2/moleflow/blob/main/src/moleflow/source.cr) (Signal sources), [`src/moleflow/api.cr`](https://github.com/kojix2/moleflow/blob/main/src/moleflow/api.cr) (gRPC services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Signal simulation"]
  node_cli["Moleflow CLI<br/>[main.cr]"]
  node_config["Configuration<br/>[config.cr]"]
  node_application["Application<br/>[application.cr]"]
  node_engine["Simulation engine<br/>[engine.cr]"]
  node_source["Signal sources<br/>[source.cr]"]
  node_molecule["Molecule model<br/>[molecule.cr]"]
  node_noise["Signal noise<br/>[noise.cr]"]
  node_model["Signal model<br/>[model.cr]"]
  node_workers["Worker pool<br/>[worker_pool.cr]"]
end

subgraph group_streaming["Live streaming"]
  node_api["gRPC services<br/>[api.cr]"]
  node_protocol["Protocol handling<br/>[protocol.cr]"]
  node_session["Live session<br/>[live_session.cr]"]
  node_encoder["Response encoding"]
  node_settings["Stream settings<br/>[stream_settings.cr]"]
  node_async["Async output<br/>[async_output.cr]"]
end

subgraph group_recording["Recording and replay"]
  node_output["Output handling<br/>[output.cr]"]
  node_recording["Read recording<br/>[recording.cr]"]
  node_formats["Signal formats<br/>[formats.cr]"]
  node_pod5["POD5 preparation<br/>[pod5.sh]"]
end

subgraph group_gui["GUI controls"]
  node_gui["GUI launcher<br/>[launcher.cr]"]
  node_gui_model["GUI settings<br/>[model.cr]"]
  node_gui_profile["GUI profiles<br/>[profile.cr]"]
  node_gui_runner["CLI runner<br/>[runner.cr]"]
  node_gui_i18n["Localization<br/>[i18n.cr]"]
end

node_operator(("Operator"))
node_client(("gRPC client"))

node_operator -->|"runs"| node_cli
node_cli -->|"loads settings"| node_config
node_cli -.->|"starts"| node_application
node_application -.->|"runs simulation"| node_engine
node_engine -->|"generates or replays"| node_source
node_client -->|"opens live reads"| node_api
node_api -.->|"serves session"| node_session
node_client -->|"sends actions"| node_api
node_cli -->|"generates offline"| node_output
node_output -->|"records signals"| node_recording
node_source -->|"replays raw int16"| node_formats
node_operator -->|"prepares POD5"| node_pod5
node_pod5 -->|"prepares replay input"| node_source
node_operator -->|"opens"| node_gui
node_gui -.->|"edits settings"| node_gui_model
node_gui -.->|"configures profiles"| node_gui_profile
node_gui -->|"offers languages"| node_gui_i18n
node_gui -->|"launches CLI"| node_gui_runner
node_gui_runner -->|"starts sibling"| node_cli

click node_cli "https://github.com/kojix2/moleflow/blob/main/src/main.cr"
click node_config "https://github.com/kojix2/moleflow/blob/main/src/moleflow/config.cr"
click node_application "https://github.com/kojix2/moleflow/blob/main/src/moleflow/application.cr"
click node_engine "https://github.com/kojix2/moleflow/blob/main/src/moleflow/engine.cr"
click node_source "https://github.com/kojix2/moleflow/blob/main/src/moleflow/source.cr"
click node_molecule "https://github.com/kojix2/moleflow/blob/main/src/moleflow/molecule.cr"
click node_noise "https://github.com/kojix2/moleflow/blob/main/src/moleflow/noise.cr"
click node_model "https://github.com/kojix2/moleflow/blob/main/src/moleflow/model.cr"
click node_workers "https://github.com/kojix2/moleflow/blob/main/src/moleflow/worker_pool.cr"
click node_api "https://github.com/kojix2/moleflow/blob/main/src/moleflow/api.cr"
click node_protocol "https://github.com/kojix2/moleflow/blob/main/src/moleflow/protocol.cr"
click node_session "https://github.com/kojix2/moleflow/blob/main/src/moleflow/live_session.cr"
click node_encoder "https://github.com/kojix2/moleflow/blob/main/src/moleflow/response_encoder.cr"
click node_settings "https://github.com/kojix2/moleflow/blob/main/src/moleflow/stream_settings.cr"
click node_async "https://github.com/kojix2/moleflow/blob/main/src/moleflow/async_output.cr"
click node_output "https://github.com/kojix2/moleflow/blob/main/src/moleflow/output.cr"
click node_recording "https://github.com/kojix2/moleflow/blob/main/src/moleflow/recording.cr"
click node_formats "https://github.com/kojix2/moleflow/blob/main/src/moleflow/formats.cr"
click node_pod5 "https://github.com/kojix2/moleflow/blob/main/scripts/pod5.sh"
click node_gui "https://github.com/kojix2/moleflow/blob/main/src/gui/launcher.cr"
click node_gui_model "https://github.com/kojix2/moleflow/blob/main/src/gui/model.cr"
click node_gui_profile "https://github.com/kojix2/moleflow/blob/main/src/gui/profile.cr"
click node_gui_runner "https://github.com/kojix2/moleflow/blob/main/src/gui/runner.cr"
click node_gui_i18n "https://github.com/kojix2/moleflow/blob/main/src/gui/i18n.cr"

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_config,node_application,node_engine,node_source,node_molecule,node_noise,node_model,node_workers,node_client toneBlue
class node_api,node_protocol,node_session,node_encoder,node_settings,node_async toneAmber
class node_output,node_recording,node_formats,node_pod5 toneMint
class node_gui,node_gui_model,node_gui_profile,node_gui_runner,node_gui_i18n toneRose
class node_operator toneIndigo
```

## Components

### Signal simulation

- [Moleflow CLI](https://github.com/kojix2/moleflow/blob/main/src/main.cr): `src/main.cr`
- [Configuration](https://github.com/kojix2/moleflow/blob/main/src/moleflow/config.cr): `src/moleflow/config.cr`
- [Application](https://github.com/kojix2/moleflow/blob/main/src/moleflow/application.cr): `src/moleflow/application.cr`
- [Simulation engine](https://github.com/kojix2/moleflow/blob/main/src/moleflow/engine.cr): `src/moleflow/engine.cr`
- [Signal sources](https://github.com/kojix2/moleflow/blob/main/src/moleflow/source.cr): `src/moleflow/source.cr`
- [Molecule model](https://github.com/kojix2/moleflow/blob/main/src/moleflow/molecule.cr): `src/moleflow/molecule.cr`
- [Signal noise](https://github.com/kojix2/moleflow/blob/main/src/moleflow/noise.cr): `src/moleflow/noise.cr`
- [Signal model](https://github.com/kojix2/moleflow/blob/main/src/moleflow/model.cr): `src/moleflow/model.cr`
- [Worker pool](https://github.com/kojix2/moleflow/blob/main/src/moleflow/worker_pool.cr): `src/moleflow/worker_pool.cr`

### Live streaming

- [gRPC services](https://github.com/kojix2/moleflow/blob/main/src/moleflow/api.cr): `src/moleflow/api.cr`
- [Protocol handling](https://github.com/kojix2/moleflow/blob/main/src/moleflow/protocol.cr): `src/moleflow/protocol.cr`
- [Live session](https://github.com/kojix2/moleflow/blob/main/src/moleflow/live_session.cr): `src/moleflow/live_session.cr`
- [Response encoding](https://github.com/kojix2/moleflow/blob/main/src/moleflow/response_encoder.cr): `src/moleflow/response_encoder.cr`
- [Stream settings](https://github.com/kojix2/moleflow/blob/main/src/moleflow/stream_settings.cr): `src/moleflow/stream_settings.cr`
- [Async output](https://github.com/kojix2/moleflow/blob/main/src/moleflow/async_output.cr): `src/moleflow/async_output.cr`

### Recording and replay

- [Output handling](https://github.com/kojix2/moleflow/blob/main/src/moleflow/output.cr): `src/moleflow/output.cr`
- [Read recording](https://github.com/kojix2/moleflow/blob/main/src/moleflow/recording.cr): `src/moleflow/recording.cr`
- [Signal formats](https://github.com/kojix2/moleflow/blob/main/src/moleflow/formats.cr): `src/moleflow/formats.cr`
- [POD5 preparation](https://github.com/kojix2/moleflow/blob/main/scripts/pod5.sh): `scripts/pod5.sh`

### GUI controls

- [GUI launcher](https://github.com/kojix2/moleflow/blob/main/src/gui/launcher.cr): `src/gui/launcher.cr`
- [GUI settings](https://github.com/kojix2/moleflow/blob/main/src/gui/model.cr): `src/gui/model.cr`
- [GUI profiles](https://github.com/kojix2/moleflow/blob/main/src/gui/profile.cr): `src/gui/profile.cr`
- [CLI runner](https://github.com/kojix2/moleflow/blob/main/src/gui/runner.cr): `src/gui/runner.cr`
- [Localization](https://github.com/kojix2/moleflow/blob/main/src/gui/i18n.cr): `src/gui/i18n.cr`

### Other components

- **Operator**
- **gRPC client**

## Connections

- Operator → Moleflow CLI: runs (evidence: `README.md`)
- Moleflow CLI → Configuration: loads settings (evidence: `README.md`)
- Moleflow CLI → Application: starts
- Application → Simulation engine: runs simulation
- Simulation engine → Signal sources: generates or replays (evidence: `README.md`)
- gRPC client → gRPC services: opens live reads (evidence: `README.md`)
- gRPC services → Live session: serves session
- gRPC client → gRPC services: sends actions (evidence: `README.md`)
- Moleflow CLI → Output handling: generates offline (evidence: `README.md`)
- Output handling → Read recording: records signals (evidence: `README.md`)
- Signal sources → Signal formats: replays raw int16 (evidence: `README.md`)
- Operator → POD5 preparation: prepares POD5 (evidence: `README.md`)
- POD5 preparation → Signal sources: prepares replay input (evidence: `README.md`)
- Operator → GUI launcher: opens (evidence: `README.md`)
- GUI launcher → GUI settings: edits settings
- GUI launcher → GUI profiles: configures profiles
- GUI launcher → Localization: offers languages (evidence: `README.md`)
- GUI launcher → CLI runner: launches CLI (evidence: `README.md`)
- CLI runner → Moleflow CLI: starts sibling (evidence: `README.md`)
