Stack

Core Technologies

CategoryTechnologyVersionPurpose
RuntimeBun1.xJavaScript/TypeScript runtime with native support
LanguageTypeScript5.xType-safe JavaScript
FrameworkHono4.xLightweight, edge-ready web framework
DatabaseMongoDB6.x+Document store with MongoOS auto-sharding
CacheBunRedisnativeBun’s native Redis client
StorageBunSQLitenativeZero-infrastructure SQLite via Bun
i18nCustomJSON file-based multi-locale support

Bun Runtime Features

Why Bun?

  • Native TypeScript — No tsc, no tsx, no build step
  • Fast startup — ~10ms cold start vs Node.js ~100ms+
  • Native SQLiteBun.SQLite for embedded storage
  • Native WebSocket — Built-in new WebSocket() for ACP client
  • Built-in test runnerbun test
  • Auto-installbun install is fast and lockfile-based

Bun-Specific Patterns

// Native SQLite
import { Database } from 'bun:sqlite';
const db = new Database('app.db');

// Native WebSocket (for ACP client)
const ws = new WebSocket(url, { headers });
ws.onmessage = (event) => console.log(event.data);

// Native SSE for streaming responses
return c.stream((stream) => {
  stream.write('data: hello\n\n');
});

Hono Framework

Why Hono?

  • Edge-ready — Works on Bun, Deno, Cloudflare Workers, Node.js
  • Lightweight — < 500KB, no dependencies
  • Type-safe — First-class TypeScript support
  • Native Bun integration — Zero adapter layer

Key Hono Patterns

import { Hono } from 'hono';

const app = new Hono();

// Middleware chain
app.use('*', rateLimitMiddleware());
app.use('*', idempotencyMiddleware());
app.use('*', i18nMiddleware());

// Route handlers
app.post('/api/v1/users', async (c) => {
  const body = await c.req.json();
  const user = await createUserUseCase.execute(body);
  return c.json(user, 201);
});

// SSE streaming
app.post('/api/v1/gateway/prompt', async (c) => {
  return c.stream((stream) => {
    for await (const chunk of sendPromptUseCase.execute(input)) {
      stream.write(`data: ${JSON.stringify(chunk)}\n\n`);
    }
  });
});

Data Layer

MongoDB

Primary data store for persistent entities.
// packages/infrastructure/database/mongodb-client.ts
import { MongoClient } from 'mongodb';

export function createMongoClient(url: string) {
  return new MongoClient(url, {
    maxPoolSize: 10,
    minPoolSize: 2,
  });
}

BunRedis

In-memory cache with Redis fallback.
// packages/infrastructure/cache/redis-cache.ts
import { Redis } from 'hono/redis';

export function createRedisCache(url: string) {
  try {
    return new Redis(url);
  } catch {
    return new InMemoryCache(); // Fallback
  }
}

BunSQLite

Zero-infrastructure session storage.
// modules/gateway/infrastructure/session-store/sqlite.ts
import { Database } from 'bun:sqlite';

export function createSessionStore() {
  const db = new Database('sessions.db');

  // Initialize schema
  db.exec(`
    CREATE TABLE IF NOT EXISTS gateway_sessions (
      id TEXT PRIMARY KEY,
      session_key TEXT UNIQUE,
      agent_id TEXT,
      user_id TEXT,
      adapter_id TEXT,
      history TEXT,
      created_at TEXT,
      updated_at TEXT
    )
  `);

  return db;
}

Architecture Pattern

Hexagonal (Ports & Adapters)

┌────────────────────────────────────────────────────────────┐
│                        App Layer                           │
│  Hono Routes ──▶ Middleware ──▶ Use Cases ──▶ Domain       │
└────────────────────────────────────────────────────────────┘

            ┌─────────────────┼─────────────────┐
            ▼                 ▼                 ▼
    ┌─────────────┐   ┌─────────────┐   ┌─────────────┐
    │   MongoDB   │   │    Redis    │   │   BunSQLite │
    └─────────────┘   └─────────────┘   └─────────────┘

Dependency Rule

domain/ ← application/ ← infrastructure/
   ↑            ↑              ↑
   ↑            ↑              │
   ↑            └──────────────┘
   │                (implements ports)
   │                (has zero deps)

Development Tools

ToolPurpose
bun run devHot reload dev server
bun run buildProduction build
bun run testTest runner
bun run typecheckTypeScript checking
bun run lintESLint

See Also