Skip to content

Introduce Zod Validation Middleware Across API Routes #13

@avishek0769

Description

@avishek0769

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

  • Zod middleware exists and supports validating req.body, req.params, and req.query.
  • Required API routes are wired to route-level Zod schemas.
  • Manual validation in controllers is removed where equivalent Zod schema validation is in place.
  • Validation failures return consistent 4xx responses with clear field-level messages.
  • Existing successful request behavior remains backward compatible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend issueseasyThis issue is easy to solveenhancementNew feature or requestgood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions