# kojix2/read_until architecture

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

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

## Overview

This repository is a Crystal shard that wraps Oxford Nanopore’s Read Until API. It is not a standalone application; it is a library centered on streaming signal inspection and control of sequencing reads.

1. Public entry point
- `src/read_until.cr` is the top-level require file.
- `shard.yml` defines the package as a Crystal dependency.
- The README shows the main usage pattern: `ReadUntil::Client.new(connection)` followed by `client.open(...)`.

2. Core runtime boundary
- The library sits between Crystal application code and an underlying connection to a Nanopore Read Until-capable system.
- The external dependency is the sequencing/control endpoint, not a database or web server.
- The user supplies the connection object; this library manages session lifecycle and read decisions.

3. Client and session orchestration
- `src/read_until/client.cr` is the main facade for opening a controlled streaming session.
- `src/read_until/session.cr` likely owns the active run state: channel scope, streaming mode, read iteration, and actions such as unblock.
- Architecturally, this is the control plane: open a session, process reads, issue decisions back to the device.

4. Read ingestion pipeline
- `src/read_until/read.cr` and `src/read_until/read_buffer.cr` represent the data plane for incoming read chunks and buffered signal data.
- The example in the README shows batch-oriented iteration over reads, suggesting the library supports streaming and incremental processing rather than loading full reads into memory.
- This is the key flow: raw signal arrives → buffer/read wrapper → user inspection → decision.

5. Prefiltering and classification
- `src/read_until/prefilter.cr` provides early filtering rules before full read processing.
- `src/read_until/classification_registry.cr` suggests a registry of classification outcomes or labels used to route reads.
- The README’s `Prefilter.strand_like(:strand, :adapter)` example indicates the library supports lightweight heuristics to decide which reads proceed to deeper analysis.

6. Signal representation
- `src/read_until/signal_format.cr` defines how raw signal data is interpreted or converted.
- The README example `read.signal(Int16)` implies the library abstracts signal extraction into typed views, so downstream code can work with signal arrays in a chosen numeric format.
- This is important for performance-sensitive analysis because signal conversion is explicit and typed.

7. Configuration and types
- `src/read_until/config.cr` centralizes session/runtime configuration.
- `src/read_until/types.cr` likely defines shared domain types used across client, session, and read handling.
- `src/read_until/version.cr` exposes package version metadata.
- These files indicate a clean separation between domain model, runtime settings, and public API surface.

8. Statistics and operational insight
- `src/read_until/stats.cr` suggests the library tracks session-level or read-level metrics.
- This is a supporting subsystem rather than the main control path, but it matters for monitoring throughput, filter outcomes, and unblock/reject behavior.

9. Example-driven architecture
- `examples/basic.cr` is the only example entry point, and it reflects the intended control loop:
  open session on a channel range, stream reads in batches, inspect signal, and send unblock actions conditionally.
- The example demonstrates the library’s primary architectural pattern: event-driven stream processing with feedback to the sequencer.

10. Test and release structure
- `spec/` contains behavior tests, with `spec/read_until_spec.cr` and shared setup in `spec/spec_helper.cr`.
- GitHub Actions workflows in `.github/workflows/test.yml` and `docs.yml` indicate automated validation and documentation generation.
- This suggests the public API is meant to stay stable and the library is verified through spec-based behavior tests.

11. Main data flow
- Incoming connection data enters through `Client`.
- `Session` coordinates channel selection, streaming mode, and batching.
- `Read`/`ReadBuffer` hold the streamed signal.
- `Prefilter` and `ClassificationRegistry` classify or triage reads.
- User code inspects typed signal, then sends a sequencing decision such as unblock.

12. Architectural summary
- The repository is best understood as a thin, stateful streaming control library for nanopore sequencing.
- Its boundaries are: Crystal application code on one side, Nanopore Read Until infrastructure on the other.
- Internally it is organized around session control, buffered signal handling, filtering/classification, and typed signal conversion.

