Skip to main content

Hono Backend

Generates Hono API routes with proper validation, error handling, and database integration for the SO1 control plane API.

Quick Reference

PropertyValue
DomainEngineering
FORGE Stage3 (Documentation)
Repositoryso1-control-plane-api
StackHono 4, Zod, Drizzle ORM, PostgreSQL

Core Capabilities

API Routes

RESTful endpoints with proper HTTP methods

Validation

Zod schemas for request/response validation

Database

Drizzle ORM queries and transactions

Middleware

Auth, logging, CORS, error handling

Usage Example

Use the Hono Backend agent to create an API endpoint:
- POST /api/v1/workflows
- Accepts JSON body with name, trigger type, and configuration
- Validates with Zod schema
- Stores in PostgreSQL via Drizzle
- Returns workflow ID or error envelope

Output

import { Hono } from 'hono';
import { zValidator } from '@hono/zod-validator';
import { z } from 'zod';
import { db } from '../db';
import { workflows } from '../db/schema';

const app = new Hono();

const CreateWorkflowSchema = z.object({
  name: z.string().min(1).max(100),
  triggerType: z.enum(['manual', 'webhook', 'schedule', 'event']),
  triggerConfig: z.record(z.unknown()).optional(),
});

app.post('/api/v1/workflows', zValidator('json', CreateWorkflowSchema), async (c) => {
  try {
    const body = c.req.valid('json');
    
    const [workflow] = await db.insert(workflows).values({
      id: `wf_${generateId()}`,
      name: body.name,
      triggerType: body.triggerType,
      triggerConfig: body.triggerConfig || {},
      status: 'draft',
    }).returning();
    
    return c.json({
      success: true,
      data: workflow,
    }, 201);
  } catch (error) {
    return c.json({
      success: false,
      error: {
        code: 'INTERNAL_ERROR',
        message: 'Failed to create workflow',
      },
    }, 500);
  }
});

export default app;

Best Practices

  • Always use zValidator for request validation
  • Return standard error envelopes: { success: false, error: { code, message } }
  • Use Drizzle for all database operations
  • Implement middleware for cross-cutting concerns
  • Follow REST conventions (201 for created, 404 for not found)

Agent Definition

View full agent markdown