How solvaratech/drawline-core works
1. What this repo is
- @solvaratech/drawline-core is a TypeScript library for deterministic database seeding and schema-aware generation.
- It is not a single app; it is a set of cooperating subsystems exposed through library exports, a CLI, and a service-oriented runtime entrypoint.
2. Primary architectural boundary
- The codebase cleanly separates schema modeling, generation logic, database adapters/connections, and code generation/diffing.
- Shared contracts live in src/types/schemaDesign.ts and src/types/schemaDiff.ts, which act as the internal language between subsystems.
3. Generation pipeline
- The main runtime flow starts with schema + relationship inputs, then passes through orchestration in src/server.ts and the generator layer in src/generator.
- Generation is ordered by dependencies, constrained by field rules, then written through a selected adapter into the target system.
4. Core generation engine
- src/generator/core contains the algorithmic heart:
- DependencyGraph.ts orders collections by foreign-key dependency.
- ConstraintEngine.ts resolves cross-field and range constraints.
- FieldInferenceEngine.ts infers realistic values from field names and metadata.
- This is the part that makes the output deterministic and relationship-safe.
5. Adapter layer
- src/generator/adapters defines the write-side database boundary via BaseAdapter.ts.
- Concrete adapters implement storage-specific behavior for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, DynamoDB, Firestore, Redis, CSV export, in-memory, ephemeral, and null/no-op modes.
- Each adapter translates the common generation output into the target database’s insert and schema operations.
6. Connection layer
- src/connections is a separate integration layer for database connectivity and introspection, with specific modules for PostgreSQL, MongoDB, and Firestore.
- This layer likely feeds metadata and schema details into the generator, while the adapter layer handles actual data creation/insertion semantics.
7. Parallel and deterministic execution
- src/generator/WorkerPool.ts and src/generator/worker.cts indicate a worker-thread based execution model for large jobs.
- The architecture supports sharded generation and parallelism while preserving deterministic output order and referential integrity.
8. Schema diff / migration subsystem
- src/schema/schemaDiffEngine.ts is a separate transformation pipeline for comparing schemas and producing DDL-oriented changes.
- This subsystem is focused on detecting structural drift and generating migration actions, distinct from data seeding.
9. ORM code generation subsystem
- src/generators/orm contains generators for Prisma, TypeORM, Drizzle, and Mongoose.
- These modules consume the same schema model but produce code artifacts instead of data, so they form a parallel output path from the shared schema core.
10. Public entrypoints
- src/index.ts aggregates library exports.
- src/cli.ts provides the command-line surface.
- src/server.ts exposes the higher-level service API used by consumers to run generation end-to-end.
11. Utility and translation layer
- src/utils/schemaConverter.ts is the main bridge from external schema shapes into Drawline’s internal model.
- Logging and error formatting live in src/utils/logger.ts, cli-logger.ts, and errorMessages.ts, supporting both CLI and programmatic use.
12. Testing and validation
- Tests are split by subsystem: adapter tests, generator tests, schema diff tests, and end-to-end tests under src/tests.
- The presence of InMemoryAdapter and EphemeralAdapter also shows that the architecture is designed to validate behavior without requiring a live database for every test path.
Main entry points: generator/index.ts Generator Facade · BaseAdapter.ts Base Adapter · connections/index.ts Connections · src/index.ts Public API
Components 24
Entrypoints
Public surfaces for library, CLI, and service runtime.
- Public API · Aggregates the package's main exports.
src/index.ts - CLI · Command-line surface for running the library.
src/cli.ts - Server API · Higher-level service entrypoint that orchestrates generation end to end.
src/server.ts
Schema Core
Shared contracts and translation into the internal schema model.
- Schema Types · Internal schema design and diff contracts shared across subsystems.
src/types/schemaDesign.ts - Diff Types · Typed model for schema change detection and migration actions.
src/types/schemaDiff.ts - Schema Converter · Bridges external schema shapes into Drawline's internal model.
src/utils/schemaConverter.ts
Generation Engine
Deterministic data generation, ordering, and execution.
- Dependency Graph · Sorts collections by foreign-key and dependency relationships.
src/generator/core/DependencyGraph.ts - Constraint Engine · Resolves cross-field rules, ranges, and generation constraints.
src/generator/core/ConstraintEngine.ts - Field Inference · Infers realistic values from names and field metadata.
src/generator/core/FieldInferenceEngine.ts - Worker Pool · Coordinates worker-thread execution for large deterministic jobs.
src/generator/WorkerPool.ts - Generator Facade · Main generator entrypoint that ties core logic together.
src/generator/index.ts
Integrations
Database connectivity and write-side adapters.
- Base Adapter · Common write-side boundary implemented by storage-specific adapters.
src/generator/adapters/BaseAdapter.ts - SQL Adapters · PostgreSQL, MySQL, SQLite, and SQL Server write adapters.
src/generator/adapters/PostgresAdapter.ts - NoSQL Adapters · MongoDB, DynamoDB, Firestore, and Redis adapters.
src/generator/adapters/MongoDBAdapter.ts - Special Adapters · CSV export, in-memory, ephemeral, and null/no-op modes.
src/generator/adapters/CSVExportAdapter.ts - Connections · Database connectivity and schema introspection helpers.
src/connections/index.ts - Postgres Conn · PostgreSQL connectivity and introspection support.
src/connections/postgresql.ts - Mongo Conn · MongoDB connectivity and introspection support.
src/connections/mongodb.ts - Firestore Conn · Firestore connectivity and introspection support.
src/connections/firestore.ts
Derived Outputs
Schema diffing and ORM code generation outputs.
- Schema Diff Engine · Compares schemas and produces DDL-oriented changes.
src/schema/schemaDiffEngine.ts - ORM Generators · Shared entrypoint for Prisma, TypeORM, Drizzle, and Mongoose generators.
src/generators/orm/index.ts
Support
Logging, error formatting, and test harnesses.
- Logging · Shared logger and CLI logger utilities.
src/utils/logger.ts - Error Messages · Centralized error formatting and user-facing messages.
src/utils/errorMessages.ts - Test Suite · Subsystem tests and end-to-end validation coverage.
src/tests/e2e.test.ts
Connections 29
- Public API → Schema Converter: exports · Public API exposes schema translation utilities.
- Public API → Generator Facade: exports · Public API exposes generation capabilities.
- Public API → Schema Diff Engine: exports · Public API exposes diffing functionality.
- CLI → Server API: invokes · CLI drives the higher-level runtime API.
- Server API → Schema Types: uses · Server orchestration consumes shared schema contracts.
- Server API → Generator Facade: orchestrates · Server coordinates generation end to end.
- Schema Converter → Schema Types: maps to · External schema shapes are normalized into internal contracts.
- Generator Facade → Dependency Graph: orders · Generation is sequenced by dependency relationships.
- Generator Facade → Constraint Engine: constrains · Field and record generation is validated against rules.
- Generator Facade → Field Inference: infers · Generator derives realistic values from field metadata.
- Generator Facade → Worker Pool: parallelizes · Large jobs are distributed across worker threads.
- Generator Facade → Base Adapter: writes via · Generated output is persisted through an adapter boundary.
- Base Adapter → SQL Adapters: implements · Concrete SQL storage backends extend the common adapter contract.
- Base Adapter → NoSQL Adapters: implements · Concrete NoSQL storage backends extend the common adapter contract.
- Base Adapter → Special Adapters: implements · Export and mock modes extend the common adapter contract.
- Connections → Postgres Conn: includes · Connection layer provides PostgreSQL support.
- Connections → Mongo Conn: includes · Connection layer provides MongoDB support.
- Connections → Firestore Conn: includes · Connection layer provides Firestore support.
- Connections → Schema Converter: feeds · Introspection metadata can be converted into the internal model.
- Schema Diff Engine → Schema Types: compares · Diff engine operates on the shared schema model.
- Schema Diff Engine → Diff Types: produces · Diff engine emits structured schema change output.
- ORM Generators → Schema Types: consumes · ORM generators read the same internal schema contracts.
- ORM Generators → Public API: exposed by · Code generators are surfaced through package exports.
- Generator Facade → Logging: logs · Generation flow uses shared logging.
- CLI → Logging: logs · CLI uses specialized logging output.
- CLI → Error Messages: formats · Command-line errors are normalized for user output.
- Test Suite → Base Adapter: validates · Test suite exercises adapter behavior.
- Test Suite → Generator Facade: validates · Test suite exercises generation flow.
- Test Suite → Schema Diff Engine: validates · Test suite exercises diffing behavior.