You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
AI-powered code generation tool for ServiceStack Apps. Generate TypeScript data models, C# APIs, migrations, and UI components from natural language prompts using LLMs.
Features
🤖AI-Powered Generation - Generate complete CRUD APIs from natural language prompts
📝TypeScript Data Models - Define your data models in TypeScript with type safety
Define your data models in TypeScript with special annotations:
/*prompt: Create a blog systemapi: ~/MyApp.ServiceModel/Blog.csmigration: ~/MyApp/Migrations/Migration1001.csui: ~/MyApp/wwwroot/admin/sections/Blog.mjs*/exportenumPostStatus{Draft="Draft",Published="Published",Archived="Archived"}exportclassBlogPost{id:numbertitle:stringslug:stringcontent:stringstatus:PostStatusauthorId:stringpublishedAt?:DatecreatedAt:DateupdatedAt:Date}exportclassComment{id:numberpostId:numberauthorId:stringcontent:stringcreatedAt:Date}exportclassTag{id:numbername:stringslug:string}exportclassPostTag{id:numberpostId:numbertagId:number}
Header Comments
The header comment specifies where generated files should be saved:
prompt: - The original prompt used to generate the models
api: - Path to the generated C# API file
migration: - Path to the generated migration file
ui: - Path to the generated UI component file
Paths starting with~/ are relative to the detected project directories.
Generated Files
For each TypeScript model file, okai generates:
1. C# API DTOs and Services
AutoQuery CRUD APIs with proper attributes and validation:
okai"Create a task management system with projects, tasks, and assignments"
Review the generated TypeScript models in the interactive preview
Accept the changes by pressinga in the preview
Edit the TypeScript models if needed (add validations, change types, etc.)
Regenerate C# files:
okai tasks.d.ts
Use watch mode during development:
okai tasks.d.ts --watch
Run migrations in your ServiceStack app to create the database tables
Access the admin UI to manage your data
Iterative Refinement
You can edit the.d.ts file and regenerate as many times as needed:
# Edit tasks.d.ts to add new properties or modelsvim tasks.d.ts# Regenerate all C# filesokai tasks.d.ts
Examples
E-Commerce System
okai"Create an e-commerce system with products, categories, orders, and customers"
Booking System
okai"Create a booking system with services, time slots, bookings, and customers"
Job Board
okai"Create a job board with companies, job listings, applications, and interviews"
CRM System
okai"Create a CRM with contacts, companies, deals, and activities"
Inventory Management
okai"Create an inventory system with warehouses, products, stock levels, and transfers"
Tips
Use Specific Prompts
The more specific your prompt, the better the results:
❌Too vague:
okai"Create a blog"
✅Better:
okai"Create a blog system with posts, comments, tags, categories, and authors. Posts should have status (draft/published), featured images, and SEO metadata"
Leverage Multiple Models
Use multiple LLM models to get the best results:
okai"Create a social network" --models gpt-4,claude-3-opus,gemini-pro
The tool will use consensus from multiple models to generate better data structures.
Customize Generated Code
After generation, you can:
Edit the TypeScript models to add custom properties
Add TypeScript decorators for validation
Modify relationships between models
Then regenerate the C# code withokai <file>.d.ts
Watch Mode for Rapid Development
Use watch mode while developing:
okai Blog.d.ts --watch
Now every time you saveBlog.d.ts, the C# files are automatically regenerated.
Troubleshooting
"No .sln or .slnx file found"
Make sure you're running okai from within a ServiceStack project directory. Alternatively, create anokai.json config file:
okai init
"Could not find ServiceModel directory"
Ensure your ServiceStack project has aServiceModel project. You can override the path inokai.json: