-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Description
The api/admin.py file contains extensive direct database queries, violating the layered architecture. Almost every endpoint executes raw SQL via db.execute() instead of delegating to services/repositories.
Steps to Reproduce
- Open
backend/api/admin.py - Search for
db.executeorawait db.execute - Count occurrences: 30+ direct DB calls
Expected Behavior
API layer should only:
- Parse HTTP requests
- Call services for business logic
- Return HTTP responses
All database queries should go through Service → Repository layers.
Actual Behavior
API endpoints directly execute database queries:
- Lines 89-111: Query profiles, count interests
- Lines 268-273, 345-350: Count recommendations
- Lines 335-336: Add activity logs
- Lines 434-520: Analytics queries
- Lines 536-808: Distribution/growth queries
- Lines 829-943: Dashboard insights
Root Cause
The admin feature was built quickly without following the established layered architecture pattern used elsewhere (e.g., api/profiles.py → ProfileService → UserProfileRepository).
Possible Solutions
-
Option A: Create AdminService + AnalyticsRepository
- Create
services/admin_service.pyfor user management logic - Create
repositories/analytics_repository.pyfor analytics queries - Refactor all endpoints to use these layers
- Create
-
Option B: Extend Existing Repositories
- Add analytics methods to
UserRepository - Add methods to
RecommendationRepository - Create minimal
AdminServicefor orchestration
- Add analytics methods to
-
Option C: Create AnalyticsService Only
- Create
services/analytics_service.pythat encapsulates queries - Accept that some admin endpoints are thin wrappers
- Focus on DRY principle rather than strict layering
- Create
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels