Skip to content
Django + React framework ยท Apache-2.0

Karni

The Django + React framework where your coding agent writes only your app or your game

Karni is an open-source Django + React framework for building web apps and web games with AI coding agents. Your agent writes only your domain or your game. The API, admin, permissions, React screens and game engine come from packages you upgrade. One rule set covers every coding agent. The build fails when an agent hand-writes what Karni ships.

Quickstart Recipes GitHub

Why Karni exists

Every web project starts with the same work: sign-in, a user model, the admin, permissions, CRUD endpoints, tables, forms, Docker and Celery. Coding agents write that setup faster, but they write it again in every project, a little different each time, and every copy has to be maintained.

Karni ships that code as versioned packages on one base, and apps and games are peers on it: a project is an app, a game, or both (apps and games). For an app, karni (Python), @karni/ui (React) and the karni command: you declare a model and who may access it, and Karni gives you the REST API, the admin, role-based access, the React screens, the tests and the demo data. For a game, karni-game and @karni/game: a server that decides players, saves, scores and coins, and the scenes, UI, drawing, collision, assets, sound and simulation a browser game is built on. The agent writes only your domain or your game, and karni check fails the build when it hand-writes what Karni ships. Karni grew out of the 34 projects we built before it.

Build an app from one line

  1. Create a project with karni new "Yoga Studio" and open it in your coding agent.
  2. Describe the app in one line after /new-app. AGENTS.md tells the agent what that asks for.
  3. The agent writes karni.yaml from the closest recipe, and asks you only the questions karni plan --questions lists.
  4. karni build makes the app: modules, Karni's code, migrations, the demo data the spec asks for, TypeScript types, the tests and karni check.
  5. The agent writes only the domain logic that is left, in the project's own files. It is done when karni check and karni test pass.
/new-app a booking app for a yoga studio, with online payments

What the agent runs, from a real session:

$ karni recipes list --match "a booking app for a yoga studio, with online payments"
booking   4  Booking: Resources with time slots that members book and pay for, never over capacity. (matched: booking)
shop      3  Online shop: Products in categories, a cart, orders and checkout with online payments. (matched: online, payment)

$ karni build
plan        22 changes, 0 risky: modules 1, features 1, roles 3, apps 1, entities 3, access 3, pages 3, migrations 1, seed 3, tests 3 (--verbose lists each)
modules     karni add payments
migrations  bookings/migrations/0001_initial.py
migrate     applied 84 on default
seed        Resource 4, Slot 30, Booking 60 (demo login demo@example.com / karni-password)
types       frontend/src/api/types.ts and hooks.ts
test        7 passed in 2.88s, tests/openapi.snapshot.json updated (the API changed: commit it)
check       ok
Built: the project matches karni.yaml.

On a developer laptop, karni new --recipe shop builds the shop from scratch on SQLite in 53.8 seconds, its tests and karni check included and the frontend install left out (how fast is it). The /new-app flow has every step. Every step is also a command you can run without an agent (building without one).

A terminal runs karni new, karni make model, migrate, seed and serve. Then the browser shows the welcome page, the admin listing the seeded events, and the React app's events table and detail view.

Coding-agent benchmark

A coding agent built three small apps (a booking app with payments, a CRM with three roles and import, and a shop with orders and refunds) on plain Django + React and on Karni, with the same model, agent version, prompt and API contract. The harness's own acceptance tests decide success.

What the agent built

One kept run per app and side, each passing every acceptance test, on the Karni 0.5.0 release. Both sides are measured the same way, by the project's own Django and its files (scripts/benchmarks/tokens/inventory.py):

In the finished app Plain Django + React Karni
API operations (route and method) 22 to 25 71 to 135
Sign-in and account endpoints, outside the admin 1 to 2 16
Models in the admin 1 to 2 26 to 30
React screens none 9 to 12
Tests the project ships with none 7 to 15
OpenAPI schema served no yes
Typed API client in the frontend no yes
Production Docker stack no yes
Rules for the coding agent no yes

Why a Karni run costs more. These tasks check only a small API contract. Plain Django meets it and stops there: no screens, no tests, and two sign-in endpoints at most. With Karni, the same request ends in the whole app above, and the agent also reads Karni's rules and runs its build and checks. So a Karni run costs more and takes longer (below), and for that the app has about 3 to 5 times the API operations, a full sign-in, an admin, React screens and tests.

What it cost

45 runs: five per app on plain Django + React, on the Karni 0.5.0 candidate, and on Karni after the work on its agent flow.

Task Plain Django + React Karni 0.5.0 candidate Karni after the agent-flow work
Booking with payments $0.19, 61.76 s, 5 of 5 passed, 5 tool calls $0.45, 208 s, 3 of 5 passed, 26 tool calls $0.33, 187 s, 5 of 5 passed, 20 tool calls
A CRM with three roles and import $0.21, 70.51 s, 5 of 5 passed, 6 tool calls $0.56, 278 s, 5 of 5 passed, 31 tool calls $0.40, 236 s, 5 of 5 passed, 22 tool calls
A shop with orders and refunds $0.23, 72.21 s, 5 of 5 passed, 7 tool calls $0.62, 238 s, 4 of 5 passed, 29 tool calls $0.44, 255 s, 4 of 5 passed, 24 tool calls
All three tasks $0.63, 204 s, 15 of 15 passed, 18 tool calls $1.63, 724 s, 12 of 15 passed, 86 tool calls $1.17, 678 s, 14 of 15 passed, 66 tool calls

