Move 9 init/seed scripts into scripts/seed/ and 7 validation scripts (+ validators/ subfolder) into scripts/validate/ to reduce clutter in the root scripts/ directory. Update all references across Makefile, CI/CD configs, pre-commit hooks, docs (~40 files), and Python imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5.9 KiB
Architecture Violations Status
Date: 2026-01-08 Total Violations: 0 blocking (221 documented/accepted) Status: ✅ All architecture validation errors resolved
Summary
Fixed 18 violations and documented remaining violations as intentional architectural decisions.
Fixed Violations (18)
JavaScript Centralized Logging
- ✅
static/admin/js/marketplace.js- Replaced 18 console.log calls with adminMarketplaceLog - ✅
static/admin/js/store-themes.js- Replaced 5 console.log calls with storeThemesLog - ✅
static/admin/js/settings.js- Replaced 1 console.log call with settingsLog - ✅
static/admin/js/imports.js- Replaced 13 console.log calls with importsLog
Remaining Violations (221)
Category 1: Transaction Control at API Layer (Intentional)
Violation: API-002 - Database commits in endpoints
Files Affected:
app/api/v1/admin/merchants.py(5 occurrences)app/api/v1/admin/stores.py(2 occurrences)- Other admin endpoints
Architectural Decision:
This is an intentional and standard pattern in FastAPI applications:
# Service Layer - Business Logic
def update_merchant(self, db: Session, merchant_id: int, data: MerchantUpdate):
merchant = self.get_merchant_by_id(db, merchant_id)
# ... business logic ...
db.flush() # Flush to get IDs, but don't commit
return merchant
# API Layer - Transaction Boundary
@router.put("/merchants/{merchant_id}")
async def update_merchant_endpoint(merchant_id: int, data: MerchantUpdate, db: Session = Depends(get_db)):
merchant = merchant_service.update_merchant(db, merchant_id, data)
db.commit() # ✅ ARCH: Commit at API level for transaction control
return merchant
Benefits:
- Service methods can call other service methods within same transaction
- API layer can rollback entire transaction on error
- Allows for complex multi-step operations
- Standard practice recommended by FastAPI documentation
Status: ✅ ACCEPTED - Added comments to document intention
Category 2: Raw Dict Responses (Legacy - Low Priority)
Violation: API-001 - Endpoint returns raw dict instead of Pydantic model
Files Affected:
app/api/v1/admin/users.pyapp/api/v1/admin/auth.pyapp/api/v1/admin/store_themes.pyapp/api/v1/admin/logs.pyapp/api/v1/admin/notifications.py- Various other endpoints
Reason: These are legacy endpoints created before Pydantic response models were standardized.
Impact: Low - endpoints work correctly, just missing type validation/documentation
Refactoring Plan:
- ⏰ Low priority - will refactor incrementally
- 📝 Create Pydantic response models
- 🔄 Update endpoints to use response_model parameter
Status: 📝 DOCUMENTED - Will fix in future refactoring sprint
Category 3: Service Layer Patterns (Legacy - Medium Priority)
Violations:
- SVC-001: Services creating instances of other services
- SVC-002: Services with unused methods
- SVC-003: Services storing db session
Reason: Pre-existing code before architecture rules were established
Refactoring Plan:
- ⏰ Medium priority
- 🔄 Gradual refactoring as we touch each service
- 📝 Follow dependency injection pattern for new code
Status: 📝 DOCUMENTED - Will fix incrementally
Category 4: Database Queries in Endpoints (Case-by-Case)
Violation: API-002 - Database queries should be in service layer
Files:
app/api/v1/admin/stores.py:63app/api/v1/admin/store_domains.py:51app/api/v1/admin/content_pages.py:188
Reason: Simple read queries that don't justify service layer complexity
Decision:
- Some simple lookups can stay in endpoints
- Complex business logic should move to services
Status: 📝 REVIEW CASE-BY-CASE
Category 5: Template Warnings (Low Priority)
Violation: TMPL-001 - Templates using inline CSS/JS
Reason: Development speed vs perfect separation
Impact: Low - doesn't affect functionality
Status: 📝 ACCEPTED - Inline styles OK for admin pages
Architecture Validation Philosophy
What We Enforce Strictly:
- ✅ Centralized logging (no console.log)
- ✅ Custom exceptions with proper status codes
- ✅ Pydantic models for new endpoints
- ✅ Service layer for complex business logic
What We Accept:
- ✅ Transaction control at API layer (documented)
- ✅ Simple queries in endpoints (case-by-case)
- ✅ Legacy code patterns (document and refactor incrementally)
What We're Improving:
- 🔄 Gradually adding Pydantic response models
- 🔄 Refactoring services to use dependency injection
- 🔄 Moving complex queries to service layer
Progress Tracking
| Category | Count | Priority | Status |
|---|---|---|---|
| JavaScript console.log | 0 | High | ✅ Fixed |
| Transaction control (intentional) | ~10 | N/A | ✅ Documented |
| Raw dict responses | ~40 | Low | 📝 Backlog |
| Service patterns | ~50 | Medium | 📝 Incremental |
| Simple queries in endpoints | ~10 | Low | 📝 Case-by-case |
| Template inline styles | ~110 | Low | ✅ Accepted |
Validation Command
python scripts/validate/validate_architecture.py
Next Actions
Immediate (Done)
- Fix JavaScript console.log violations
- Document transaction control pattern
- Add comments to intentional violations
Short Term (Next Sprint)
- Create Pydantic response models for top 10 endpoints
- Refactor 2-3 services to use dependency injection
- Move complex queries to service layer
Long Term (Continuous)
- Gradually refactor legacy endpoints
- Standardize all services
- Achieve <50 total violations
Conclusion
Current State: 221 violations
- 18 fixed
- ~120 acceptable (documented reasons)
- ~80 legacy code (low priority refactoring)
Philosophy: Enforce strict standards for new code, document and incrementally improve legacy code.
Result: ✅ Codebase is in good architectural health with clear improvement path.