Documentation

Overview

This project uses a modern API architecture built with oRPC and Hono framework, providing type-safe and high-performance API services.

Tech Stack

Core Technologies

  • oRPC - Type-safe RPC framework with end-to-end type inference
  • Hono - Lightweight, high-performance web framework
  • Zod - TypeScript-first schema validation library
  • OpenAPI - API documentation specification

Key Dependencies

  • @orpc/server - oRPC server implementation
  • @orpc/client - oRPC client implementation
  • @orpc/openapi - OpenAPI integration
  • @orpc/zod - Zod schema converter
  • hono - Web framework
  • zod - Schema validation

Project Structure

The API code is located in the /packages/api directory:

packages/api/
├── index.ts                 # Hono application entry
├── orpc/
│   ├── router.ts           # Main router configuration
│   ├── procedures.ts       # Base procedures (public, protected, admin)
│   ├── handler.ts          # RPC and OpenAPI handlers
│   └── middleware/         # Middleware
│       └── locale-middleware.ts
└── modules/                # Feature modules
    ├── users/
    ├── organizations/
    ├── payments/
    ├── admin/
    └── ...

Module Structure

Each module typically contains:

modules/example/
├── router.ts              # Module router definition
├── types.ts              # Zod schemas and type definitions
└── procedures/           # API endpoint implementations
    └── example-action.ts

Dual Protocol Support

The project supports two API invocation methods:

1. RPC Protocol

Type-safe remote procedure calls:

  • Path prefix: /api/rpc
  • Use case: Frontend application calls
  • Features: Full TypeScript type safety, auto-completion

2. RESTful OpenAPI

Standard REST API:

  • Path prefix: /api
  • Use case: Third-party integrations, API documentation
  • Features: OpenAPI spec, HTTP standard methods

Main Application

The Hono application is configured in packages/api/index.ts:

export const app = new Hono()
  .basePath("/api")
  // Middleware
  .use(honoLogger(...))
  .use(cors(...))
  // Auth handling
  .on(["POST", "GET"], "/auth/**", ...)
  // OpenAPI schema
  .get("/openapi", ...)
  // API documentation
  .get("/docs", ...)
  // Webhooks
  .post("/webhooks/payments", ...)
  // Health check
  .get("/health", ...)
  // oRPC handlers
  .use("*", async (c, next) => \{
    // Auto-route to RPC or OpenAPI handler
  \});