mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-22 06:46:41 +02:00
Extract the credit system from mana-core-auth into a standalone service. Uses Hono framework on Bun runtime instead of NestJS. Service includes: - Personal credit balance with optimistic locking - Immutable transaction ledger - Stripe payment integration (PaymentIntents, Checkout Sessions) - Guild shared pools with per-member spending limits - Gift code system (simple, personalized, split, first_come, riddle) - Service-to-service internal API (X-Service-Key auth) - JWT validation via JWKS from mana-core-auth (jose library) Architecture: - 27 files, ~2.2k LOC (vs ~4.1k in NestJS) - Drizzle ORM schemas adapted for standalone DB (no FK to auth tables) - Zod validation instead of class-validator - Manual service instantiation instead of NestJS DI - Hono middleware for JWT + service key auth Port: 3060 Database: mana_credits (separate from mana_auth) Next steps: Update CreditClientService URL, update mana-core-auth registration hooks, configure Docker + Cloudflare Tunnel. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
19 lines
470 B
TypeScript
19 lines
470 B
TypeScript
/**
|
|
* Database connection using Drizzle ORM + postgres.js
|
|
*/
|
|
|
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
import postgres from 'postgres';
|
|
import * as schema from './schema/index';
|
|
|
|
let db: ReturnType<typeof drizzle<typeof schema>> | null = null;
|
|
|
|
export function getDb(databaseUrl: string) {
|
|
if (!db) {
|
|
const client = postgres(databaseUrl, { max: 10 });
|
|
db = drizzle(client, { schema });
|
|
}
|
|
return db;
|
|
}
|
|
|
|
export type Database = ReturnType<typeof getDb>;
|