Add Elysia API scaffold

This commit is contained in:
Asep Haryana Saputra
2026-05-22 12:25:41 +00:00
parent e543226209
commit 5e38c9276a
10 changed files with 110 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
import { defineConfig } from 'drizzle-kit';
export default defineConfig({
schema: './src/db/schema.ts',
out: './drizzle',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL ?? 'postgres://postgres:postgres@localhost:5432/zeavis_edu',
},
});
+23
View File
@@ -0,0 +1,23 @@
type: application
language: typescript
tasks:
dev:
command: bun run dev
local: true
build:
command: bun build src/index.ts --outdir dist --target bun
inputs:
- src/**/*
- package.json
- tsconfig.json
- drizzle.config.ts
outputs:
- dist
typecheck:
command: bun run typecheck
inputs:
- src/**/*
- package.json
- tsconfig.json
- drizzle.config.ts
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@zeavis/api",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "bun --watch src/index.ts",
"start": "bun src/index.ts",
"typecheck": "tsc --project tsconfig.json",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate"
},
"dependencies": {
"@zeavis/shared": "workspace:*",
"drizzle-orm": "^0.36.4",
"elysia": "^1.1.25",
"postgres": "^3.4.5"
},
"devDependencies": {
"drizzle-kit": "^0.27.1",
"typescript": "^5.6.3"
}
}
+4
View File
@@ -0,0 +1,4 @@
export const env = {
port: Number(Bun.env.API_PORT ?? 3000),
databaseUrl: Bun.env.DATABASE_URL,
};
+13
View File
@@ -0,0 +1,13 @@
import { drizzle } from 'drizzle-orm/postgres-js';
import postgres from 'postgres';
import { env } from '../config/env';
import * as schema from './schema';
export function createDbClient() {
if (!env.databaseUrl) {
throw new Error('DATABASE_URL is required to create a database client');
}
const client = postgres(env.databaseUrl);
return drizzle(client, { schema });
}
+7
View File
@@ -0,0 +1,7 @@
import { pgTable, timestamp, uuid, varchar } from 'drizzle-orm/pg-core';
export const appEvents = pgTable('app_events', {
id: uuid('id').primaryKey().defaultRandom(),
name: varchar('name', { length: 120 }).notNull(),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
});
+10
View File
@@ -0,0 +1,10 @@
import { Elysia } from 'elysia';
import { env } from './config/env';
import { healthRoutes } from './routes/health';
import { statusRoutes } from './routes/status';
const app = new Elysia().use(healthRoutes).use(statusRoutes).listen(env.port);
console.log(`ZeaVis Edu API running at http://${app.server?.hostname}:${app.server?.port}`);
export type App = typeof app;
+5
View File
@@ -0,0 +1,5 @@
import { Elysia } from 'elysia';
export const healthRoutes = new Elysia().get('/health', () => ({
status: 'ok' as const,
}));
+6
View File
@@ -0,0 +1,6 @@
import { createAppStatus } from '@zeavis/shared';
import { Elysia } from 'elysia';
export const statusRoutes = new Elysia({ prefix: '/api/v1' }).get('/status', () =>
createAppStatus(),
);
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ES2022"],
"types": ["bun"],
"noEmit": true
},
"include": ["src", "drizzle.config.ts"]
}