""" Schema definitions for the code generation system. Defines strict contracts for all intermediate and final outputs. """ from typing import Any, Dict, List, Optional from dataclasses import dataclass from enum import Enum class FieldType(str, Enum): """Supported field types in schemas.""" STRING = "string" NUMBER = "number" BOOLEAN = "boolean" ARRAY = "array" OBJECT = "object" DATE = "date" EMAIL = "email" ENUM = "enum" @dataclass class Field: """Represents a field in any schema.""" name: str type: FieldType required: bool = True description: str = "" validation_rules: Optional[Dict[str, Any]] = None enum_values: Optional[List[str]] = None @dataclass class DBTable: """Database table schema.""" name: str fields: List[Field] primary_key: str relations: Optional[Dict[str, str]] = None # field_name -> other_table indexes: Optional[List[str]] = None @dataclass class APIEndpoint: """API endpoint schema.""" path: str method: str # GET, POST, PUT, DELETE description: str request_body: Optional[Dict[str, Field]] = None response_body: Optional[Dict[str, Field]] = None required_role: Optional[str] = None validation_rules: Optional[List[str]] = None @dataclass class UIComponent: """UI component schema.""" name: str type: str # button, input, form, table, etc. fields: List[Field] visibility_rules: Optional[List[str]] = None validation_rules: Optional[List[str]] = None @dataclass class UIPage: """UI page schema.""" path: str title: str components: List[UIComponent] required_role: Optional[str] = None data_source: Optional[str] = None # API endpoint @dataclass class Role: """Authorization role.""" name: str permissions: List[str] # e.g., ["read_contacts", "create_contact"] description: str @dataclass class AppIntentExtraction: """Output of Intent Extraction stage.""" app_name: str app_description: str key_features: List[str] user_roles: List[str] core_entities: List[str] business_requirements: List[str] constraints: List[str] @dataclass class SystemDesign: """Output of System Design stage.""" entities: Dict[str, List[str]] # entity_name -> attributes user_flows: List[Dict[str, Any]] # flow descriptions roles_and_permissions: Dict[str, List[str]] # role -> permissions data_models: List[str] api_patterns: List[str] ui_structure: List[str] @dataclass class GeneratedConfig: """Final generated configuration.""" app_name: str app_description: str database_schema: List[DBTable] api_schema: List[APIEndpoint] ui_schema: List[UIPage] auth_config: Dict[str, Any] roles: List[Role] business_logic: Dict[str, Any] validation_metadata: Dict[str, Any] class ValidationResult: """Represents validation result with detailed errors.""" def __init__(self, is_valid: bool = True, errors: Optional[List[str]] = None, warnings: Optional[List[str]] = None, repairs_applied: Optional[List[str]] = None): self.is_valid = is_valid self.errors = errors or [] self.warnings = warnings or [] self.repairs_applied = repairs_applied or [] def add_error(self, error: str): self.errors.append(error) self.is_valid = False def add_warning(self, warning: str): self.warnings.append(warning) def add_repair(self, repair: str): self.repairs_applied.append(repair) def to_dict(self): return { "is_valid": self.is_valid, "errors": self.errors, "warnings": self.warnings, "repairs_applied": self.repairs_applied }