WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Module common

    Common validation schemas and utilities for WayrApp Backend API

    This module provides a comprehensive collection of reusable Zod validation schemas that serve as the foundation for data validation across the entire WayrApp language learning platform. These schemas implement consistent validation patterns, data types, and business rules that are shared between multiple modules, ensuring uniform data handling and validation behavior throughout the application.

    The common schemas cover fundamental data types including pagination parameters, identifiers, user information, geographic data, content metadata, and application-specific enumerations. They are designed to be composable building blocks that can be combined to create more complex validation schemas while maintaining consistency and reducing code duplication.

    Key architectural benefits include centralized validation logic that ensures consistent behavior across all API endpoints, reusable schema components that accelerate development, standardized error messages that improve user experience, and type safety through TypeScript integration that prevents runtime errors and improves code reliability.

    The schemas implement industry best practices for data validation including input sanitization to prevent injection attacks, length limits to prevent buffer overflow and denial-of-service attacks, format validation to ensure data integrity, and comprehensive error handling that provides clear feedback for validation failures.

    Security considerations include protection against common web vulnerabilities through strict input validation, prevention of malicious data injection through pattern matching and sanitization, enforcement of business rules that maintain data consistency, and comprehensive logging support for security monitoring and audit trails.

    The module supports internationalization requirements through flexible language and country code validation, accommodates various content types and user roles specific to language learning applications, and provides extensible patterns that can be adapted for future feature requirements and platform evolution.

    Exequiel Trujillo

    1.0.0

    // Basic usage with validation middleware
    import { EmailSchema, PaginationSchema, IdParamSchema } from '@/shared/schemas/common';
    import { validate } from '@/shared/middleware/validation';

    router.get('/users', validate({ query: PaginationSchema }), userController.list);
    router.get('/users/:id', validate({ params: IdParamSchema }), userController.getById);
    // Composing schemas for complex validation
    import { EmailSchema, UsernameSchema, CountryCodeSchema } from '@/shared/schemas/common';

    const UserRegistrationSchema = z.object({
    email: EmailSchema,
    username: UsernameSchema,
    country: CountryCodeSchema.optional()
    });
    // Using factory functions for flexible validation
    import { TextFieldSchema, OptionalTextFieldSchema } from '@/shared/schemas/common';

    const CourseSchema = z.object({
    title: TextFieldSchema(1, 100), // Required, 1-100 characters
    description: OptionalTextFieldSchema(500), // Optional, max 500 characters
    tags: z.array(TextFieldSchema(1, 50)).max(10) // Array of tags, max 10 items
    });

    Type Aliases

    PaginationQuery
    IdParam
    UuidParam

    Variables

    BasePaginationSchema
    PaginationSchema
    IdParamSchema
    UuidParamSchema
    LanguageCodeSchema
    CountryCodeSchema
    EmailSchema
    UsernameSchema
    UrlSchema
    ExperiencePointsSchema
    OrderSchema
    ScoreSchema
    TimeSecondsSchema
    BooleanStringSchema
    RoleSchema
    ModuleTypeSchema
    ExerciseTypeSchema
    JsonSchema

    Functions

    TextFieldSchema
    OptionalTextFieldSchema