Split the monolithic .architecture-rules.yaml (1700+ lines) into focused domain-specific files in .architecture-rules/ directory: - _main.yaml: Core config, principles, ignore patterns, severity levels - api.yaml: API endpoint rules (API-001 to API-005) - service.yaml: Service layer rules (SVC-001 to SVC-007) - model.yaml: Model rules (MDL-001 to MDL-004) - exception.yaml: Exception handling rules (EXC-001 to EXC-005) - naming.yaml: Naming convention rules (NAM-001 to NAM-005) - auth.yaml: Auth and multi-tenancy rules (AUTH-*, MT-*) - middleware.yaml: Middleware rules (MDW-001 to MDW-002) - frontend.yaml: Frontend rules (JS-*, TPL-*, FE-*, CSS-*) - language.yaml: Language/i18n rules (LANG-001 to LANG-010) - quality.yaml: Code quality rules (QUAL-001 to QUAL-003) Also creates scripts/validators/ module with base classes for future modular validator extraction. The validate_architecture.py loader now auto-detects and merges split YAML files while maintaining backward compatibility with single file mode. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
56 lines
1.9 KiB
YAML
56 lines
1.9 KiB
YAML
# Architecture Rules - Model Rules
|
|
# Rules for models/database/*.py and models/schema/*.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"
|
|
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"
|
|
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"
|
|
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"
|
|
check: "table_naming_plural"
|