src/app/index.ts
): The request first hits the main Hono application instance.src/app/index.ts
):
hono/cache
middleware checks if a valid cached response exists for the request URL and Accept-Language
header. If a cache hit occurs, the cached response is returned immediately.src/app/index.ts
-> src/features/.../routes.ts
): Hono matches the request path to the appropriate route defined within the feature modules (e.g., /api/v1/countries/...
).src/features/.../routes.ts
): The @hono/zod-validator
middleware validates path parameters (paramSchema
) and/or query parameters (querySchema
) using Zod schemas defined in validators.ts
. If validation fails, a 400 Bad Request response is generated automatically.src/features/.../routes.ts
): If validation passes, the specific route handler function (e.g., handleGetCountryByName
) is executed.src/features/.../service.ts
): The handler typically calls functions within the corresponding service module. The service contains the core business logic:
Map
structures created at startup).sortData.ts
).filterData.ts
).src/shared/lib/utils/
, src/shared/lib/i18n/
): Service functions utilize shared utility functions for tasks like string normalization, sorting, filtering, and translation lookups.c.json()
to construct the JSON response.src/app/index.ts
): If any error occurs during the process (e.g., data not found leading to a thrown HTTPException
, validation error, or unexpected server error), the global app.onError
handler catches it. It logs the error (if appropriate), determines the correct status code, retrieves a translated error message using getTranslatedMessage.ts
, and returns a consistent JSON error response ({ error: { status, message } }
).countries/service.ts
, region/service.ts
) preprocess the static JSON data into efficient Map
structures on application startup for fast lookups (O(1) average time complexity for name/region searches).Accept-Language
header using logic in shared/lib/i18n/
and messages defined in shared/config/i18n/
.hono/cache
middleware for edge caching, significantly improving performance for repeated requests. The Vary: Accept-Language
header ensures correct caching for different languages.