Business apps for your industry, delivered as source you own: your license, your data in one SQLite file, and no vendor to call. Take each as a Node script or a native Rust binary; run it on your own machine or any container host.
Every app here uses the same spec as data apps, so you can open one there and change its tables, or model its data as a graph first.
Scheduling, visits and billing for a small practice. Keep protected health information on hardware you control.
Unpack with tar -xf clinic-scheduling-node.tar, then node server.js and open http://localhost:8080. 3 tables, 20 columns.
Computed from the files you download, not asserted: change the app and this list changes with it.
// Patient scheduling: generated by the TommieBot software factory (lib/data-apps/bundle.ts).
// Zero dependencies: node:http + node:sqlite (Node 22.13 or later). Your data stays in DB_PATH (default ./app.db).
"use strict";
const http = require("node:http");
const fs = require("node:fs");
const path = require("node:path");
const { DatabaseSync } = require("node:sqlite");
const crypto = require("node:crypto");
const SCHEMA = {
"patients": {
"key": "id",
"columns": [
{
"name": "id",
"type": "integer",
"required": false
},
{
"name": "full_name",
"type": "text",
"required": true
},
{
"name": "date_of_birth",
"type": "datetime",
"required": false
},
{
"name": "phone",
"type": "text",
"required": false
},
{
"name": "email",
"type": "text",
"required": false
},
{
"name": "insurer",
"type": "text",
"required": false
},
{
"name": "member_id",
"type": "text",
"required": false
}
]
},
"providers": {
"key": "id",
"columns": [
{
"name": "id",
"type": "integer",
"required": false
},
{
"name": "full_name",
"type": "text",
"required": true
},
{
"name": "specialty",
"type": "text",
"required": false
},
{
"name": "npi",
"type": "text",
"required": false
},
{
"name": "active",
"type": "boolean",
"required": false
}
]
},
"appointments": {
"key": "id",
"columns": [
{
"name": "id",
"type": "integer",
"required": false
},
{
"name": "patient_id",
"type": "integer",
"required": true,
"references": "patients.id"
},
{
"name": "provider_id",
"type": "integer",
"required": true,
"references": "providers.id"
},
{
"name": "starts_at",
"type": "datetime",
"required": true
},
{
"name": "minutes",
"type": "integer",
"required": false
},
{
"name": "room",
"type": "text",
"required": false
},
{
"name": "status",
"type": "text",
"required": false
},
{
"name": "reason",
"type": "text",
"required": false
}
]
}
};
const TITLE = "Patient scheduling";
const MAX_BODY = 1024 * 1024;
const MAX_IMPORT = 64 * 1024 * 1024;
const TOKEN = process.env.APP_TOKEN || "";
const db = new DatabaseSync(process.env.DB_PATH || path.join(__dirname, "app.db"));
db.exec("PRAGMA foreign_keys = ON");
db.exec(fs.readFileSync(path.join(__dirname, "schema.sql"), "utf8"));
const UI = fs.readFileSync(path.join(__dirname, "index.html"), "utf8");
const OPENAPI = fs.readFileSync(path.join(__dirname, "openapi.json"), "utf8");
const q = (name) => '"' + name + '"';
// APP_TOKEN guards writes and the full export; compared in constant time so response timing doesn't leak it
function authorized(req) {
if (!TOKEN) return true;
const got = Buffer.from(String(req.headers.authorization || ""));
const want = Buffer.from("Bearer " + TOKEN);
return got.length === want.length && crypto.timingSafeEqual(got, want);
}
function send(res, status, body, type) {
res.statusCode = status;
res.setHeader("content-type", type || "application/json; charset=utf-8");
res.setHeader("x-content-type-options", "nosniff");
res.setHeader("referrer-policy", "no-referrer");
res.end(type ? body : JSON.stringify(body));
}
function readJson(req, max = MAX_BODY) {
return new Promise((resolve, reject) => {
let size = 0;
let tooLarge = false;
const chunks = [];
// past the cap, keep reading but drop the bytes, so the client still gets its 413 instead of a reset socket
req.on("data", (c) => {
size += c.length;
if (size > 8 * max) return req.destroy();
if (size > max) tooLarge = true;
else chunks.push(c);
});
req.on("end", () => {
if (tooLarge) return reject(Object.assign(new Error("body too large"), { status: 413 }));
try { resolve(JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}")); }
catch { reject(Object.assign(new Error("body is not JSON"), { status: 400 })); }
});
req.on("error", reject);
});
}
function coerce(type, value) {
if (value === null || value === undefined || value === "") return null;
if (type === "integer") { const n = Number(value); if (!Number.isInteger(n)) throw new Error("not an integer"); return n; }
if (type === "real") { const n = Number(value); if (!Number.isFinite(n)) throw new Error("not a number"); return n; }
if (type === "boolean") return value === true || value === "true" || value === 1 || value === "1" ? 1 : 0;
return String(value).slice(0, 10000);
}
// Every row of every table, as one JSON document: the whole app, portable to another device or runtime.
function exportAll() {
const tables = {};
for (const name of Object.keys(SCHEMA)) tables[name] = db.prepare("SELECT * FROM " + q(name)).all();
return { format: 1, app: TITLE, exportedAtUnix: Math.floor(Date.now() / 1000), tables };
}
// Replace everything with an export, in one transaction: all of it lands or none of it does.
function importAll(doc) {
if (!doc || typeof doc.tables !== "object" || doc.tables === null || Array.isArray(doc.tables)) throw Object.assign(new Error("send an export: { tables: { <table>: [rows] } }"), { status: 400 });
for (const name of Object.keys(doc.tables)) {
if (!Object.prototype.hasOwnProperty.call(SCHEMA, name)) throw Object.assign(new Error("unknown table: " + name.slice(0, 64)), { status: 400 });
if (!Array.isArray(doc.tables[name])) throw Object.assign(new Error(name + " must be an array of rows"), { status: 400 });
}
const names = Object.keys(SCHEMA);
const counts = {};
db.exec("PRAGMA defer_foreign_keys = ON");
db.exec("BEGIN");
try {
for (const name of [...names].reverse()) db.prepare("DELETE FROM " + q(name)).run();
for (const name of names) {
const known = new Map(SCHEMA[name].columns.map((c) => [c.name, c]));
const rows = doc.tables[name] || [];
for (const row of rows) {
if (!row || typeof row !== "object" || Array.isArray(row)) throw Object.assign(new Error(name + ": every row must be an object"), { status: 400 });
const cols = Object.keys(row);
const unknown = cols.find((k) => !known.has(k));
if (unknown) throw Object.assign(new Error(name + ": unknown column " + unknown.slice(0, 64)), { status: 400 });
let values;
try { values = cols.map((k) => coerce(known.get(k).type, row[k])); }
catch (e) { throw Object.assign(new Error(name + ": " + e.message), { status: 400 }); }
db.prepare(cols.length ? "INSERT INTO " + q(name) + " (" + cols.map(q).join(",") + ") VALUES (" + cols.map(() => "?").join(",") + ")" : "INSERT INTO " + q(name) + " DEFAULT VALUES").run(...values);
}
counts[name] = rows.length;
}
db.exec("COMMIT");
} catch (e) {
db.exec("ROLLBACK");
throw e;
}
return { imported: counts };
}
const server = http.createServer(async (req, res) => {
try {
const url = new URL(req.url, "http://local");
const parts = url.pathname.split("/").filter(Boolean);
if (req.method === "GET" && parts.length === 0) return send(res, 200, UI, "text/html; charset=utf-8");
if (parts[0] === "health") return send(res, 200, { ok: true });
if (parts[0] === "api" && parts[1] === "openapi.json") return send(res, 200, OPENAPI, "application/json; charset=utf-8");
if (parts[0] === "api" && parts[1] === "schema") return send(res, 200, { title: TITLE, tables: SCHEMA, writesNeedToken: Boolean(TOKEN) });
if (parts[0] === "api" && parts[1] === "export" && req.method === "GET") {
if (!authorized(req)) return send(res, 401, { error: "the full export needs APP_TOKEN" });
return send(res, 200, exportAll());
}
if (parts[0] === "api" && parts[1] === "import" && req.method === "POST") {
if (!authorized(req)) return send(res, 401, { error: "writes need APP_TOKEN" });
return send(res, 200, importAll(await readJson(req, MAX_IMPORT)));
}
if (parts[0] !== "rows" || !Object.prototype.hasOwnProperty.call(SCHEMA, parts[1])) return send(res, 404, { error: "not found" });
const table = parts[1];
const spec = SCHEMA[table];
if (req.method !== "GET" && !authorized(req)) return send(res, 401, { error: "writes need APP_TOKEN" });
if (req.method === "GET" && parts.length === 2) {
const limit = Math.min(Math.max(Number(url.searchParams.get("limit")) || 200, 1), 1000);
const order = spec.key ? " ORDER BY " + q(spec.key) + " DESC" : "";
return send(res, 200, db.prepare("SELECT * FROM " + q(table) + order + " LIMIT ?").all(limit));
}
if (req.method === "POST" && parts.length === 2) {
const row = await readJson(req);
if (!row || typeof row !== "object" || Array.isArray(row)) return send(res, 400, { error: "send one JSON object" });
const known = new Map(spec.columns.map((c) => [c.name, c]));
const unknown = Object.keys(row).filter((k) => !known.has(k));
if (unknown.length) return send(res, 400, { error: "unknown column: " + unknown[0].slice(0, 64) });
const cols = Object.keys(row).filter((k) => !(k === spec.key && (row[k] === "" || row[k] === null)));
for (const c of spec.columns) if (c.required && c.name !== spec.key && (row[c.name] === undefined || row[c.name] === "" || row[c.name] === null)) return send(res, 400, { error: "missing " + c.name });
let values;
try { values = cols.map((k) => coerce(known.get(k).type, row[k])); }
catch (e) { return send(res, 400, { error: e.message }); }
const sql = cols.length
? "INSERT INTO " + q(table) + " (" + cols.map(q).join(",") + ") VALUES (" + cols.map(() => "?").join(",") + ")"
: "INSERT INTO " + q(table) + " DEFAULT VALUES";
const result = db.prepare(sql).run(...values);
return send(res, 201, { id: Number(result.lastInsertRowid) });
}
if (req.method === "DELETE" && parts.length === 3 && spec.key) {
const result = db.prepare("DELETE FROM " + q(table) + " WHERE " + q(spec.key) + " = ?").run(parts[2]);
return send(res, result.changes ? 200 : 404, { deleted: Number(result.changes) });
}
return send(res, 405, { error: "method not allowed" });
} catch (e) {
const status = e && e.status ? e.status : /constraint/i.test(String(e && e.message)) ? 409 : 500;
if (status === 500) console.error(e);
return send(res, status, { error: status === 500 ? "server error" : String(e.message).slice(0, 200) });
}
});
const port = Number(process.env.PORT) || 8080;
server.listen(port, process.env.HOST || "0.0.0.0", () => console.log(TITLE + " listening on http://localhost:" + port));
The same generator runs from a script, over HTTP and as MCP tools (factory_catalog, factory_generate), so an agent can make an app the same way you do here. Every app also ships openapi.json, so standard client generators (openapi-generator, openapi-typescript, oapi-codegen, progenitor) build a typed client for it in any language.
# from this repo
pnpm factory:gen clinic-scheduling --runtime node --license MIT --out ./clinic-scheduling --check
pnpm factory:check ./clinic-scheduling
# over HTTP: the source as a .tar, straight into a folder
curl -s -X POST "$ORIGIN/api/factory?format=tar" -H 'content-type: application/json' \
-d '{"app":"clinic-scheduling","runtime":"node","license":"MIT"}' | tar -x
# a typed client for the running app
npx openapi-typescript http://localhost:8080/api/openapi.json -o clinic-scheduling.d.ts