Universal Adapter Pattern
The core philosophy of Aerostack modules is Platform Portability. By following the three-layer architecture, your logic can run on Cloudflare Workers, Node.js, Bun, or Deno with zero changes.
The Three Layers
Section titled “The Three Layers”1. Logic Layer (core.ts)
Section titled “1. Logic Layer (core.ts)”This is where your business logic lives.
- Rule: No framework imports (no Hono, Express, etc.).
- Rule: Use the
CoreContextpattern to access DB and Environment.
export async function createNote(ctx: CoreContext, data: any) { return ctx.db.insert(notes).values(data).returning();}2. Data Layer (schema.ts)
Section titled “2. Data Layer (schema.ts)”Defines your database tables using Drizzle ORM.
- Benefit: Allows the Aerostack CLI to auto-detect and sync your schema when a module is installed.
3. Adapter Layer (adapter.ts)
Section titled “3. Adapter Layer (adapter.ts)”The “glue” that connects your core logic to a specific web framework.
- Hono Adapter (for Workers/Bun):
import { Hono } from 'hono';import { createNote } from './core';const app = new Hono();app.post('/', async (c) => c.json(await createNote({ db: c.env.DB }, await c.req.json())));
Why this matters
Section titled “Why this matters”- No Vendor Lock-in: Move from Cloudflare to a dedicated server without rewriting your feature logic.
- Easy Testing: You can unit test your
core.tsin standard Node.js without mocking complex Worker environments. - Composable Repos: The CLI uses these layers to safely “stitch” community modules into your codebase.