> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zopio.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# crud-schema

> Generate JSON schema and TypeScript interface for a model

# CRUD Schema Command

The `crud-schema` command generates JSON schema and TypeScript interface definitions for a model in your `zopio` project. This helps ensure type safety and data validation across your application.

## Usage

```bash theme={"system"}
zopio crud-schema [options]
```

## Options

| Option                     | Description                             |
| -------------------------- | --------------------------------------- |
| `-m, --model <name>`       | Model name                              |
| `-f, --fields <fields>`    | Fields in format "name:type,age:number" |
| `-o, --output <directory>` | Output directory for generated schemas  |
| `-h, --help`               | Display help for command                |

## Examples

### Generate schema for a User model

```bash theme={"system"}
zopio crud-schema --model User --fields "name:string,email:string,age:number,isActive:boolean"
```

### Generate schema with a custom output directory

```bash theme={"system"}
zopio crud-schema --model Product --fields "name:string,price:number,description:string,inStock:boolean" --output src/schemas
```

## Generated Files

When you run the `crud-schema` command, the following files will be generated:

1. **TypeScript Interface**: A TypeScript interface for the model
2. **JSON Schema**: A JSON schema definition for validation
3. **Schema Utils**: Helper functions for working with the schema

### Example TypeScript Interface

```typescript theme={"system"}
export interface User {
  id: string;
  name: string;
  email: string;
  age: number;
  isActive: boolean;
  createdAt: Date;
  updatedAt: Date;
}
```

### Example JSON Schema

```json theme={"system"}
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "User",
  "type": "object",
  "properties": {
    "id": { "type": "string", "format": "uuid" },
    "name": { "type": "string" },
    "email": { "type": "string", "format": "email" },
    "age": { "type": "number" },
    "isActive": { "type": "boolean" },
    "createdAt": { "type": "string", "format": "date-time" },
    "updatedAt": { "type": "string", "format": "date-time" }
  },
  "required": ["name", "email"]
}
```

## Related Commands

* [`crud`](/cli/01_commands/crud) - Generate basic CRUD operations
* [`crud-unified`](/cli/01_commands/crud-unified) - Generate a complete CRUD setup
* [`crud-validation`](/cli/01_commands/crud-validation) - Generate validation schemas
