Skip to content

Scaffolding and Development

Reference for TypoKit CLI commands that scaffold new projects and modules, run builds, and start the development server.

Every command accepts these global flags:

FlagDescription
--root <dir>Project root directory (default: current working directory)
--verbose, -vShow detailed output including timing and file-level information

Create a new TypoKit project from a starter template.

Syntax

Terminal window
typokit init [name]

Arguments

ArgumentDescription
nameProject directory name (optional — prompts if omitted)

Flags

FlagDescription
--verbose, -vShow detailed output

What it does

  1. Prompts for project name (if not provided as argument)
  2. Prompts for server adapter (Native, Fastify, Hono, or Express)
  3. Prompts for database adapter (Drizzle, Kysely, Prisma, or Raw SQL)
  4. Creates project directory with src/types.ts, route modules, and configuration
  5. Generates typokit.config.ts with chosen adapters
  6. Installs dependencies with the detected package manager

Example

Terminal window
typokit init my-api
? Choose a server adapter: › Native (recommended)
? Choose a database adapter: › Drizzle
✔ Created my-api/
├── src/
│ ├── types.ts schema type definitions
│ ├── app.ts app factory
│ └── routes/ route contracts & handlers
├── typokit.config.ts
└── package.json
✔ Dependencies installed
✔ Ready! Run `cd my-api && typokit dev` to start.

Scaffold a new route module with contract and handler files.

Syntax

Terminal window
typokit add route <name>

Arguments

ArgumentDescription
nameRoute name (e.g., users, posts, auth/login)

Flags

FlagDescription
--verbose, -vShow detailed output

What it does

  1. Creates contracts.ts defining route contracts with typed parameters, query, body, and response
  2. Creates handlers.ts with handler stubs matching the contracts
  3. Places files under the configured routeFiles glob path (default: packages/server/src/routes/<name>/)

Example

Terminal window
typokit add route users
✔ Created packages/server/src/routes/users/
├── contracts.ts Route contracts (GET, POST, GET/:id, PUT/:id, DELETE/:id)
└── handlers.ts Handler implementations
Next: Define your types, then register the route group in app.ts.

Generated contracts.ts:

import type { RouteContract } from "@typokit/core";
export const getUsers: RouteContract<void, { page?: number }, void, User[]> = {
method: "GET",
path: "/users",
};
export const createUser: RouteContract<void, void, CreateUserInput, User> = {
method: "POST",
path: "/users",
};
export const getUser: RouteContract<{ id: string }, void, void, User> = {
method: "GET",
path: "/users/:id",
};
export const updateUser: RouteContract<{ id: string }, void, UpdateUserInput, User> = {
method: "PUT",
path: "/users/:id",
};
export const deleteUser: RouteContract<{ id: string }, void, void, void> = {
method: "DELETE",
path: "/users/:id",
};

Scaffold a new service file for shared business logic.

Syntax

Terminal window
typokit add service <name>

Arguments

ArgumentDescription
nameService name (e.g., email, auth, notifications)

Flags

FlagDescription
--verbose, -vShow detailed output

What it does

  1. Creates a service file with a factory function and typed interface
  2. Places the file under packages/server/src/services/<name>.ts

Example

Terminal window
typokit add service email
✔ Created packages/server/src/services/email.ts
Next: Import and register the service in your app configuration.

Generated email.ts:

export interface EmailService {
send(to: string, subject: string, body: string): Promise<void>;
}
export function createEmailService(): EmailService {
return {
async send(to, subject, body) {
// TODO: Implement email sending
throw new Error("Not implemented");
},
};
}

Run the full build pipeline — resolving type files, running the Rust transform, emitting plugin outputs, and compiling TypeScript.

Syntax

Terminal window
typokit build

Flags

FlagDescription
--verbose, -vShow detailed timing and file-level output

What it does

  1. Resolve files — Finds all type files and route files from typokit.config.ts globs
  2. Rust transform — Parses TypeScript AST to extract type metadata, JSDoc tags, and route contracts
  3. Plugin hooks — Runs build pipeline hooks (beforeTransformafterTypeParseafterValidatorsafterRouteTableemitcompiledone)
  4. Emit artifacts — Generates validators, database schemas, OpenAPI spec, client code, and contract tests to the output directory (default: .typokit/)
  5. Compile — Runs the compile hook, then the default TypeScript compiler (tsc). Plugins like @typokit/plugin-axum can override this step to run their own compiler (e.g., cargo build)

Example

Terminal window
typokit build
● Resolving type files... 12 files found
● Resolving route files... 8 files found
● Running transform... done in 145ms
● Emitting validators... 12 files
● Emitting DB schema... 6 tables
● Emitting OpenAPI spec... 24 operations
● Emitting client... 8 modules
● Emitting contract tests... 24 test files
● TypeScript compile... done in 2.1s
✔ Build complete (2.4s)

With --verbose:

Terminal window
typokit build --verbose
● Resolving type files...
packages/schema/src/user.ts
packages/schema/src/post.ts
packages/schema/src/comment.ts
... (12 files)
● Running Rust transform (145ms)
├── Parse AST: 45ms
├── Extract metadata: 32ms
└── Validate schemas: 68ms
● Plugin: afterTypeParse (2 hooks)
├── plugin-debug: 1ms
└── plugin-ws: 3ms
● Emitting validators...
.typokit/validators/user.ts (2.1kB)
.typokit/validators/post.ts (1.8kB)
...
✔ Build complete (2.4s)

Start the development server with file watching for incremental rebuilds.

Syntax

Terminal window
typokit dev [--debug-port <port>]

Flags

FlagDescription
--debug-port <port>Debug sidecar port (default: 9800)
--verbose, -vShow detailed rebuild output

What it does

  1. Runs an initial full build (same as typokit build)
  2. Starts the server using the configured server adapter
  3. Watches type files and route files for changes
  4. On file change, performs an incremental rebuild using the AST cache and dependency graph — only re-processing affected files
  5. If @typokit/plugin-debug is registered, starts the debug sidecar on the specified port

Example

Terminal window
typokit dev
● Initial build... done in 2.4s
● Server listening on http://localhost:3000
● Debug sidecar on http://localhost:9800
● Watching for changes...
[18:30:45] Changed: packages/schema/src/user.ts
● Incremental rebuild... done in 89ms (3 files affected)
● Server reloaded

With a custom debug port:

Terminal window
typokit dev --debug-port 9229
● Initial build... done in 2.4s
● Server listening on http://localhost:3000
● Debug sidecar on http://localhost:9229
● Watching for changes...