Architecture
The main layers and data flow inside comon_orm.
Architecture
The high-level flow is:
schema.prismais parsed into an AST.- The schema is validated and normalized.
- Code generation emits typed Dart models, inputs, delegates, and runtime metadata.
- The generated client routes queries through neutral query models.
- Runtime adapters translate that query shape into in-memory behavior, SQLite SQL, PostgreSQL SQL, or Flutter SQLite calls.
Main layers
Schema layer
SchemaParserturns source text intoSchemaDocumentSchemaValidatorapplies DSL and provider-specific validation rules- formatting and source regeneration work from the same AST model
Code generation layer
- generated clients expose models, inputs, relation helpers, delegates, and runtime metadata
- generated cursor selectors and query arguments flow into the neutral query layer
- simple
createMany(...)routes into adapter-level batch paths where supported
Runtime layer
ComonOrmClientandModelDelegatesit between generated code and adapters- middleware can wrap adapters without changing their implementation
- adapters own provider-specific execution details such as SQL pushdown, cursor windows, and include materialization
Migration layer
- shared PostgreSQL and SQLite migrations live in VM-oriented packages
- migration artifacts store warnings, checksums, and before/after schema snapshots
- Flutter local SQLite upgrades are explicit app-side code, not shared-database rollout
Design rule worth remembering
Normal runtime startup should be generated-metadata-first. Runtime adapters are not the place to auto-apply schema changes in production.