️ CLI Scaffold Generator

Generate complete CRUD functionality from an existing model with a single command. The scaffold generator creates web + API routes, a template and tries to link the routes in main.py using safe patching (it never rewrites the file blindly).

Basic Usage

First, create your model using the model CLI (it only asks for the model name and writes a starter model), then generate the scaffold:

Scaffold Generator


# Create a model first
lila model create --name Product

# Generate the complete CRUD scaffold
lila crud --model Product

# Custom route slug
lila crud --model Product --name products

# Apply the new table (adds missing columns too)
lila migrate

What Gets Generated

The scaffold generator creates:

  • app/routes/api/{name}.py - Pydantic Create/Update models and the JSON API
  • app/routes/web/{name}.py - page that renders the DataTable
  • resources/html/{name}/index.jinja - DataTable with create/edit modals
  • a safe import/link attempt in main.py (via lila.cli._patch.patch_main)

If a generated file already exists and the content changes, the previous version is kept next to it with a .bak suffix.

️ Generated Endpoints

With the default route slug (product) the generated routes are:

API Endpoints


GET    /product              → HTML page with the ResponsiveDataTable
GET    /api/product          → JSON list (selects the display columns)
GET    /api/product/{id}     → JSON single product (404 if missing)
POST   /api/product          → Create (CSRF required)
PUT    /api/product/{id}     → Update (CSRF required)
DELETE /api/product/{id}     → Soft delete (active=0) (CSRF required)

csrf=True is set on the write routes, so the client must send X-CSRF-Token (the generated template uses Http(), which adds it from the page's <meta name="csrf-token">).

Features

  • ✅ Validates that the model exists before generating
  • ✅ Responsive DataTable with search and pagination
  • ✅ Create and Edit modals
  • ✅ Soft delete functionality (active=0)
  • ✅ Real Pydantic Create/Update models, not comments
  • ✅ CSRF on POST/PUT/DELETE
  • ✅ Safe main.py patching, with .bak backups

Customization

After generation, you can customize:

  • the import/link in main.py if the automatic patch could not apply
  • app/routes/api/{name}.py to add business logic or auth
  • the Pydantic models to add fields/constraints
  • the HTML template, columns and form fields
  • router-level middlewares (auth=True, rate_limit, ...)