d_rocket
Dart's data rocket — serialize, query, persist, sync.
d_rocket is the engine-agnostic core of a single-package framework for the data layer of Dart and Flutter applications. It unifies the six concerns that, in most stacks, force you to glue together half a dozen different libraries: JSON serialization, typed HTTP clients, LINQ-style queries, an ORM, offline-first sync, and WebSocket / SSE realtime.
Modular by design
The framework is built as six independent layers. A single
import — package:d_rocket/d_rocket.dart — exposes them all,
but only the code you use is in your final app:
- A Flutter app that just needs typed JSON ↔ Dart picks the
SerializerAPI and ships with Layer 1 only (≈ 60 KB). - A pure REST client picks
@RestClient(Layer 2) and ships with Layer 2 only (≈ 110 KB), without pulling in LINQ, the ORM, sync, or realtime. - A client with an HTTP API + offline cache + push notifications picks Layers 2 + 4 + 6 and ships just those (≈ 290 KB).
- A full backend client that uses all six ships the whole package (≈ 530 KB pre-tree-shake).
There is no global state, no main()-time side effects, no
implicit registration. The codegen emits only the fromJson /
toJson / RestClient impl / EntityMeta / typed stream
for the classes you actually annotated. Lint rules, the engine
adapter, and the DB facade are separate dev_dependencies that
don't bloat the runtime.
The corollary: you can adopt d_rocket one layer at a time. Start with
@Serializablefor JSON. Later add@RestClient. Later add the ORM. The migration is per-class, not project-wide.
The six layers
| # | Layer | Highlights | Doc |
|---|---|---|---|
| 1 | Serialization | @Serializable → fromJson / toJson; @SerializableUnion; @JsonKey + JsonNaming; JsonFactory / JsonEncoder; CodecEncoder (json, msgpack, cbor, bson, xml, url-form, multipart, raw); SerializerSnapshot. |
04 |
| 2 | REST | @RestClient + 6 verbs + 7 parameter annotations; 7 wrap-around clients — HttpCache, GzipCodec, HmacSha256Signer, OAuth2HttpClient, RateLimitedHttpClient, RetryingHttpClient, CircuitBreakerHttpClient; streaming; CancelToken; LoggingInterceptor. |
05 |
| 3 | LINQ | Deferred Queryable<T> with 35+ operators (filter, project, order, page, group, join, aggregate, set, quantifier, element, convert). Engine-agnostic Expr AST. Sync *_ + async *Async_ terminals. |
06 |
| 4 | ORM | DbContext + change-tracked DbSet<T> (add / markModified / remove + saveChanges); include_<TNav>(); watch(); DbInterceptor chain; @Migration + auto-migrator (pendingSchemaDiff() / runAutoMigrations()); bulk ops. |
07 |
| 5 | Sync | SyncProvider (sealed) — RestSyncProvider, WebSocketSyncProvider, MultiTransportSyncProvider; persistent identity; push + pull; conflict resolution (Lww, ClientWins, Custom, MergeStrategies); 4 retry policies; 3 SyncStateStore impls; ConnectivityProvider; MultiTenantSync; AuthRefreshSync; VectorClock. |
08 |
| 6 | Realtime | @WebSocketClient + @SseClient → typed Stream<T>; IOWebSocketClient (dart:io) + WebWebSocketClient (browser); WebSocketReconnector (backoff + heartbeat). |
09 |
A single initializeD() call (emitted by d_rocket_builder into
d_rocket_registry.g.dart) wires every annotated class in your
project. There is no per-file registerAll().
Engine adapters
The DB engine is a separate package. The same DbContext /
DbSet<T> / LINQ code runs on:
| Engine | Backend | LINQ |
|---|---|---|
d_rocket_engine_sqlite |
package:sqlite3 (file or sqlite::memory:; SQLCipher supported) |
sync + async |
d_rocket_engine_postgres |
package:postgres (wire protocol; pure Dart, no FFI) |
async only |
d_rocket_engine_web |
IndexedDB via idb_shim (browser) |
async only |
The engine-agnostic LINQ is provided by
d_rocketcore. Each engine supplies aQueryProviderand aSqlDialectso the in-memoryExprtree is translated to the engine's SQL dialect.
Install
Pick the layers you need. There is no single "all-in" config.
# Layer 1 only (JSON ↔ Dart):
dependencies:
d_rocket: ^2.0.0
# Layer 1 + 2 (typed HTTP client):
dependencies:
d_rocket: ^2.0.0
dev_dependencies:
d_rocket_builder: ^2.0.0
build_runner: ^2.4.13
# Layers 1, 2, 4, 6 (HTTP + ORM + realtime):
dependencies:
d_rocket: ^2.0.0
d_rocket_engine_sqlite: ^2.0.0 # or postgres / web
dev_dependencies:
d_rocket_builder: ^2.0.0
d_rocket_lints: ^2.0.0 # N+1 + closure-linq lints
build_runner: ^2.4.13
Code generation
d_rocket_builder runs under build_runner and emits 7 builders,
one per concern:
| Builder | Reads | Emits |
|---|---|---|
d_rocket_builder:record |
extends Record |
_<Name>Init + register<X>Record |
d_rocket_builder:serializer |
@Serializable / @SerializableUnion |
fromJson / toJson + register<X>Serializer |
d_rocket_builder:rest_client |
@RestClient |
per-interface impl with interceptors, retry, serialization |
d_rocket_builder:rocket_table |
@Table + @Column + @PrimaryKey + @ForeignKey + @Index + @Embedded |
EntityMeta |
d_rocket_builder:rocket_migration |
@Migration top-level function |
_$_<fnName> extends MigrationBase |
d_rocket_builder:realtime |
@WebSocketClient / @SseClient |
per-interface typed Stream<T> client |
d_rocket_builder:record_registry |
the union of all the above | d_rocket_registry.g.dart with initializeD() |
dart run build_runner build --delete-conflicting-outputs
CLI
# Scaffold a migration from a pending schema diff
dart run d_rocket:migration add add_note_to_patients \
--db app.db --entities lib/db/entities.dart
# Auto-rewrite LINQ closures to Expr.lambda
dart run d_rocket:closure transform-file lib/services/order_query.dart
# Run the analyzer with d_rocket lints (N+1 + closure-linq)
dart analyze
Documentation
Full documentation lives in the
monorepo README
and in the
docs/
directory (one .md per layer, plus installation, migrations,
cookbook, FAQ, and architecture). The package targets
Dart 3.6+ and Flutter 3.10+.
License
MIT — see LICENSE. Copyright (c) 2026 Torogoz Tech.
Author
Abner Velasco — Arquitecto de Soluciones
Libraries
- d_rocket
- 🚀 d_rocket — Dart's data rocket.