# Architecture Rules - Model Rules
# Rules for models/database/*.py, models/schema/*.py, app/modules/*/models/**/*.py, and app/modules/*/schemas/**/*.py files

model_rules:

  - id: "MDL-001"
    name: "Database models must use SQLAlchemy Base"
    severity: "error"
    description: |
      All database models must inherit from SQLAlchemy Base and use proper
      column definitions with types and constraints.
    pattern:
      file_pattern:
        - "models/database/**/*.py"
        - "app/modules/*/models/**/*.py"
      required_patterns:
        - "class.*\\(Base\\):"

  - id: "MDL-002"
    name: "Use Pydantic models separately from SQLAlchemy models"
    severity: "error"
    description: |
      Never mix SQLAlchemy and Pydantic in the same model.
      SQLAlchemy = database schema, Pydantic = API validation/serialization.
    pattern:
      file_pattern:
        - "models/**/*.py"
        - "app/modules/*/models/**/*.py"
        - "app/modules/*/schemas/**/*.py"
      anti_patterns:
        - "class.*\\(Base, BaseModel\\):"

  - id: "MDL-003"
    name: "Pydantic models must use from_attributes for ORM mode"
    severity: "error"
    description: |
      Pydantic response models must enable from_attributes to work with SQLAlchemy models.
    pattern:
      file_pattern:
        - "models/schema/**/*.py"
        - "app/modules/*/schemas/**/*.py"
      required_in_response_models:
        - "from_attributes = True"

  - id: "MDL-004"
    name: "Database tables use plural names"
    severity: "warning"
    description: |
      Database table names should be plural lowercase following industry standard
      conventions (Rails, Django, Laravel, most ORMs). A table represents a
      collection of entities, so plural names are natural: 'users', 'orders',
      'products'. This reads naturally in SQL: SELECT * FROM users WHERE id = 1.

      Examples:
        - Good: users, vendors, products, orders, order_items, cart_items
        - Bad: user, vendor, product, order

      Junction/join tables use both entity names in plural:
        - Good: vendor_users, order_items, product_translations
    pattern:
      file_pattern:
        - "models/database/**/*.py"
        - "app/modules/*/models/**/*.py"
      check: "table_naming_plural"
