# solvaratech/drawline-core architecture

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

- Interactive diagram: https://gitdiagram.com/solvaratech/drawline-core
- Repository: https://github.com/solvaratech/drawline-core

## Overview

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: [`src/generator/index.ts`](https://github.com/solvaratech/drawline-core/blob/main/src/generator/index.ts) (Generator Facade), [`src/generator/adapters/BaseAdapter.ts`](https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/BaseAdapter.ts) (Base Adapter), [`src/connections/index.ts`](https://github.com/solvaratech/drawline-core/blob/main/src/connections/index.ts) (Connections), [`src/index.ts`](https://github.com/solvaratech/drawline-core/blob/main/src/index.ts) (Public API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entrypoints"]
  node_index["Public API<br/>library export<br/>[index.ts]"]
  node_cli["CLI<br/>command entry<br/>[cli.ts]"]
  node_server["Server API<br/>runtime entry<br/>[server.ts]"]
end

subgraph group_schema["Schema Core"]
  node_schema_types["Schema Types<br/>contracts<br/>[schemaDesign.ts]"]
  node_diff_types["Diff Types<br/>contracts<br/>[schemaDiff.ts]"]
  node_schema_converter["Schema Converter<br/>translator<br/>[schemaConverter.ts]"]
end

subgraph group_gen["Generation Engine"]
  node_dep_graph["Dependency Graph<br/>ordering engine<br/>[DependencyGraph.ts]"]
  node_constraint_engine["Constraint Engine<br/>rules engine"]
  node_field_inference["Field Inference<br/>inference engine"]
  node_worker_pool["Worker Pool<br/>parallel runtime<br/>[WorkerPool.ts]"]
  node_generator_index["Generator Facade<br/>orchestration layer<br/>[index.ts]"]
end

subgraph group_io["Integrations"]
  node_base_adapter["Base Adapter<br/>adapter contract<br/>[BaseAdapter.ts]"]
  node_sql_adapters["SQL Adapters<br/>storage adapters<br/>[PostgresAdapter.ts]"]
  node_nosql_adapters["NoSQL Adapters<br/>storage adapters<br/>[MongoDBAdapter.ts]"]
  node_special_adapters["Special Adapters<br/>storage adapters"]
  node_connections["Connections<br/>introspection layer<br/>[index.ts]"]
  node_postgres_conn["Postgres Conn<br/>connection module<br/>[postgresql.ts]"]
  node_mongo_conn["Mongo Conn<br/>connection module<br/>[mongodb.ts]"]
  node_firestore_conn["Firestore Conn<br/>connection module<br/>[firestore.ts]"]
end

subgraph group_artifacts["Derived Outputs"]
  node_schema_diff["Schema Diff Engine<br/>transformation pipeline"]
  node_orm_generators["ORM Generators<br/>codegen facade<br/>[index.ts]"]
end

subgraph group_support["Support"]
  node_logger["Logging<br/>support<br/>[logger.ts]"]
  node_errors["Error Messages<br/>support<br/>[errorMessages.ts]"]
  node_tests["Test Suite<br/>validation<br/>[e2e.test.ts]"]
end

node_index -->|"exports"| node_schema_converter
node_index -->|"exports"| node_generator_index
node_index -->|"exports"| node_schema_diff
node_cli -->|"invokes"| node_server
node_server -->|"uses"| node_schema_types
node_server -->|"orchestrates"| node_generator_index
node_schema_converter -->|"maps to"| node_schema_types
node_generator_index -->|"orders"| node_dep_graph
node_generator_index -->|"constrains"| node_constraint_engine
node_generator_index -->|"infers"| node_field_inference
node_generator_index -->|"parallelizes"| node_worker_pool
node_generator_index -->|"writes via"| node_base_adapter
node_base_adapter -->|"implements"| node_sql_adapters
node_base_adapter -->|"implements"| node_nosql_adapters
node_base_adapter -->|"implements"| node_special_adapters
node_connections -->|"includes"| node_postgres_conn
node_connections -->|"includes"| node_mongo_conn
node_connections -->|"includes"| node_firestore_conn
node_connections -->|"feeds"| node_schema_converter
node_schema_diff -->|"compares"| node_schema_types
node_schema_diff -->|"produces"| node_diff_types
node_orm_generators -->|"consumes"| node_schema_types
node_orm_generators -->|"exposed by"| node_index
node_generator_index -->|"logs"| node_logger
node_cli -->|"logs"| node_logger
node_cli -->|"formats"| node_errors
node_tests -->|"validates"| node_base_adapter
node_tests -->|"validates"| node_generator_index
node_tests -->|"validates"| node_schema_diff

click node_index "https://github.com/solvaratech/drawline-core/blob/main/src/index.ts"
click node_cli "https://github.com/solvaratech/drawline-core/blob/main/src/cli.ts"
click node_server "https://github.com/solvaratech/drawline-core/blob/main/src/server.ts"
click node_schema_types "https://github.com/solvaratech/drawline-core/blob/main/src/types/schemaDesign.ts"
click node_diff_types "https://github.com/solvaratech/drawline-core/blob/main/src/types/schemaDiff.ts"
click node_schema_converter "https://github.com/solvaratech/drawline-core/blob/main/src/utils/schemaConverter.ts"
click node_dep_graph "https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/DependencyGraph.ts"
click node_constraint_engine "https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/ConstraintEngine.ts"
click node_field_inference "https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/FieldInferenceEngine.ts"
click node_worker_pool "https://github.com/solvaratech/drawline-core/blob/main/src/generator/WorkerPool.ts"
click node_generator_index "https://github.com/solvaratech/drawline-core/blob/main/src/generator/index.ts"
click node_base_adapter "https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/BaseAdapter.ts"
click node_sql_adapters "https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/PostgresAdapter.ts"
click node_nosql_adapters "https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/MongoDBAdapter.ts"
click node_special_adapters "https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/CSVExportAdapter.ts"
click node_connections "https://github.com/solvaratech/drawline-core/blob/main/src/connections/index.ts"
click node_postgres_conn "https://github.com/solvaratech/drawline-core/blob/main/src/connections/postgresql.ts"
click node_mongo_conn "https://github.com/solvaratech/drawline-core/blob/main/src/connections/mongodb.ts"
click node_firestore_conn "https://github.com/solvaratech/drawline-core/blob/main/src/connections/firestore.ts"
click node_schema_diff "https://github.com/solvaratech/drawline-core/blob/main/src/schema/schemaDiffEngine.ts"
click node_orm_generators "https://github.com/solvaratech/drawline-core/blob/main/src/generators/orm/index.ts"
click node_logger "https://github.com/solvaratech/drawline-core/blob/main/src/utils/logger.ts"
click node_errors "https://github.com/solvaratech/drawline-core/blob/main/src/utils/errorMessages.ts"
click node_tests "https://github.com/solvaratech/drawline-core/blob/main/src/tests/e2e.test.ts"

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_index,node_cli,node_server toneBlue
class node_schema_types,node_diff_types,node_schema_converter toneAmber
class node_dep_graph,node_constraint_engine,node_field_inference,node_worker_pool,node_generator_index toneMint
class node_base_adapter,node_sql_adapters,node_nosql_adapters,node_special_adapters,node_connections,node_postgres_conn,node_mongo_conn,node_firestore_conn toneRose
class node_schema_diff,node_orm_generators toneIndigo
class node_logger,node_errors,node_tests toneTeal
```

## Components

### Entrypoints

Public surfaces for library, CLI, and service runtime.

- [Public API](https://github.com/solvaratech/drawline-core/blob/main/src/index.ts): library export · Aggregates the package's main exports. · `src/index.ts`
- [CLI](https://github.com/solvaratech/drawline-core/blob/main/src/cli.ts): command entry · Command-line surface for running the library. · `src/cli.ts`
- [Server API](https://github.com/solvaratech/drawline-core/blob/main/src/server.ts): runtime entry · 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](https://github.com/solvaratech/drawline-core/blob/main/src/types/schemaDesign.ts): contracts · Internal schema design and diff contracts shared across subsystems. · `src/types/schemaDesign.ts`
- [Diff Types](https://github.com/solvaratech/drawline-core/blob/main/src/types/schemaDiff.ts): contracts · Typed model for schema change detection and migration actions. · `src/types/schemaDiff.ts`
- [Schema Converter](https://github.com/solvaratech/drawline-core/blob/main/src/utils/schemaConverter.ts): translator · Bridges external schema shapes into Drawline's internal model. · `src/utils/schemaConverter.ts`

### Generation Engine

Deterministic data generation, ordering, and execution.

- [Dependency Graph](https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/DependencyGraph.ts): ordering engine · Sorts collections by foreign-key and dependency relationships. · `src/generator/core/DependencyGraph.ts`
- [Constraint Engine](https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/ConstraintEngine.ts): rules engine · Resolves cross-field rules, ranges, and generation constraints. · `src/generator/core/ConstraintEngine.ts`
- [Field Inference](https://github.com/solvaratech/drawline-core/blob/main/src/generator/core/FieldInferenceEngine.ts): inference engine · Infers realistic values from names and field metadata. · `src/generator/core/FieldInferenceEngine.ts`
- [Worker Pool](https://github.com/solvaratech/drawline-core/blob/main/src/generator/WorkerPool.ts): parallel runtime · Coordinates worker-thread execution for large deterministic jobs. · `src/generator/WorkerPool.ts`
- [Generator Facade](https://github.com/solvaratech/drawline-core/blob/main/src/generator/index.ts): orchestration layer · Main generator entrypoint that ties core logic together. · `src/generator/index.ts`

### Integrations

Database connectivity and write-side adapters.

- [Base Adapter](https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/BaseAdapter.ts): adapter contract · Common write-side boundary implemented by storage-specific adapters. · `src/generator/adapters/BaseAdapter.ts`
- [SQL Adapters](https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/PostgresAdapter.ts): storage adapters · PostgreSQL, MySQL, SQLite, and SQL Server write adapters. · `src/generator/adapters/PostgresAdapter.ts`
- [NoSQL Adapters](https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/MongoDBAdapter.ts): storage adapters · MongoDB, DynamoDB, Firestore, and Redis adapters. · `src/generator/adapters/MongoDBAdapter.ts`
- [Special Adapters](https://github.com/solvaratech/drawline-core/blob/main/src/generator/adapters/CSVExportAdapter.ts): storage adapters · CSV export, in-memory, ephemeral, and null/no-op modes. · `src/generator/adapters/CSVExportAdapter.ts`
- [Connections](https://github.com/solvaratech/drawline-core/blob/main/src/connections/index.ts): introspection layer · Database connectivity and schema introspection helpers. · `src/connections/index.ts`
- [Postgres Conn](https://github.com/solvaratech/drawline-core/blob/main/src/connections/postgresql.ts): connection module · PostgreSQL connectivity and introspection support. · `src/connections/postgresql.ts`
- [Mongo Conn](https://github.com/solvaratech/drawline-core/blob/main/src/connections/mongodb.ts): connection module · MongoDB connectivity and introspection support. · `src/connections/mongodb.ts`
- [Firestore Conn](https://github.com/solvaratech/drawline-core/blob/main/src/connections/firestore.ts): connection module · Firestore connectivity and introspection support. · `src/connections/firestore.ts`

### Derived Outputs

Schema diffing and ORM code generation outputs.

- [Schema Diff Engine](https://github.com/solvaratech/drawline-core/blob/main/src/schema/schemaDiffEngine.ts): transformation pipeline · Compares schemas and produces DDL-oriented changes. · `src/schema/schemaDiffEngine.ts`
- [ORM Generators](https://github.com/solvaratech/drawline-core/blob/main/src/generators/orm/index.ts): codegen facade · Shared entrypoint for Prisma, TypeORM, Drizzle, and Mongoose generators. · `src/generators/orm/index.ts`

### Support

Logging, error formatting, and test harnesses.

- [Logging](https://github.com/solvaratech/drawline-core/blob/main/src/utils/logger.ts): support · Shared logger and CLI logger utilities. · `src/utils/logger.ts`
- [Error Messages](https://github.com/solvaratech/drawline-core/blob/main/src/utils/errorMessages.ts): support · Centralized error formatting and user-facing messages. · `src/utils/errorMessages.ts`
- [Test Suite](https://github.com/solvaratech/drawline-core/blob/main/src/tests/e2e.test.ts): validation · Subsystem tests and end-to-end validation coverage. · `src/tests/e2e.test.ts`

## Connections

- 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.
