Check for proper separation of concerns between layers
Analyzes Python codebase for repository pattern violations across router, service, and repository layers.
/plugin marketplace add adelabdelgawad/full-stack/plugin install repository-pattern@full-stackIMPORTANT: When this command is invoked, you MUST actually SCAN the codebase and REPORT findings. Do NOT just describe what to check.
Use Glob to find files in each layer:
Routers: {backend}/api/routers/*.py
Services: {backend}/api/services/*_service.py
Repositories: {backend}/api/repositories/*_repository.py
Routers should ONLY:
❌ VIOLATIONS to find:
from api.repositories.* import *Repositorysession.execute()Services should:
❌ VIOLATIONS to find:
session.execute(text(...) - Raw SQLsession.query(...) - Direct queryselect(Model).where(...) without using repositoryRepositories should:
flush() not commit()❌ VIOLATIONS to find:
session.commit() - Should use flush()HTTPException, status.HTTP_*)FORMAT YOUR OUTPUT EXACTLY LIKE THIS:
╔══════════════════════════════════════════════════════════════╗
║ REPOSITORY PATTERN COMPLIANCE REPORT ║
╚══════════════════════════════════════════════════════════════╝
📋 LAYER ANALYSIS
────────────────────────
🔷 ROUTERS
✅ user_router.py - Clean (delegates to services)
✅ role_router.py - Clean
❌ order_router.py - VIOLATION: Direct repository call
🔷 SERVICES
✅ user_service.py - Clean (uses repositories)
❌ report_service.py - VIOLATION: Raw SQL query
🔷 REPOSITORIES
✅ user_repository.py - Clean (uses flush)
❌ order_repository.py - VIOLATION: Calls commit()
📊 VIOLATIONS DETAIL
────────────────────────
order_router.py:
Line 45: from api.repositories.order_repository import OrderRepository
Line 67: repo = OrderRepository() ❌ Router should not use repository directly
report_service.py:
Line 89: result = await session.execute(text("SELECT ...")) ❌ Raw SQL in service
order_repository.py:
Line 34: await session.commit() ❌ Should use flush()
📊 SUMMARY
────────────────────────
Routers clean: 5/6
Services clean: 4/5
Repositories clean: 5/6
Total violations: 3
🔧 REQUIRED FIXES
────────────────────────
1. order_router.py: Move repository call to OrderService
2. report_service.py: Create ReportRepository for raw queries
3. order_repository.py: Replace commit() with flush()
If violations are found, ask: "Would you like me to fix the layer separation violations?"
If user agrees:
Move repository calls to services:
# Before (router)
@router.get("/orders/{id}")
async def get_order(id: str, session = Depends(get_session)):
repo = OrderRepository()
return await repo.get_by_id(session, id)
# After (router)
@router.get("/orders/{id}")
async def get_order(id: str, session = Depends(get_session)):
return await OrderService().get_by_id(session, id)
Move raw SQL to repositories:
# Create new repository method
class ReportRepository:
async def get_summary(self, session):
result = await session.execute(text("SELECT ..."))
return result.fetchall()
# Before
await session.commit()
# After
await session.flush()
This command MUST:
DO NOT just tell the user to run a script. PERFORM THE CHECK.