Rebuild the hub on Bun: Elysia API, Better Auth, Drizzle, Next.js website
CI / test (push) Successful in 30s

The hub becomes a Bun monorepo: apps/api (Elysia, Better Auth for accounts, roles, bans, proxy device
sign-in and JWT keys; tagline linking, presence and the console as before), packages/db (Drizzle; Postgres in
production, PGlite in development and tests), and the Next.js website from apps/web. Self-hostable with
docker compose; the website deploys to Vercel-style hosts, the API to any that runs Bun or containers. The
first version, in Go, is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-10-29 05:03:54 -07:00
1 parent 64c552330b
commit 7a06ba49c3
59 files changed
+2640 -3523

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
// The hub's database: Postgres in production (DATABASE_URL), or PGlite (Postgres compiled to WebAssembly, in
// process) for development and tests, so nothing needs installing.
import { drizzle as drizzleBun } from "drizzle-orm/bun-sql";
import { migrate as migrateBun } from "drizzle-orm/bun-sql/migrator";
import { drizzle as drizzlePglite } from "drizzle-orm/pglite";
import { migrate as migratePglite } from "drizzle-orm/pglite/migrator";
import { PGlite } from "@electric-sql/pglite";
import { SQL } from "bun";
import { mkdirSync } from "node:fs";
import { fileURLToPath } from "node:url";
import * as schema from "./schema";
export { schema };
export * from "drizzle-orm";
const migrationsFolder = fileURLToPath(new URL("../drizzle", import.meta.url));
export type Database = ReturnType<typeof drizzlePglite<typeof schema>>;
/**
* Opens the database and brings its schema up to date.
* @param url a postgres:// URL, "memory" (a fresh in-process database), or a directory for PGlite's files.
*/
export async function openDatabase(url: string): Promise<{ db: Database; close: () => Promise<void> }> {
if (url.startsWith("postgres://") || url.startsWith("postgresql://")) {
const client = new SQL(url);
const db = drizzleBun({ client, schema });
await migrateBun(db, { migrationsFolder });
// Both drivers speak the same query builder; the PGlite type stands for both.
return { db: db as unknown as Database, close: async () => client.close() };
}
if (url !== "memory") mkdirSync(url, { recursive: true });
const client = url === "memory" ? new PGlite() : new PGlite(url);
const db = drizzlePglite({ client, schema });
await migratePglite(db, { migrationsFolder });
return { db, close: async () => client.close() };
}