CodeAI Declarative Backend Framework for LLMs

Build production-ready APIs with human-readable .cai files. Free, open-source, and designed for AI code generation.

api.cai
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
}
Type-Safe Auto-Validated OpenAPI Ready

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 declarative specifications

Parser

Participle v2 lexer & AST

Go Runtime

Chi, PostgreSQL, MongoDB, Redis, Temporal, Asynq

REST API

OpenAPI 3.0 with auto-generated docs

Go 1.24+
PostgreSQL
MongoDB
Redis
Temporal
Asynq
Prometheus
Quick Start

Get Started in Minutes

From zero to a running API in four simple steps. No complex configuration required.

1

Install CodeAI

Install the CodeAI CLI with a single command. Requires Go 1.24+ installed on your system.

terminal
# Install CodeAI CLI
curl -sSL https://raw.githubusercontent.com/bargom/codeai/main/install.sh | sh
2

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.

app.cai
# 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
3

Start the Server

Start MongoDB with Docker, then launch CodeAI. It parses your .cai file and automatically registers all your REST endpoints.

terminal
# 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
4

Test Your REST API

Test your endpoints with curl. All CRUD operations are automatically available based on your endpoint definitions.

terminal
# 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.

simple-api.cai
// 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)
}
10x
Less boilerplate than traditional frameworks
Type-Safe
Validated at parse time with clear errors
LLM-Ready
Designed for AI code generation

Real-World Examples

Explore complete, production-ready examples. Each project demonstrates different CodeAI features and patterns.

Beginner

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
~120
Lines .cai
vs
~800
Lines Go
85% less
entity Task {
  id: uuid, primary, auto
  title: string, required
  status: enum(pending, done)
  created_at: timestamp, auto
}
View Code
Intermediate

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
~380
Lines .cai
vs
~3,200
Lines Go
88% less
entity Post {
  id: uuid, primary, auto
  title: string, searchable
  author_id: ref(User)
  deleted_at: timestamp, soft_delete
}
View Code
Advanced

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
~750
Lines .cai
vs
~6,500
Lines Go
88% less
workflow ProcessOrder {
  trigger: OrderPlaced
  steps {
    validate_inventory { ... }
    charge_payment { ... }
  }
}
View Code
Specialist

External Integrations

Resilient external API patterns with circuit breakers, webhooks, and GraphQL support.

  • Circuit breaker patterns
  • Retry with backoff
  • Webhook delivery
  • GraphQL integration
~610
Lines .cai
vs
~5,000
Lines Go
87% less
integration PaymentAPI {
  circuit_breaker: {
    threshold: 5 failures in 1m
    reset_after: 30s
  }
}
View Code
Specialist

Scheduled Jobs

Background job processing with cron scheduling, queues, retries, and monitoring.

  • Cron-based scheduling
  • Priority job queues
  • Report generation
  • Data maintenance tasks
~680
Lines .cai
vs
~5,400
Lines Go
87% less
job DailyReport {
  schedule: "0 6 * * *"
  queue: default
  timeout: 30m
  retry: 3 times
}
View Code
Browse All Examples on GitHub

Each example includes documentation, test scripts, and is fully runnable

Documentation

Explore the full documentation on GitHub

View Documentation