katax-cli
v1.0.0
Published
CLI tool to generate Express APIs with TypeScript and katax-core validation
Maintainers
Readme
Katax CLI
🚀 CLI tool to generate Express REST APIs with TypeScript and katax-core validation.
✨ Features
- 🎯 Quick API Setup - Initialize Express + TypeScript projects in seconds
- ✅ Built-in Validation - Integrates katax-core for type-safe schema validation
- 🔧 Code Generation - Generate endpoints, CRUD operations, and routes
- 📦 Database Support - PostgreSQL, MySQL, MongoDB, or none
- 🔐 JWT Authentication - Optional JWT auth scaffolding
- 📝 TypeScript First - Full type safety and IntelliSense support
- 🎨 Interactive CLI - Beautiful prompts and feedback
📦 Installation
# Global installation
npm install -g @katax/cli
# Or use with npx (no installation needed)
npx @katax/cli init my-api🚀 Quick Start
1. Create a New API Project
katax init my-apiThis will:
- Create project structure
- Setup TypeScript + Express
- Install dependencies
- Configure katax-core validation
- Add database connection (optional)
- Setup JWT authentication (optional)
2. Add an Endpoint
cd my-api
katax add endpoint usersInteractive prompts will guide you through:
- HTTP method (GET, POST, PUT, DELETE)
- Route path
- Request fields and validation rules
- Async validators (unique checks, etc.)
🚀 CLI tool to generate Express REST APIs with TypeScript and katax-core validation.
- 🔧 Code Generation - Generate endpoints, CRUD operations, and routes
- 📦 Database Support - PostgreSQL, MySQL, MongoDB, or none
- 🔐 JWT Authentication - Optional JWT auth scaffolding
- 📝 TypeScript First - Full type safety and IntelliSense support
- 🎨 Interactive CLI - Beautiful prompts and feedback
📦 Installation
# Global installation
npm install -g katax-cli
# Or use with npx (no installation needed)
npx katax-cli init my-api🚀 Quick Start
1. Create a New API Project
katax init my-apiThis will:
- Create project structure
- Setup TypeScript + Express
- Install dependencies
- Configure katax-core validation
- Add database connection (optional)
- Setup JWT authentication (optional)
2. Add an Endpoint
cd my-api
katax add endpoint usersInteractive prompts will guide you through:
- HTTP method (GET, POST, PUT, DELETE)
- Route path
- Request fields and validation rules
- Async validators (unique checks, etc.)
This generates:
users.validator.ts- katax-core validation schemasusers.controller.ts- Business logicusers.routes.ts- Express routes- Updates main router automatically
3. Generate CRUD Resource
katax generate crud productsCreates a complete CRUD API with 5 endpoints:
GET /api/products- List allGET /api/products/:id- Get onePOST /api/products- Create
katax init [project-name]
Initialize a new Express API project.
Options:
-f, --force- Overwrite existing directory katax init my-awesome-api
### `katax add endpoint <name>`
Add a new endpoint with validation.
**Options:**
- `-m, --method <method>` - HTTP method (GET, POST, PUT, DELETE)
**Example:**
```bash
katax add endpoint users -m POST -p /api/userskatax generate crud <resource-name>
Generate a complete CRUD resource.
Options:
--no-auth- Skip authentication middleware
Example:
katax generate crud productskatax info
Show current project structure and routes.
Aliases: status, ls
Example:
katax info🎯 Generated Code Example
When you run katax add endpoint users, it generates:
users.validator.ts:
import { k, kataxInfer } from 'katax-core';
export const usersSchema = k.object({
username: k.string()
.minLength(3, 'Username must be at least 3 characters')
.maxLength(50, 'Username cannot exceed 50 characters'),
email: k.string().email('Must be a valid email'),
age: k.number().min(0, 'Age must be positive').optional()
});
export type UsersData = kataxInfer<typeof usersSchema>;
export async function validateUsers(data: unknown) {
return await usersSchema.safeParse(data);
}users.controller.ts:
import { UsersData } from './users.validator.js';
import { ControllerResult, createSuccessResult } from '../../shared/api.utils.js';
export async function createUsers(data: UsersData): Promise<ControllerResult<any>> {
try {
// Your business logic here
const newUser = { id: 1, ...data, createdAt: new Date() };
return createSuccessResult('User created successfully', newUser, undefined, 201);
} catch (error) {
// Error handling
}
}users.routes.ts:
import { Router } from 'express';
import { createUsers } from './users.controller.js';
# Katax CLI
[](https://www.npmjs.com/package/katax-cli)
[](https://opensource.org/licenses/MIT)
Katax CLI — generate Express REST APIs with TypeScript and katax-core validation.
## Features
- Quick project scaffolding (Express + TypeScript)
- katax-core integration for type-safe validation
- Generate endpoints, CRUD resources and routes
- Optional DB scaffolding (Postgres / MySQL / MongoDB)
- Optional JWT authentication
## Installation
```bash
# global
npm install -g katax-cli
# or run with npx
npx katax-cli init my-apiUsage
katax init <name>— initialize a new API projectkatax add endpoint <name>— add endpoint with validationkatax generate crud <resource>— scaffold full CRUDkatax info— show project structure and routes
Development
Run development server:
npm run devBuild and publish:
npm run build
npm publishExample generated files
users.validator.ts— katax-core schemausers.controller.ts— business logicusers.routes.ts— express routes
Links
- Repository: https://github.com/LOPIN6FARRIER/katax-cli
- katax-core: https://github.com/LOPIN6FARRIER/katax-core
MIT © Vinicio Esparza
