···206206207207Note: Migrations must be defined in both `index.ts` and `cache.ts` to avoid circular dependencies in the import structure.
208208209209+### Adding New Routes
210210+211211+The app uses a type-safe route system that automatically generates Swagger documentation from route definitions. This ensures the API docs always stay in sync with the actual implementation.
212212+213213+To add a new route, you need to:
214214+215215+1. Create the handler function in `src/handlers/index.ts`:
216216+217217+```typescript
218218+export const handleMyNewEndpoint: RouteHandlerWithAnalytics = async (
219219+ request,
220220+ recordAnalytics,
221221+) => {
222222+ // Your handler logic here
223223+ const data = { message: "Hello from new endpoint" };
224224+225225+ await recordAnalytics(200);
226226+ return Response.json(data);
227227+};
228228+```
229229+230230+2. Add the route definition in `src/routes/api-routes.ts`:
231231+232232+```typescript
233233+"/my-new-endpoint": {
234234+ GET: createRoute(
235235+ withAnalytics("/my-new-endpoint", "GET", handlers.handleMyNewEndpoint),
236236+ {
237237+ summary: "My new endpoint",
238238+ description: "Does something useful",
239239+ tags: ["MyFeature"],
240240+ parameters: {
241241+ query: [
242242+ queryParam("limit", "number", "Number of items to return", false, 10)
243243+ ]
244244+ },
245245+ responses: Object.fromEntries([
246246+ apiResponse(200, "Success", {
247247+ type: "object",
248248+ properties: {
249249+ message: { type: "string", example: "Hello from new endpoint" }
250250+ }
251251+ })
252252+ ])
253253+ }
254254+ )
255255+}
256256+```
257257+258258+The route will automatically:
259259+- Handle analytics recording (request timing, status codes, user agents)
260260+- Generate Swagger documentation with the provided metadata
261261+- Include proper TypeScript types for parameters and responses
262262+- Validate the route definition at compile time
263263+264264+No need to manually update Swagger docs or add boilerplate analytics code. The system handles all of that automatically based on your route definitions.
265265+209266<p align="center">
210267 <img src="https://raw.githubusercontent.com/taciturnaxolotl/carriage/master/.github/images/line-break.svg" />
211268</p>