← knowledge.oriz.in

API routes — apps/api/src/routes/ structure

architecture architectureapihonoroutes

API routes — apps/api/src/routes/ structure

Concept

Inside the umbrella Worker, routes are organised by external service / concern. Each folder owns one integration so an integration swap is contained to one folder, not threaded through the whole Worker.

How it works

apps/api/
├── src/
│   ├── routes/
│   │   ├── contact.ts        ← relay to Web3Forms / EmailJS
│   │   ├── recaptcha.ts      ← verify reCAPTCHA Enterprise tokens
│   │   ├── razorpay/         ← subscription webhook + signature verify
│   │   ├── firestore/        ← firebase-rest-firestore wrappers
│   │   ├── turso/            ← lifestream warm-cache reads
│   │   └── auth/             ← firebase-auth-cloudflare-workers verify
│   └── index.ts              ← composes routes; export type AppType = typeof app
└── wrangler.jsonc            ← custom_domain: api.oriz.in

Why this shape

Each external service eventually gets swapped — Web3Forms could become Formspree, Razorpay could become Stripe, reCAPTCHA could become Turnstile. Folder-per-service means a swap is one folder edit, not a search-and-replace across a 5,000-line Worker. It also matches the package isolation rule on the client side — see package-isolation-rule.md.

Cross-refs