Each cell: median cost in US dollars, median wall time, runs that passed every acceptance test, and median tool calls. In the last row the runs add up and the other figures are the sums of the task medians, as the benchmark report gives them.

  • Plain Django + React was cheaper and faster on these three small apps. Karni after the agent-flow work cost about 1.8 to 1.9 times as much per app (median) and took about 3 to 3.5 times as long.
  • The agent-flow work cut the median cost by 27 to 30 percent and the context the agent read again by 30 to 43 percent, and raised the runs that passed every test from 12 of 15 to 14 of 15.
  • With Karni the agent wrote fewer lines of its own (median 256 to 431 per app, against 438 to 554), and each Karni project ended with far more code in it (median about 11,500 to 20,000 lines, most of it generated by Karni, against about 440 to 570).

Not counted here: setting up. Both sides started from a ready-made project; the harness, not the agent, made plain's Django and React starting point. Without Karni, that setup is done again for every new project. With Karni, karni new does it, and builds what the first table shows, with no AI tokens. A benchmark that starts from an empty folder and a one-line request is next.

The benchmark report has every figure with its range, the method, the limits, the commands to repeat it and the raw data.

What you get

Every feature, with its status

Recipes and modules

Recipe What it gives One command
shop Products in categories, a cart, orders, checkout with online payments karni new "Corner Shop" --recipe shop
booking Resources with time slots that members book and pay for, never over capacity karni new "Yoga Studio" --recipe booking
crm Companies, contacts and deals in a pipeline, with two-factor sign-in karni new "Sales Desk" --recipe crm
lms Courses with lessons in order, enrolments and each student's progress karni new "Course Hub" --recipe lms
marketplace Sellers, listings, orders and the payout after the fee karni new "Market Hall" --recipe marketplace
data-portal Datasets and indicators by region and sector, with saved charts karni new "Data Portal" --recipe data-portal
Module What it gives One command
karni-payments Hosted checkout, refunds and signature-verified webhooks for Stripe and Razorpay, with a test provider for CI pip install karni-payments && karni add payments
karni-approvals A second person approves high-value changes before they are written, with a queue and an audit trail pip install karni-approvals && karni add approvals
karni-impersonation Safe "log in as user" for support staff: a banner, a time limit, both identities in the audit trail pip install karni-impersonation && karni add impersonation
karni-site A public website whose every text, image and menu is editable in the admin, with forms and redirects pip install "karni-site[images]" && karni add site
karni-charts Charts defined and previewed in the admin, served under each resource's access pip install karni-charts && karni add charts
karni-reports A row printed to PDF from an HTML template in the background, served only to users who may see the row pip install karni-reports && karni add reports
karni-ai Rows for any resource read from text, a web page or a PDF by a language model, always through the import preview pip install "karni-ai[<provider>]" && karni add ai
karni-storage Files a row owns, in S3 or an S3-compatible service, served only to whoever may read the row pip install "karni-storage[images]" && karni add storage
karni-commerce One cart, checkout and order path for anything a project sells: products, seats, bookings pip install karni-commerce && karni add commerce
karni-game The server side of a game: guest players, cloud saves, leaderboards, a soft-currency wallet, daily content, achievements pip install karni-game && karni add game

Quickstart

You need Python 3.12 or later and Node 20.19 or later. This runs the shop recipe on SQLite, with no Docker:

python3 -m venv .venv && . .venv/bin/activate
pip install karni karni-cli karni-payments pytest pytest-django
karni new "Corner Shop" --recipe shop && cd corner_shop
printf 'DATABASE_URL=sqlite:///data/db.sqlite3\nKARNI_CACHE=locmem\n' > .env
karni build
karni serve --local

Then, in a second terminal: cd corner_shop/frontend && npm install && npm run dev. The quickstart guide does the same on PostgreSQL, Karni's default database.

How it works

flowchart LR
    spec["karni.yaml<br/>apps, entities, access,<br/>roles, modules, pages"]
    plan["karni plan<br/>what will change,<br/>risky changes first"]
    build["karni build<br/>migrate, seed, types,<br/>tests, karni check"]
    owned["Code Karni owns<br/>&lt;app&gt;/karni/, the karni:spec blocks<br/>rewritten on every build"]
    yours["Code you own<br/>&lt;app&gt;/models.py, viewsets.py,<br/>seeds.py, your pages and tests<br/>created once, never rewritten"]
    pkgs["Versioned packages<br/>karni, @karni/ui, karni-cli<br/>moved on by karni upgrade"]
    spec --> plan --> build
    build --> owned
    build --> yours
    yours -- "subclass" --> owned
    owned -- "extends" --> pkgs

The code you own subclasses what Karni writes. For one resource it is a model and a viewset:

class Venue(BaseModel):
    name = models.CharField(max_length=200)
    city = models.CharField(max_length=100)
    capacity = models.IntegerField()


class VenueViewSet(BaseViewSet):
    model = Venue
    access = Access(read=Public(), write=HasRole("organizer", "staff"))
    search_fields = ("name", "city")

From those two classes Karni derives the endpoints at /api/venues/, the OpenAPI schema and a typed client, the admin screen, the permission checks on every query, and a table, form and detail view in React (what Karni owns, and what the project owns).

Questions

Karni is not production-ready yet: it has two reference applications and CI on every push, but no known production deployment. The FAQ answers that and more, the stability promise says what an upgrade may change, and Karni is open source under the Apache License 2.0.