CodeAI Declarative Backend Framework for LLMs
Build production-ready APIs with human-readable .cai files.
Free, open-source, and designed for AI code generation.
entity User {
id uuid @primary
email string @unique
name string
createdAt timestamp @default(now)
}
api UserAPI {
GET "/users" → list
GET "/users/:id" → read
POST "/users" → create
PUT "/users/:id" → update
DELETE "/users/:id" → delete
}
Why CodeAI?
A declarative backend framework designed from the ground up for LLM code generation. Write less, deploy more.
LLM-Friendly Syntax
Declarative constructs optimized for AI token prediction patterns. LLMs write .cai specs that compile to production-ready Go code.
Production Ready
Built-in authentication (JWT, JWKS), Redis caching, Temporal workflows, and Asynq job queues. Everything you need for enterprise backends, out of the box.
Type Safe
Go-powered runtime with compile-time type checking. Catch errors before deployment with strict validation and AST analysis during the build phase.
Fault Tolerant
Flexible whitespace handling and lenient syntax variations. Graceful error recovery ensures your specs parse even with minor formatting issues.
OpenAPI Generation
Automatic OpenAPI 3.0 specification generation from your DSL. Get interactive API documentation and client SDKs without any extra configuration.
Enterprise Features
Temporal SDK for durable workflows, Asynq for distributed job scheduling, Redis caching with circuit breakers, and Prometheus metrics built-in.
Zero Boilerplate
No manual routing, middleware setup, or SQL queries. Define your entities and APIs declaratively; the runtime handles the rest automatically.
Open Source
MIT licensed and community-driven. Contribute, customize, and deploy without vendor lock-in. Full transparency and freedom to extend.
How It Works
From declarative specs to production APIs in seconds. Watch your .cai files transform into a fully-featured backend.
DSL Layer
.cai Files
Parser
Participle v2
Go Runtime
Production Engine
REST API
OpenAPI 3.0
DSL Layer
.cai declarative specifications
Parser
Participle v2 lexer & AST
Go Runtime
Chi, PostgreSQL, MongoDB, Redis, Temporal, Asynq
REST API
OpenAPI 3.0 with auto-generated docs
Get Started in Minutes
From zero to a running API in four simple steps. No complex configuration required.
Install CodeAI
Install the CodeAI CLI with a single command. Requires Go 1.24+ installed on your system.
# Install CodeAI CLI
curl -sSL https://raw.githubusercontent.com/bargom/codeai/main/install.sh | sh
Create Your First .cai File
Define your MongoDB collection and REST API endpoints in a single declarative file. This example shows full CRUD operations with validation, type-safe handlers, and automatic route registration.
# Create app.cai
cat > app.cai << 'EOF'
config {
database_type: "mongodb"
mongodb_uri: "mongodb://localhost:27017"
mongodb_database: "myapp"
}
database mongodb {
collection User {
_id: objectid, primary, auto
name: string, required
email: string, required, unique
age: int, optional
created_at: date, auto
}
}
// REST API Endpoints
endpoint POST "/users" {
request CreateUserRequest from body
response User status 201
do {
validate(request)
insert("users", request)
}
}
endpoint GET "/users/:id" {
request User from path
response User status 200
do {
validate(id)
query("users", id)
}
}
endpoint PUT "/users/:id" {
request UpdateUserRequest from body
response User status 200
do {
validate(id)
validate(request)
update("users", id, request)
}
}
endpoint DELETE "/users/:id" {
response Empty status 204
do {
validate(id)
delete("users", id)
}
}
EOF
Start the Server
Start MongoDB with Docker, then launch CodeAI. It parses your .cai file and automatically registers all your REST endpoints.
# Start MongoDB
docker run -d --name mongodb -p 27017:27017 mongo:7
# Start CodeAI (reads config from app.cai)
codeai server start
# Output:
INFO Connected to MongoDB
INFO Registered endpoint: POST /users
INFO Registered endpoint: GET /users/:id
INFO Registered endpoint: PUT /users/:id
INFO Registered endpoint: DELETE /users/:id
INFO Server listening on localhost:8080
Test Your REST API
Test your endpoints with curl. All CRUD operations are automatically available based on your endpoint definitions.
# Create a user
curl -X POST http://localhost:8080/users \
-H "Content-Type: application/json" \
-d '{"name":"Alice","email":"alice@example.com","age":25}'
# Get user by ID
curl http://localhost:8080/users/507f1f77bcf86cd799439011
# Update user
curl -X PUT http://localhost:8080/users/507f1f77bcf86cd799439011 \
-H "Content-Type: application/json" \
-d '{"name":"Alice Smith","age":26}'
# Delete user
curl -X DELETE http://localhost:8080/users/507f1f77bcf86cd799439011
See It In Action
Explore real .cai examples. Click on the tabs below to see different features.
// Define REST endpoints with minimal syntax
endpoint GET /tasks {
description: "List all tasks with filtering"
auth: optional
query {
status: string, optional
page: integer, default(1)
limit: integer, default(20)
}
returns: paginated(Task)
}
endpoint POST /tasks {
description: "Create a new task"
auth: required
body {
title: string, required
description: text, optional
priority: integer, default(1)
}
returns: Task
on_success: emit(TaskCreated)
}
Real-World Examples
Explore complete, production-ready examples. Each project demonstrates different CodeAI features and patterns.
Hello World / Task Manager
A simple task/todo API demonstrating basic CRUD operations, authentication, and events.
- Entity definitions with typed fields
- REST endpoints for CRUD
- JWT authentication
- Event emission
entity Task {
id: uuid, primary, auto
title: string, required
status: enum(pending, done)
created_at: timestamp, auto
}
Blog API
Multi-entity blog platform with users, posts, comments, and categories with full RBAC.
- Entity relationships (ref)
- Role-based access (RBAC)
- Soft delete support
- Full-text search
entity Post {
id: uuid, primary, auto
title: string, searchable
author_id: ref(User)
deleted_at: timestamp, soft_delete
}
E-commerce Backend
Complete order processing with products, cart, checkout workflow, and payment integration.
- Order workflow (Temporal)
- Saga pattern with rollback
- Payment integration
- Inventory management
workflow ProcessOrder {
trigger: OrderPlaced
steps {
validate_inventory { ... }
charge_payment { ... }
}
}
External Integrations
Resilient external API patterns with circuit breakers, webhooks, and GraphQL support.
- Circuit breaker patterns
- Retry with backoff
- Webhook delivery
- GraphQL integration
integration PaymentAPI {
circuit_breaker: {
threshold: 5 failures in 1m
reset_after: 30s
}
}
Scheduled Jobs
Background job processing with cron scheduling, queues, retries, and monitoring.
- Cron-based scheduling
- Priority job queues
- Report generation
- Data maintenance tasks
job DailyReport {
schedule: "0 6 * * *"
queue: default
timeout: 30m
retry: 3 times
}
Each example includes documentation, test scripts, and is fully runnable