Main entry points: [`src/read_until/session.cr`](https://github.com/kojix2/read_until/blob/main/src/read_until/session.cr) (Session), [`src/read_until.cr`](https://github.com/kojix2/read_until/blob/main/src/read_until.cr) (Entry file), [`src/read_until/client.cr`](https://github.com/kojix2/read_until/blob/main/src/read_until/client.cr) (Client), [`src/read_until/read.cr`](https://github.com/kojix2/read_until/blob/main/src/read_until/read.cr) (Read)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Public API"]
  node_src_read_until["Entry file<br/>module entry<br/>[read_until.cr]"]
end

subgraph group_control["Control Plane"]
  node_client["Client<br/>facade<br/>[client.cr]"]
  node_session["Session<br/>runtime state<br/>[session.cr]"]
  node_external_endpoint[("Read Until API<br/>external endpoint")]
end

subgraph group_data["Data Plane"]
  node_read["Read<br/>domain object<br/>[read.cr]"]
  node_read_buffer["Read buffer<br/>[read_buffer.cr]"]
  node_signal_format["Signal format<br/>conversion<br/>[signal_format.cr]"]
  node_prefilter{{"Prefilter<br/>filtering<br/>[prefilter.cr]"}}
  node_classification_registry["Registry<br/>routing rules"]
end

subgraph group_support["Support"]
  node_config["Config<br/>[config.cr]"]
  node_types["Types<br/>[types.cr]"]
  node_stats["Stats<br/>metrics<br/>[stats.cr]"]
  node_version["Version<br/>metadata<br/>[version.cr]"]
end

subgraph group_usage["Examples & Specs"]
  node_example_basic["Basic example<br/>[basic.cr]"]
  node_spec_read_until["Specs<br/>behavior tests<br/>[read_until_spec.cr]"]
end

node_src_read_until -->|"exports"| node_client
node_src_read_until -->|"exports"| node_session
node_src_read_until -->|"exports"| node_read
node_src_read_until -->|"exports"| node_read_buffer
node_src_read_until -->|"exports"| node_prefilter
node_src_read_until -->|"exports"| node_classification_registry
node_src_read_until -->|"exports"| node_signal_format
node_src_read_until -->|"exports"| node_config
node_src_read_until -->|"exports"| node_types
node_src_read_until -->|"exports"| node_stats
node_client -->|"connects"| node_external_endpoint
node_client -->|"opens"| node_session
node_session -->|"controls"| node_external_endpoint
node_session -->|"streams"| node_read_buffer
node_session -->|"emits"| node_read
node_session -->|"applies"| node_prefilter
node_session -->|"records"| node_stats
node_read_buffer -->|"wraps"| node_read
node_read -->|"views"| node_signal_format
node_prefilter -->|"routes"| node_classification_registry
node_config -->|"configures"| node_client
node_config -->|"configures"| node_session
node_types -->|"shared by"| node_client
node_types -->|"shared by"| node_session
node_types -->|"shared by"| node_read
node_types -->|"shared by"| node_prefilter
node_stats -->|"observes"| node_session
node_version -->|"metadata"| node_src_read_until
node_example_basic -->|"uses"| node_client
node_example_basic -->|"uses"| node_session
node_example_basic -->|"inspects"| node_read
node_example_basic -->|"converts"| node_signal_format
node_example_basic -->|"triages"| node_prefilter
node_spec_read_until -->|"verifies"| node_client
node_spec_read_until -->|"verifies"| node_session
node_spec_read_until -->|"verifies"| node_read
node_spec_read_until -->|"verifies"| node_prefilter

click node_src_read_until "https://github.com/kojix2/read_until/blob/main/src/read_until.cr"
click node_client "https://github.com/kojix2/read_until/blob/main/src/read_until/client.cr"
click node_session "https://github.com/kojix2/read_until/blob/main/src/read_until/session.cr"
click node_read "https://github.com/kojix2/read_until/blob/main/src/read_until/read.cr"
click node_read_buffer "https://github.com/kojix2/read_until/blob/main/src/read_until/read_buffer.cr"
click node_signal_format "https://github.com/kojix2/read_until/blob/main/src/read_until/signal_format.cr"
click node_prefilter "https://github.com/kojix2/read_until/blob/main/src/read_until/prefilter.cr"
click node_classification_registry "https://github.com/kojix2/read_until/blob/main/src/read_until/classification_registry.cr"
click node_config "https://github.com/kojix2/read_until/blob/main/src/read_until/config.cr"
click node_types "https://github.com/kojix2/read_until/blob/main/src/read_until/types.cr"
click node_stats "https://github.com/kojix2/read_until/blob/main/src/read_until/stats.cr"
click node_version "https://github.com/kojix2/read_until/blob/main/src/read_until/version.cr"
click node_example_basic "https://github.com/kojix2/read_until/blob/main/examples/basic.cr"
click node_spec_read_until "https://github.com/kojix2/read_until/blob/main/spec/read_until_spec.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_src_read_until toneBlue
class node_client,node_session,node_external_endpoint toneAmber
class node_read,node_read_buffer,node_signal_format,node_prefilter,node_classification_registry toneMint
class node_config,node_types,node_stats,node_version toneRose
class node_example_basic,node_spec_read_until toneIndigo
```

## Components

### Public API

Top-level require and package surface

- [Entry file](https://github.com/kojix2/read_until/blob/main/src/read_until.cr): module entry · Top-level require file for the shard · `src/read_until.cr`

### Control Plane

Session orchestration and sequencing decisions

- [Client](https://github.com/kojix2/read_until/blob/main/src/read_until/client.cr): facade · Main API for opening and controlling a Read Until session · `src/read_until/client.cr`
- [Session](https://github.com/kojix2/read_until/blob/main/src/read_until/session.cr): runtime state · Owns active streaming session state and sequencing decisions · `src/read_until/session.cr`
- **Read Until API**: external endpoint · Nanopore Read Until-capable sequencing/control system

### Data Plane

Read ingestion, buffering, and signal views

- [Read](https://github.com/kojix2/read_until/blob/main/src/read_until/read.cr): domain object · Wrapper for incoming reads and signal access · `src/read_until/read.cr`
- [Read buffer](https://github.com/kojix2/read_until/blob/main/src/read_until/read_buffer.cr): buffer · Incremental storage for streamed signal chunks · `src/read_until/read_buffer.cr`
- [Signal format](https://github.com/kojix2/read_until/blob/main/src/read_until/signal_format.cr): conversion · Typed interpretation of raw signal data · `src/read_until/signal_format.cr`
- [Prefilter](https://github.com/kojix2/read_until/blob/main/src/read_until/prefilter.cr): filtering · Early heuristics for triaging reads · `src/read_until/prefilter.cr`
- [Registry](https://github.com/kojix2/read_until/blob/main/src/read_until/classification_registry.cr): routing rules · Classification outcomes and labels used to route reads · `src/read_until/classification_registry.cr`

### Support

Shared domain types, config, stats, and versioning

- [Config](https://github.com/kojix2/read_until/blob/main/src/read_until/config.cr): configuration · Session and runtime configuration · `src/read_until/config.cr`
- [Types](https://github.com/kojix2/read_until/blob/main/src/read_until/types.cr): shared types · Common domain types used across the shard · `src/read_until/types.cr`
- [Stats](https://github.com/kojix2/read_until/blob/main/src/read_until/stats.cr): metrics · Operational counters and session-level measurements · `src/read_until/stats.cr`
- [Version](https://github.com/kojix2/read_until/blob/main/src/read_until/version.cr): metadata · Package version metadata · `src/read_until/version.cr`

### Examples & Specs

Intended usage and behavioral coverage

- [Basic example](https://github.com/kojix2/read_until/blob/main/examples/basic.cr): example · Demonstrates open, stream, inspect, and unblock flow · `examples/basic.cr`
- [Specs](https://github.com/kojix2/read_until/blob/main/spec/read_until_spec.cr): behavior tests · Public API and session behavior coverage · `spec/read_until_spec.cr`

## Connections

- Entry file → Client: exports · Top-level entry requires the main client API
- Entry file → Session: exports · Top-level entry exposes session orchestration
- Entry file → Read: exports · Top-level entry exposes read handling
- Entry file → Read buffer: exports · Top-level entry exposes buffered signal support
- Entry file → Prefilter: exports · Top-level entry exposes prefiltering helpers
- Entry file → Registry: exports · Top-level entry exposes classification routing
- Entry file → Signal format: exports · Top-level entry exposes signal conversion
- Entry file → Config: exports · Top-level entry exposes configuration
- Entry file → Types: exports · Top-level entry exposes shared types
- Entry file → Stats: exports · Top-level entry exposes metrics support
- Client → Read Until API: connects · Client operates over a supplied connection to the sequencing system
- Client → Session: opens · Client creates and manages active sessions
- Session → Read Until API: controls · Session issues read-until decisions back to the device
- Session → Read buffer: streams · Session coordinates incremental read buffering
- Session → Read: emits · Session yields reads for inspection and decisioning
- Session → Prefilter: applies · Session can triage reads before deeper processing
- Session → Stats: records · Session updates operational counters and throughput data
- Read buffer → Read: wraps · Buffered chunks are exposed through read objects
- Read → Signal format: views · Reads expose typed signal access
- Prefilter → Registry: routes · Early heuristics map reads into classification outcomes
- Config → Client: configures · Configuration shapes client behavior
- Config → Session: configures · Configuration shapes session scope and runtime mode
- Types → Client: shared by · Shared domain types support the public API
- Types → Session: shared by · Shared domain types support session orchestration
- Types → Read: shared by · Shared domain types support read handling
- Types → Prefilter: shared by · Shared domain types support filtering decisions
- Stats → Session: observes · Metrics summarize session activity
- Version → Entry file: metadata · Package version metadata belongs to the public module
- Basic example → Client: uses · Example constructs the client and opens a session
- Basic example → Session: uses · Example demonstrates the streaming control loop
- Basic example → Read: inspects · Example inspects read signal batches
- Basic example → Signal format: converts · Example shows typed signal extraction
- Basic example → Prefilter: triages · Example demonstrates read filtering decisions
- Specs → Client: verifies · Specs cover the public client API
- Specs → Session: verifies · Specs cover session behavior
- Specs → Read: verifies · Specs cover read handling and signal access
- Specs → Prefilter: verifies · Specs cover filtering behavior
