The receipts
Three files. One backend.
Describe the data, define
what it does, say where it runs. The code that calls it is written from the same
description, so the two sides can’t drift apart. The description even
carries a photo upload: files are part of the deal, not an add-on.
schema.tswhat your data looks like · who can touch it
import { boolean, file, owner, schema, string, table } from "create-dillo/schema";
// One table: fields that say what they hold, private to the person who created the row —
// and a cover photo for the project. A real upload: the file itself
// lives in R2 (the file storage), and the row keeps its id.
export default schema({
Project: table({
name: string().min(1).max(120),
active: boolean().default(true),
cover: file().accept("image/*").maxSize("10 MB").optional(),
}).permissions({
view: owner, // the armor: enforced on every request
edit: owner,
}),
});
backend.tswhat your app does · functions, validated
import { defineBackend, defineFunction } from "create-dillo/backend";
import { string } from "create-dillo/schema";
import schema from "./schema.ts";
export default defineBackend({
schema,
functions: {
greet: defineFunction()
.input({ name: string().min(1) })
.output({ message: string() })
.handler((_context, input) => ({ message: `Hello ${input.name}` })),
},
});
alchemy.run.tswhere it runs · on your own account
import { app } from "create-dillo/deploy/cloudflare";
import backend from "./backend.ts";
export default app({
id: "my-app",
backend,
signup: "open",
});
client.tshow anything calls it · written from the same description
import { Armadillo } from "create-dillo/client";
import type backend from "./backend.ts";
// Written from your own backend — there is no second copy to drift.
// (That address is the app running on your own machine while you build.)
const api = Armadillo.client<typeof backend>({ url: "http://localhost:8787" });
const project = await api.tables.Project.create({ name: "Garden", active: true });
const active = await api.tables.Project.query().where({ active: true }).limit(20).find();
// A function call: greet takes a name, checks it, and answers.
const { message } = await api.functions.greet({ name: "Sam" });
// message → "Hello Sam"
// Files are uploads, not placeholders. The photo itself goes up —
// it lands in R2 — and then the row is pointed at it: open the
// project, and there's its photo. (coverFile is a File from your page.)
const photo = await api.files.upload(coverFile);
await api.tables.Project.update(project.id, { cover: photo.id });