refactor: Migrate to Hono framework for multi-platform support

- Replace Vercel-specific handler with Hono framework
- Add Cloudflare Workers support via wrangler.toml
- Restructure project: src/index.js, src/routes/messages.js
- Update README with Cloudflare deployment instructions
- Save framework decision to memory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-25 23:02:08 +07:00
parent bfb936ae4a
commit 415790a9f1
11 changed files with 332 additions and 242 deletions

View File

@@ -2,3 +2,4 @@
- [Memory Saving Rules](memory_saving_rules.md) — How to save memories in this project
- [Implementation Plan](implementation_plan.md) — Architecture and design decisions for Claude Central Gateway
- [Framework Decision - Hono](framework_decision.md) — Why Hono was chosen over alternatives

View File

@@ -0,0 +1,26 @@
---
name: Framework Decision - Hono
description: Why Hono was chosen over alternatives for the gateway
type: project
---
## Framework Choice: Hono
**Decision:** Use Hono as the web framework for Claude Central Gateway.
**Why Hono over alternatives:**
| Alternative | Why not |
|-------------|---------|
| Nitro | Overkill for simple proxy, 200KB+ bundle vs 14KB |
| itty-router | Cloudflare-focused, Vercel needs adapter |
| Native | Duplicate code per platform, manual streaming |
**Why Hono:**
- Single codebase for Vercel + Cloudflare + Deno + Bun
- Ultra-lightweight (~14KB)
- First-class streaming support (critical for SSE)
- Zero-config multi-platform
- Aligns with project philosophy: "Minimal, simple, deploy anywhere"
**How to apply:** All API routes should use Hono's `app.route()` pattern. Keep handlers simple and stateless.

View File

@@ -21,7 +21,8 @@ Claude Code → Gateway (Vercel) → OpenAI API
### Key Decisions
- **Language**: Node.js with JavaScript (no TypeScript)
- **Deployment**: Vercel serverless functions
- **Framework**: Hono (multi-platform: Vercel, Cloudflare, Deno, Bun)
- **Deployment**: Vercel serverless functions OR Cloudflare Workers
- **Providers**: OpenAI first (via official SDK), others in TODO
- **Config**: Environment variables only (no database)
- **Auth**: Single shared token (user's `ANTHROPIC_AUTH_TOKEN` must match `GATEWAY_TOKEN`)
@@ -39,9 +40,15 @@ Claude Code → Gateway (Vercel) → OpenAI API
### File Structure
```
api/v1/messages.js - Main proxy handler
package.json - Dependencies (openai SDK)
vercel.json - Routing config
src/
├── index.js - Hono app entry point
├── routes/
│ └── messages.js - /v1/messages proxy handler
api/
└── index.js - Vercel adapter
package.json - Dependencies (hono, openai)
vercel.json - Vercel config
wrangler.toml - Cloudflare Workers config
```
### How to apply: When adding new providers or modifying the gateway, follow the established pattern in `api/v1/messages.js` for request/response transformation.