Summary
Add a centralized Zod-based request validation layer for required API routes and replace ad-hoc/manual input validation inside controllers.
Problem
Validation is currently inconsistent across routes and controllers. Some controllers perform inline checks, while other inputs are not validated in a uniform way. This increases risk of invalid payloads, duplicated logic, and inconsistent error responses.
Expected Solution
Create reusable Zod schemas and a validation middleware for body, params, and query. Attach middleware at route level for required endpoints, then remove controller-level manual input checks that are replaced by schema validation. Standardize validation error response shape.
Scope
- Backend middleware:
- backend/middlewares/ (new Zod validation middleware)
- Backend routes:
- backend/routers/chat.route.js
- backend/routers/chatMessage.route.js
- backend/routers/user.route.js
- backend/routers/apikey.route.js
- backend/routers/usage.route.js (where applicable)
- Backend controllers (remove replaced manual validation):
- backend/controllers/chat.controller.js
- backend/controllers/chatMessage.controller.js
- backend/controllers/user.controller.js
- backend/controllers/apikey.controller.js
Acceptance Criteria
Summary
Add a centralized Zod-based request validation layer for required API routes and replace ad-hoc/manual input validation inside controllers.
Problem
Validation is currently inconsistent across routes and controllers. Some controllers perform inline checks, while other inputs are not validated in a uniform way. This increases risk of invalid payloads, duplicated logic, and inconsistent error responses.
Expected Solution
Create reusable Zod schemas and a validation middleware for body, params, and query. Attach middleware at route level for required endpoints, then remove controller-level manual input checks that are replaced by schema validation. Standardize validation error response shape.
Scope
Acceptance Criteria