Chapter 19: CLI & Scaffolding
1. Getting a New Developer Up to Speed
A new developer joins your team. You hand them the repo URL. By 10am they have a running project, a new database model, CRUD routes, a migration, and a deployment to staging. All from the command line.
The Tina4 CLI is a single Rust binary. It manages all four Tina4 frameworks: PHP, Python, Ruby, and Node.js. Same commands across all languages.
2. tina4 init -- Project Scaffolding
tina4 init my-projectCreating Tina4 project in ./my-project ...
Detected language: Node.js (package.json)
Created .env
Created .env.example
Created .gitignore
Created src/routes/
Created src/orm/
Created src/migrations/
Created src/seeds/
Created src/templates/
Created src/public/
Created data/
Created logs/
Created secrets/
Created tests/
Project created! Next steps:
cd my-project
npm install
tina4 serveLanguage Detection
The CLI detects the language from the project directory:
| File Found | Language |
|---|---|
package.json | Node.js |
composer.json | PHP |
pyproject.toml | Python |
Gemfile | Ruby |
3. tina4 serve -- Dev Server
tina4 serve Tina4 Node.js v3.0.0
Server running at http://0.0.0.0:7148
Debug mode: ON
Live reload: ONOptions:
tina4 serve --port 8080
tina4 serve --host 127.0.0.1
tina4 serve --no-reload4. tina4 generate -- Code Generation
Generate a Model
tina4 generate model ProductCreates src/orm/Product.ts:
import { BaseModel } from "tina4-nodejs";
export class Product extends BaseModel {
static tableName = "products";
static primaryKey = "id";
id!: number;
createdAt!: string;
updatedAt!: string;
}Generate a Route
tina4 generate route productsCreates src/routes/products.ts with GET, POST, PUT, DELETE stubs.
Generate a Migration
tina4 generate migration create_products_tableCreates src/migrations/20260322143000_create_products_table.sql.
Generate a Test
tina4 generate test ProductTestCreates tests/ProductTest.ts with test stubs.
5. tina4 migrate -- Database Migrations
tina4 migrate # Apply pending migrations
tina4 migrate:status # Show migration status
tina4 migrate:rollback # Roll back last migration
tina4 migrate:create NAME # Create a new migration6. tina4 routes -- Route Listing
tina4 routes
tina4 routes --method POST
tina4 routes --filter users7. tina4 queue -- Queue Management
tina4 queue:work # Start processing jobs
tina4 queue:work --queue send-email # Process specific queue
tina4 queue:dead # List dead letter jobs
tina4 queue:retry 42 # Retry a dead job
tina4 queue:clear --older-than 7d # Clear old dead jobs8. tina4 test -- Running Tests
tina4 test # Run all tests
tina4 test --filter ProductTest # Run specific test classOr use npm:
npm testThis runs tests/run-all.ts which discovers and executes all test classes.
9. tina4 doctor -- System Check
tina4 doctorSystem Check
Node.js: v20.11.1 [OK]
npm: 10.2.4 [OK]
tsx: 4.7.0 [OK]
SQLite: 3.43.0 [OK]
.env: found [OK]
Database: connected [OK]
AI tools detected:
Claude Code: .claude/ [FOUND]
Cursor: .cursor/ [NOT FOUND]10. tina4 build -- Production Build
tina4 buildCompiles TypeScript to JavaScript. Bundles for production. Optimizes:
Building for production...
Compiled 47 TypeScript files
Output: dist/
Size: 245KB
Ready for deployment:
node dist/app.js11. Custom CLI Commands
Create custom commands by adding files to src/commands/:
// src/commands/seed-products.ts
import { Command, Database } from "tina4-nodejs";
export default class SeedProducts extends Command {
static command = "seed:products";
static description = "Seed the database with sample products";
async run() {
const db = Database.getConnection();
const products = [
{ name: "Keyboard", price: 79.99 },
{ name: "Mouse", price: 29.99 },
{ name: "Monitor", price: 399.99 }
];
for (const p of products) {
await db.execute(
"INSERT INTO products (name, price) VALUES (:name, :price)",
p
);
}
console.log(`Seeded ${products.length} products`);
}
}Run it:
tina4 seed:products12. Exercise: Scaffold a Blog Project
Use the CLI to scaffold a complete blog project from scratch.
Requirements
- Initialize a new project called
my-blog - Generate models: User, Post, Comment
- Generate migrations for each model
- Generate routes for posts and comments
- Run migrations
- Generate tests for the Post API
- Run the test suite
13. Solution
tina4 init my-blog
cd my-blog
npm install
tina4 generate model User
tina4 generate model Post
tina4 generate model Comment
tina4 generate migration create_users_table
tina4 generate migration create_posts_table
tina4 generate migration create_comments_table
# Edit migrations to add columns, then:
tina4 migrate
tina4 generate route posts
tina4 generate route comments
tina4 generate test PostApiTest
npm test
tina4 serve