Code Generators
The velox make command scaffolds common code patterns for a single model at a time.
Available Generators
Section titled “Available Generators”| Generator | Alias | Description |
|---|---|---|
namespace | ns | Schema + procedures from existing Prisma model |
resource | r, res | Full resource stack (Prisma model + schema + procedures + tests) |
procedure | p, proc | Procedure files |
schema | s, zod | Zod schemas |
migration | mig | Prisma migrations |
model | m | Full model setup |
test | t, spec | Test files |
Namespace (Single Model)
Section titled “Namespace (Single Model)”The fastest way to scaffold procedures for a single existing Prisma model:
- Define your Prisma model
- Run
velox make namespace
The generator reads your Prisma schema, detects relations, and scaffolds type-safe procedures with the correct include clauses automatically.
Step 1: Define the Prisma Model
Section titled “Step 1: Define the Prisma Model”model Order { id String @id @default(uuid()) total Float status String @default("pending") createdAt DateTime @default(now()) updatedAt DateTime @updatedAt
customer Customer @relation(fields: [customerId], references: [id]) customerId String items OrderItem[]
@@map("orders")}Push the schema to your database:
pnpm db:pushStep 2: Generate the Namespace
Section titled “Step 2: Generate the Namespace”velox make namespace Order --exampleThis creates three files and auto-registers the procedures in your router:
Created: src/schemas/order.ts # Zod schemas (Create, Update, base) src/procedures/orders.ts # CRUD procedures with Prisma queries src/procedures/__tests__/orders.test.ts
Modified: src/index.ts # Auto-registered orderProceduresBecause the generator detected the customer (belongsTo) and items (hasMany) relations in your Prisma schema, the generated queries include them automatically:
// Generated procedures include detected relationsgetOrder: procedure() .input(z.object({ id: z.string().uuid() })) .query(async ({ input, ctx }) => { return ctx.db.order.findUnique({ where: { id: input.id }, include: { customer: true, items: true }, }); }),Options
Section titled “Options”| Option | Short | Description |
|---|---|---|
--example | -e | Include example CRUD procedures (recommended) |
--with-tests | -t | Generate test file (default: true) |
--skip-registration | -S | Skip auto-registering in router.ts |
Without --example
Section titled “Without --example”Running without --example creates a minimal scaffold with commented-out procedure examples, ready for you to fill in:
velox make namespace OrderResource (Full Stack)
Section titled “Resource (Full Stack)”Creates everything from scratch: Prisma model, Zod schema, procedures, and tests.
velox make resource ProductCreates: model, schema, procedures, and tests.
Procedure
Section titled “Procedure”velox make procedure usersvelox make procedure posts --crudSchema
Section titled “Schema”velox make schema Uservelox make schema Post --crudMigration
Section titled “Migration”velox make migration create_users_tablevelox make migration add_email_to_usersCommon Options
Section titled “Common Options”| Option | Description |
|---|---|
--crud | Include CRUD operations |
--soft-delete | Add deletedAt field |
--pagination | Add paginated list |
--dry-run | Preview without writing |
--json | Machine-readable output |
Output
Section titled “Output”velox make procedure users --crud
Created: src/procedures/users.ts - listUsers (GET /api/users) - getUser (GET /api/users/:id) - createUser (POST /api/users) - updateUser (PUT /api/users/:id) - deleteUser (DELETE /api/users/:id)Related Content
Section titled “Related Content”- Database Commands - Migrations
- Procedures - Procedure API
- Nested Relations - Auto-detected relation projection