ztd-cli Package Concept Draft
This page is a Concept Spec draft for the target direction of @rawsql-ts/ztd-cli. It describes the intended package concept, not the current implementation state.
Message
This message is the package positioning statement. It is not a complete summary of responsibilities; it is the short promise the package should make before readers inspect the detailed concept boundary.
Definition
ztd-cli is a runtime-free code generation CLI for SQL-first backend development.
It treats DDL as the single source of truth for data structure, uses rawsql-ts SQL AST analysis at generation time, and generates SQL execution boundaries, DAO-style access code, AOT row mappers, and ZTD-backed unit-test scaffolds.
The standard generated runtime path does not require ztd-cli, rawsql-ts, runtime mapper libraries, or runtime validator libraries. It may use a thin driver adapter so reviewable SQL files can keep named parameters while the selected database driver receives its required placeholder format.
Responsibilities
- Use DDL as the source of truth for table, column, constraint, and database type information.
- Use
rawsql-tsSQL AST analysis during code generation, inspection, scaffolding, and checks. - Generate reviewable SQL assets and application-side SQL execution boundaries.
- Generate DAO-style access code that calls explicit SQL resources and generated mappers.
- Generate AOT row mappers instead of relying on runtime mapping descriptors.
- Generate ZTD-backed query-boundary tests that exercise SQL execution and mapper behavior.
- Provide generated mapper drift checks so SQL, boundary contracts, and generated mapper artifacts stay aligned.
- Keep SQL files readable by allowing named parameters and delegating driver placeholder conversion to a thin adapter boundary.
- Support PostgreSQL as the current standard database target.
Non-Responsibilities
ztd-cliis not a runtime ORM.ztd-cliis not a runtime fluent SQL builder.ztd-clidoes not participate in production runtime behavior.ztd-clishould be needed only as a development-time code generation, inspection, and verification dependency.ztd-cliaffects application code only through generated artifacts and mechanical checks.ztd-cliis not the standard production runtime for SQL AST rewriting.ztd-clidoes not make runtime DB row validation with Zod, ArkType, or similar validators part of the standard mapper path.ztd-clidoes not use SQL-side JSON shaping or SQL JSON result construction as a generated result-mapping strategy.ztd-clidoes not hide business SQL shape behind runtime SQL rewriting in the standard path.ztd-cliis not a database driver and does not own connection pooling, transactions, or driver lifecycle.- Advanced runtime SQL processing, such as pipeline execution, scalar helpers, SSSQL optional-branch pruning, and parameter compression, belongs outside the core standard generated runtime path.
Invariants
- Generated standard runtime code must execute without depending on
ztd-clior SQL AST transformation libraries. - SQL remains a reviewable source artifact; runtime behavior must not depend on hidden SQL shape changes in the standard path.
- Driver adapter behavior must be limited to driver-facing mechanics such as named-parameter compilation and row-result normalization. It must not become ORM behavior, runtime result validation, SQL result shaping, or hidden business SQL rewriting.
- DDL is the source of truth for database structure, but it is not the source of truth for business concepts, process decisions, or feature intent.
- Runtime DB row validation is not required on the hot mapper path when the SQL contract and mapper are covered by generated mapper drift checks and ZTD-backed tests.
- A DAO generated by
ztd-clican be treated as type-safe when its SQL contract, generated mapper, and ZTD mapper tests are aligned and passing. - AOT mapper generation must be reproducible from source artifacts.
- Mapper drift must fail through a mechanical check rather than relying on humans to notice stale generated code.
- Generated code must keep the boundary between generated artifacts and human-owned SQL, query contracts, and test cases visible.
Rationale
Database result rows are a narrower trust boundary than external requests. The database already enforces strong structure through types, NOT NULL, constraints, and query semantics.
For the standard ztd-cli path, mapper correctness should therefore be shifted left into DDL review, SQL review, query-boundary contracts, generated mapper drift checks, and ZTD-backed mapper tests.
This keeps production runtime code small and direct while preserving a strong review and verification story.
Target Runtime Shape
The target standard runtime shape is:
SQL file with :name parameters
+ thin driver adapter
+ generated DAO
+ generated AOT mapperThe target verification shape is:
DDL + query contract + generated mapper drift check + ZTD-backed mapper testThis means the runtime path should be close to direct SQL execution plus direct assignment into DTOs.
Out Of Scope For This Draft
- Exact package split for advanced runtime SQL processing.
- Migration plan for legacy runtime mapper, catalog, and writer APIs.
- Deprecation schedule for JSON result construction helpers.
- Generated file layout details.
- CLI command names and command-line option design.
- Non-PostgreSQL support policy.
Open Questions
- Which advanced runtime SQL processing features should move into a separate package first?
- Should the separated advanced runtime package be positioned as optional infrastructure or as a compatibility layer?
- Which driver-specific adapter packages should be added after the core driver adapter boundary?
- Which current scaffold outputs must change before the
ztd-cliconcept can move from draft to defined? - What minimum generated project smoke test proves the runtime-free standard path?
- How should legacy runtime API users be guided through the transition without hiding the new concept boundary?