Skip to content

[FEATURE] Add collection-level data validation rules — enforce schema constraints (min/max length, regex, required fields) before insert/update #279

@Abhushan187

Description

@Abhushan187

Problem

While urBackend supports unique field constraints (PR #52), there is no way for project owners to enforce data quality rules such as "email must match regex", "username must be 3-20 characters", or "age must be a positive integer". Invalid data enters the database freely, causing application bugs downstream and forcing client-side validation duplication across every SDK consumer.


Proposed Improvement

Add per-field validation rules in the collection schema designer that enforce constraints at the API level before any insert or update operation. The feature should:

  • Support validation types: minLength, maxLength, min, max, regex, enum, required
  • Validate on both POST /api/data/{collection} (insert) and PATCH /api/data/{collection}/{id} (update)
  • Return standardized 422 Unprocessable Entity with detailed field-level error messages
  • Show validation rules in the dashboard schema designer with live preview
  • Apply validation in both public-api and dashboard-api for consistency
  • Skip validation for sk_live requests if explicitly configured (admin override)

Expected Impact

  • Better data quality and integrity across all projects
  • Reduced client-side validation duplication in SDKs
  • Improved developer experience with clear validation errors
  • Better long-term scalability with pluggable validation engine

Possible Implementation

  • Add ValidationRule schema to packages/common/models/ with fields: type, value, message, fieldId
  • Extend Field model with validationRules array
  • Add validateDocument middleware in apps/public-api/middleware/ and apps/dashboard-api/middleware/
  • Integrate with existing unique constraint flow (PR feat: add unique field constraints support with validation and model … #52) for unified validation pipeline
  • Update dashboard UI: add validation rule builder per field type with regex tester
  • Add GET /api/projects/{id}/collections/{name}/validation endpoint to fetch rules
  • Write tests for each validation type, edge cases (empty string, null, regex edge cases), and bypass scenarios

I'm GSSoC'26 contributor, Please assign this task to me!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions