Rename "shop" to "storefront" as not all platforms sell items - storefront is a more accurate term for the customer-facing interface. Changes: - Rename app/api/v1/shop/ → app/api/v1/storefront/ - Rename app/routes/shop_pages.py → app/routes/storefront_pages.py - Rename app/modules/cms/routes/api/shop.py → storefront.py - Rename tests/integration/api/v1/shop/ → storefront/ - Update API prefix from /api/v1/shop to /api/v1/storefront - Update route tags from shop-* to storefront-* - Rename get_shop_context() → get_storefront_context() - Update architecture rules to reference storefront paths - Update all test API endpoint paths This is Phase 2 of the storefront module restructure plan. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
88 lines
2.9 KiB
YAML
88 lines
2.9 KiB
YAML
# Architecture Rules - Authentication & Authorization Rules
|
|
# Rules for auth patterns and multi-tenancy
|
|
|
|
auth_rules:
|
|
|
|
- id: "AUTH-001"
|
|
name: "Use JWT tokens in Authorization header"
|
|
severity: "error"
|
|
description: |
|
|
Authentication must use JWT tokens in Authorization: Bearer header
|
|
pattern:
|
|
file_pattern: "app/api/**/*.py"
|
|
enforcement: "middleware"
|
|
|
|
- id: "AUTH-002"
|
|
name: "Role-based access control with Depends"
|
|
severity: "error"
|
|
description: |
|
|
Use Depends(get_current_admin/vendor/customer) for role checks
|
|
pattern:
|
|
file_pattern: "app/api/v1/**/*.py"
|
|
required: "Depends\\(get_current_"
|
|
|
|
- id: "AUTH-003"
|
|
name: "Never store plain passwords"
|
|
severity: "error"
|
|
description: |
|
|
Always hash passwords with bcrypt before storing
|
|
pattern:
|
|
file_pattern: "app/services/auth_service.py"
|
|
required: "bcrypt"
|
|
|
|
- id: "AUTH-004"
|
|
name: "Vendor context pattern - use appropriate dependency for endpoint type"
|
|
severity: "error"
|
|
description: |
|
|
Two vendor context patterns exist - use the appropriate one:
|
|
|
|
1. SHOP ENDPOINTS (public, no authentication required):
|
|
- Use: vendor: Vendor = Depends(require_vendor_context())
|
|
- Vendor is detected from URL/subdomain/domain
|
|
- File pattern: app/api/v1/storefront/**/*.py
|
|
- Mark as public with: # public
|
|
|
|
2. VENDOR API ENDPOINTS (authenticated):
|
|
- Use: current_user.token_vendor_id from JWT token
|
|
- Or use permission dependencies: require_vendor_permission(), require_vendor_owner
|
|
- These dependencies get vendor from token and set request.state.vendor
|
|
- File pattern: app/api/v1/vendor/**/*.py
|
|
|
|
DEPRECATED for vendor APIs:
|
|
- require_vendor_context() - only for shop endpoints
|
|
- getattr(request.state, "vendor", None) without permission dependency
|
|
|
|
See: docs/backend/vendor-in-token-architecture.md
|
|
pattern:
|
|
file_pattern: "app/api/v1/vendor/**/*.py"
|
|
anti_patterns:
|
|
- "require_vendor_context\\(\\)"
|
|
file_pattern: "app/api/v1/storefront/**/*.py"
|
|
required_patterns:
|
|
- "require_vendor_context\\(\\)|# public"
|
|
|
|
# ============================================================================
|
|
# MULTI-TENANCY RULES
|
|
# ============================================================================
|
|
|
|
multi_tenancy_rules:
|
|
|
|
- id: "MT-001"
|
|
name: "All queries must be scoped to vendor_id"
|
|
severity: "error"
|
|
description: |
|
|
In vendor/shop contexts, all database queries must filter by vendor_id
|
|
pattern:
|
|
file_pattern: "app/services/**/*.py"
|
|
context: "vendor_shop"
|
|
required_pattern: ".filter\\(.*vendor_id.*\\)"
|
|
|
|
- id: "MT-002"
|
|
name: "No cross-vendor data access"
|
|
severity: "error"
|
|
description: |
|
|
Queries must never access data from other vendors
|
|
pattern:
|
|
file_pattern: "app/services/**/*.py"
|
|
enforcement: "database_query_level"
|