# lauotero/libtuxrt_core architecture

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

- Interactive diagram: https://gitdiagram.com/lauotero/libtuxrt_core
- Repository: https://github.com/lauotero/libtuxrt_core

## Overview

libtuxrt_core is a C runtime for deterministic 3D-printer and CNC motion, exposed through a stable C ABI. The principal workflow is G-code input, motion interpretation and planning, then shaped and compressed step generation with synchronized hardware output. Supporting branches provide real-time scheduling and safety, persistence and recovery, industrial communications, and hardware-accelerated integrity/compression. Relationships are limited to README-documented capabilities; sampled excerpts do not establish most internal call sites, so finer implementation links are omitted.

Main entry points: [`src/motion/motion.c`](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/motion.c) (Motion engine), [`src/db/db_framework.c`](https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_framework.c) (Database abstraction), [`src/motion/trapq.c`](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/trapq.c) (Trapezoid queue), [`src/motion/steppersync.c`](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/steppersync.c) (Stepper synchronization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_motion["Motion control"]
  node_gcode["G-code parser<br/>[gcode_parser.c]"]
  node_kinematics["Kinematics<br/>[kinematics.c]"]
  node_lookahead["Motion lookahead<br/>[motion_lookahead.c]"]
  node_motion_core["Motion engine<br/>[motion.c]"]
  node_trapq["Trapezoid queue<br/>[trapq.c]"]
  node_shaper["Input shaping<br/>[input_shaper.c]"]
  node_stepcompress["Step compression<br/>[stepcompress.c]"]
  node_steppersync["Stepper synchronization<br/>[steppersync.c]"]
end

subgraph group_runtime["Real-time runtime"]
  node_scheduler["RT scheduler<br/>[scheduler.c]"]
  node_sirc["Safety controller<br/>[sirc.c]"]
  node_mutex["Priority mutex<br/>[mutex.c]"]
  node_observability["Event tracing<br/>[observability.c]"]
end

subgraph group_resilience["Resilience and state"]
  node_kares["KARES recovery<br/>[kares_recovery.c]"]
  node_uss["USS snapshots<br/>[uss.c]"]
  node_uss_ecc["USS ECC<br/>[uss_ecc.c]"]
  node_wal["Segmented WAL<br/>[wal.c]"]
  node_job_queue["Job queue<br/>[job_queue.c]"]
  node_tuxatlas["TuxAtlas rollback<br/>[tuxatlas.c]"]
end

subgraph group_io["Hardware and transport"]
  node_transport["Industrial transports<br/>[transport.c]"]
  node_transport_api["REST and gRPC<br/>[transport_rest.c]"]
  node_websocket["WebSocket client"]
  node_phsync["Phase sync<br/>[phsync.c]"]
  node_hal["Board and GPIO<br/>[gpio.c]"]
end

subgraph group_services["Data and acceleration"]
  node_dbal["Database abstraction<br/>[db_framework.c]"]
  node_db_sqlite[("SQLite backend")]
  node_db_mysql[("MySQL backend<br/>[db_backend_mysql.c]")]
  node_db_postgres[("PostgreSQL backend")]
  node_tsc["TSC compression<br/>[tsc.c]"]
  node_jlpp["JLPP compression<br/>[jlpp.c]"]
  node_crc["CRC integrity<br/>[ultracrc.c]"]
  node_hardware_detect["ISA detection<br/>[hwdet.c]"]
  node_ipc["IPC channels<br/>[channel.c]"]
  node_sdk["Public C ABI<br/>[tuxrt_sdk.h]"]
end

node_consumer(("ABI consumers"))

node_consumer -->|"uses ABI"| node_sdk
node_sdk -->|"accepts G-code"| node_gcode
node_gcode -->|"parses commands"| node_motion_core
node_motion_core -->|"maps motion"| node_kinematics
node_motion_core -->|"plans ahead"| node_lookahead
node_motion_core -->|"queues segments"| node_trapq
node_trapq -->|"shapes trajectory"| node_shaper
node_trapq -->|"compresses steps"| node_stepcompress
node_stepcompress -->|"synchronizes steps"| node_steppersync
node_steppersync -->|"outputs motion"| node_transport
node_steppersync -->|"aligns phase"| node_phsync
node_transport -.->|"controls hardware"| node_hal
node_scheduler -.->|"supports safety"| node_sirc
node_kares -->|"uses snapshots"| node_uss
node_uss -->|"protects snapshots"| node_uss_ecc
node_dbal -->|"selects backend"| node_db_sqlite
node_dbal -->|"selects backend"| node_db_mysql
node_dbal -->|"selects backend"| node_db_postgres
node_tsc -->|"dispatches SIMD"| node_hardware_detect
node_crc -->|"checks ISA"| node_hardware_detect

click node_gcode "https://github.com/lauotero/libtuxrt_core/blob/main/src/parser/gcode_parser.c"
click node_kinematics "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/kinematics.c"
click node_lookahead "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/motion_lookahead.c"
click node_motion_core "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/motion.c"
click node_trapq "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/trapq.c"
click node_shaper "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/input_shaper.c"
click node_stepcompress "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/stepcompress.c"
click node_steppersync "https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/steppersync.c"
click node_scheduler "https://github.com/lauotero/libtuxrt_core/blob/main/src/core/scheduler.c"
click node_sirc "https://github.com/lauotero/libtuxrt_core/blob/main/src/core/sirc.c"
click node_mutex "https://github.com/lauotero/libtuxrt_core/blob/main/src/core/mutex.c"
click node_observability "https://github.com/lauotero/libtuxrt_core/blob/main/src/core/observability.c"
click node_kares "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/kares/kares_recovery.c"
click node_uss "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/uss/uss.c"
click node_uss_ecc "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/uss/uss_ecc.c"
click node_wal "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/wal/wal.c"
click node_job_queue "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/job_queue/job_queue.c"
click node_tuxatlas "https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/tuxatlas/tuxatlas.c"
click node_transport "https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport.c"
click node_transport_api "https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport_rest.c"
click node_websocket "https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport_websocket.c"
click node_phsync "https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/phsync.c"
click node_hal "https://github.com/lauotero/libtuxrt_core/blob/main/src/hal/gpio.c"
click node_dbal "https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_framework.c"
click node_db_sqlite "https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_sqlite.c"
click node_db_mysql "https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_mysql.c"
click node_db_postgres "https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_postgres.c"
click node_tsc "https://github.com/lauotero/libtuxrt_core/blob/main/src/compression/tsc.c"
click node_jlpp "https://github.com/lauotero/libtuxrt_core/blob/main/src/compression/jlpp.c"
click node_crc "https://github.com/lauotero/libtuxrt_core/blob/main/src/integrity/ultracrc.c"
click node_hardware_detect "https://github.com/lauotero/libtuxrt_core/blob/main/src/accel/hwdet.c"
click node_ipc "https://github.com/lauotero/libtuxrt_core/blob/main/src/ipc/channel.c"
click node_sdk "https://github.com/lauotero/libtuxrt_core/blob/main/include/tuxrt_sdk.h"

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_gcode,node_kinematics,node_lookahead,node_motion_core,node_trapq,node_shaper,node_stepcompress,node_steppersync toneBlue
class node_scheduler,node_sirc,node_mutex,node_observability toneAmber
class node_kares,node_uss,node_uss_ecc,node_wal,node_job_queue,node_tuxatlas toneMint
class node_transport,node_transport_api,node_websocket,node_phsync,node_hal toneRose
class node_dbal,node_db_sqlite,node_db_mysql,node_db_postgres,node_tsc,node_jlpp,node_crc,node_hardware_detect,node_ipc,node_sdk,node_consumer toneIndigo
```

## Components

### Motion control

- [G-code parser](https://github.com/lauotero/libtuxrt_core/blob/main/src/parser/gcode_parser.c): `src/parser/gcode_parser.c`
- [Kinematics](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/kinematics.c): `src/motion/kinematics.c`
- [Motion lookahead](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/motion_lookahead.c): `src/motion/motion_lookahead.c`
- [Motion engine](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/motion.c): `src/motion/motion.c`
- [Trapezoid queue](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/trapq.c): `src/motion/trapq.c`
- [Input shaping](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/input_shaper.c): `src/motion/input_shaper.c`
- [Step compression](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/stepcompress.c): `src/motion/stepcompress.c`
- [Stepper synchronization](https://github.com/lauotero/libtuxrt_core/blob/main/src/motion/steppersync.c): `src/motion/steppersync.c`

### Real-time runtime

- [RT scheduler](https://github.com/lauotero/libtuxrt_core/blob/main/src/core/scheduler.c): `src/core/scheduler.c`
- [Safety controller](https://github.com/lauotero/libtuxrt_core/blob/main/src/core/sirc.c): `src/core/sirc.c`
- [Priority mutex](https://github.com/lauotero/libtuxrt_core/blob/main/src/core/mutex.c): `src/core/mutex.c`
- [Event tracing](https://github.com/lauotero/libtuxrt_core/blob/main/src/core/observability.c): `src/core/observability.c`

### Resilience and state

- [KARES recovery](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/kares/kares_recovery.c): `src/resilience/kares/kares_recovery.c`
- [USS snapshots](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/uss/uss.c): `src/resilience/uss/uss.c`
- [USS ECC](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/uss/uss_ecc.c): `src/resilience/uss/uss_ecc.c`
- [Segmented WAL](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/wal/wal.c): `src/resilience/wal/wal.c`
- [Job queue](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/job_queue/job_queue.c): `src/resilience/job_queue/job_queue.c`
- [TuxAtlas rollback](https://github.com/lauotero/libtuxrt_core/blob/main/src/resilience/tuxatlas/tuxatlas.c): `src/resilience/tuxatlas/tuxatlas.c`

### Hardware and transport

- [Industrial transports](https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport.c): `src/transport/transport.c`
- [REST and gRPC](https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport_rest.c): `src/transport/transport_rest.c`
- [WebSocket client](https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/transport_websocket.c): `src/transport/transport_websocket.c`
- [Phase sync](https://github.com/lauotero/libtuxrt_core/blob/main/src/transport/phsync.c): `src/transport/phsync.c`
- [Board and GPIO](https://github.com/lauotero/libtuxrt_core/blob/main/src/hal/gpio.c): `src/hal/gpio.c`

### Data and acceleration

- [Database abstraction](https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_framework.c): `src/db/db_framework.c`
- [SQLite backend](https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_sqlite.c): `src/db/db_backend_sqlite.c`
- [MySQL backend](https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_mysql.c): `src/db/db_backend_mysql.c`
- [PostgreSQL backend](https://github.com/lauotero/libtuxrt_core/blob/main/src/db/db_backend_postgres.c): `src/db/db_backend_postgres.c`
- [TSC compression](https://github.com/lauotero/libtuxrt_core/blob/main/src/compression/tsc.c): `src/compression/tsc.c`
- [JLPP compression](https://github.com/lauotero/libtuxrt_core/blob/main/src/compression/jlpp.c): `src/compression/jlpp.c`
- [CRC integrity](https://github.com/lauotero/libtuxrt_core/blob/main/src/integrity/ultracrc.c): `src/integrity/ultracrc.c`
- [ISA detection](https://github.com/lauotero/libtuxrt_core/blob/main/src/accel/hwdet.c): `src/accel/hwdet.c`
- [IPC channels](https://github.com/lauotero/libtuxrt_core/blob/main/src/ipc/channel.c): `src/ipc/channel.c`
- [Public C ABI](https://github.com/lauotero/libtuxrt_core/blob/main/include/tuxrt_sdk.h): `include/tuxrt_sdk.h`

### Other components

- **ABI consumers**

## Connections

- ABI consumers → Public C ABI: uses ABI
- Public C ABI → G-code parser: accepts G-code
- G-code parser → Motion engine: parses commands
- Motion engine → Kinematics: maps motion
- Motion engine → Motion lookahead: plans ahead
- Motion engine → Trapezoid queue: queues segments
- Trapezoid queue → Input shaping: shapes trajectory
- Trapezoid queue → Step compression: compresses steps
- Step compression → Stepper synchronization: synchronizes steps
- Stepper synchronization → Industrial transports: outputs motion
- Stepper synchronization → Phase sync: aligns phase
- Industrial transports → Board and GPIO: controls hardware
- RT scheduler → Safety controller: supports safety
- KARES recovery → USS snapshots: uses snapshots (evidence: `src/resilience/kares/kares_recovery.c`)
- USS snapshots → USS ECC: protects snapshots
- Database abstraction → SQLite backend: selects backend
- Database abstraction → MySQL backend: selects backend
- Database abstraction → PostgreSQL backend: selects backend
- TSC compression → ISA detection: dispatches SIMD (evidence: `src/compression/tsc.c`)
- CRC integrity → ISA detection: checks ISA (evidence: `src/integrity/ultracrc.c`)
