AI-powered code generation tool for ServiceStack Apps. Generate TypeScript data models, C# APIs, migrations, and UI components from natural language prompts using LLMs.
- 🤖 AI-Powered Generation - Generate complete CRUD APIs from natural language prompts
- 📝 TypeScript Data Models - Define your data models in TypeScript with type safety
- 🔄 Auto-Generate C# Code - Automatically generate C# APIs, DTOs, and migrations
- 🗄️ Database Migrations - Create OrmLite migrations for your data models
- 🎨 UI Components - Generate Vue.js admin UI components
- 👀 Watch Mode - Auto-regenerate C# files when TypeScript models change
- 🔌 Multiple LLM Support - Use up to 5 different LLM models simultaneously
- 🔄 Schema Conversion - Convert existing database schemas to TypeScript models
npm install -g okai- Node.js >= 24.0.0
- A ServiceStack application with a
.slnor.slnxfile - ServiceStack project structure with ServiceModel directory
cd /path/to/appokai "Create a blog system with posts, comments, and tags"This will:
- Generate TypeScript data models (
.d.tsfile) - Create C# API DTOs and AutoQuery services
- Generate database migrations
- Create Vue.js admin UI components
- Show an interactive preview where you can review and accept the changes
okai Blog.d.tsokai Blog.d.ts --watchokai <prompt>Options:
-m, --models <model,model,...>- Specify up to 5 LLM models to use-l, --license <LC-xxx>- Provide ServiceStack license for premium models-v, --verbose- Display verbose logging
Example:
okai "Create a job board with companies, jobs, and applicants"okai "Create an e-commerce system" --models gpt-4,claude-3-opusRegenerate C# APIs, migrations, and UI from an existing TypeScript definition file:
okai <models>.d.tsOptions:
-w, --watch- Watch for changes and auto-regenerate
Example:
okai Blog.d.ts
okai Blog.d.ts --watchRemove a TypeScript model file and all its generated C# files:
okai rm <models>.d.tsExample:
okai rm Blog.d.tsDisplay available premium LLM models:
okai ls modelsCreate an okai.json configuration file with your project structure:
okai initThis auto-detects your ServiceStack project structure and creates a config file you can customize.
Create an empty TypeScript definition file for a specific model:
okai init <model>Example:
okai init BlogConvert .NET RDBMS table definitions to TypeScript data models:
okai convert <schema.json>Show detected project information:
okai infoSubmit a chat request to OpenAI:
okai chat <prompt>Options:
--system <prompt>- Specify a system prompt
Example:
okai chat "Explain AutoQuery" --system "You are a ServiceStack expert"Configure okai behavior using environment variables:
OKAI_URL- Base URL for the okai service (default:https://okai.servicestack.com)OKAI_MODELS- Default LLM models to use (comma-separated)SERVICESTACK_LICENSE- Your ServiceStack license key for premium models
Example:
export OKAI_MODELS="gpt-4,claude-3-opus"
export SERVICESTACK_LICENSE="..."
okai "Create a booking system"The okai.json file allows you to customize project paths:
{
"projectName": "MyApp",
"slnDir": "/path/to/solution",
"hostDir": "/path/to/MyApp",
"migrationsDir": "/path/to/MyApp/Migrations",
"serviceModelDir": "/path/to/MyApp.ServiceModel",
"serviceInterfaceDir": "/path/to/MyApp.ServiceInterfaces",
"uiMjsDir": "/path/to/MyApp/wwwroot/admin/sections",
"userType": "ApplicationUser",
"userIdType": "string",
"userLabel": "DisplayName"
}Generate this file automatically with:
okai initDefine your data models in TypeScript with special annotations:
/*prompt: Create a blog system
api: ~/MyApp.ServiceModel/Blog.cs
migration: ~/MyApp/Migrations/Migration1001.cs
ui: ~/MyApp/wwwroot/admin/sections/Blog.mjs
*/
export enum PostStatus {
Draft = "Draft",
Published = "Published",
Archived = "Archived"
}
export class BlogPost {
id: number
title: string
slug: string
content: string
status: PostStatus
authorId: string
publishedAt?: Date
createdAt: Date
updatedAt: Date
}
export class Comment {
id: number
postId: number
authorId: string
content: string
createdAt: Date
}
export class Tag {
id: number
name: string
slug: string
}
export class PostTag {
id: number
postId: number
tagId: number
}The header comment specifies where generated files should be saved:
prompt:- The original prompt used to generate the modelsapi:- Path to the generated C# API filemigration:- Path to the generated migration fileui:- Path to the generated UI component file
Paths starting with ~/ are relative to the detected project directories.
For each TypeScript model file, okai generates:
AutoQuery CRUD APIs with proper attributes and validation:
[Tag("Blog")]
public class QueryBlogPosts : QueryDb<BlogPost> {}
[Tag("Blog")]
public class CreateBlogPost : ICreateDb<BlogPost>, IReturn<IdResponse>
{
public string Title { get; set; }
public string Content { get; set; }
// ...
}OrmLite migrations for creating tables:
public class Migration1001 : MigrationBase
{
public override void Up()
{
Db.CreateTable<BlogPost>();
Db.CreateTable<Comment>();
// ...
}
public override void Down()
{
Db.DropTable<PostTag>();
Db.DropTable<Tag>();
// ...
}
}AutoQueryGrid components for admin interface:
export default {
group: "Blog",
items: {
BlogPosts: {
type: 'BlogPost',
component: {
template: `
<AutoQueryGrid :type="type"
selected-columns="id,title,status,authorId,publishedAt" />
`,
},
},
// ...
}
}-
Generate from prompt:
okai "Create a task management system with projects, tasks, and assignments" -
Review the generated TypeScript models in the interactive preview
-
Accept the changes by pressing
ain 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
You can edit the .d.ts file and regenerate as many times as needed:
# Edit tasks.d.ts to add new properties or models
vim tasks.d.ts
# Regenerate all C# files
okai tasks.d.tsokai "Create an e-commerce system with products, categories, orders, and customers"okai "Create a booking system with services, time slots, bookings, and customers"okai "Create a job board with companies, job listings, applications, and interviews"okai "Create a CRM with contacts, companies, deals, and activities"okai "Create an inventory system with warehouses, products, stock levels, and transfers"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"Use multiple LLM models to get the best results:
okai "Create a social network" --models gpt-4,claude-3-opus,gemini-proThe tool will use consensus from multiple models to generate better data structures.
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 with
okai <file>.d.ts
Use watch mode while developing:
okai Blog.d.ts --watchNow every time you save Blog.d.ts, the C# files are automatically regenerated.
Make sure you're running okai from within a ServiceStack project directory. Alternatively, create an okai.json config file:
okai initEnsure your ServiceStack project has a ServiceModel project. You can override the path in okai.json:
{
"serviceModelDir": "/custom/path/to/ServiceModel"
}If you encounter SSL certificate errors:
okai "your prompt" --ignore-ssl-errors