# System Endpoints ## Purpose Document system module endpoints for AI prompts, author profiles, strategies, and system/settings resources. ## Code Locations (exact paths) - Routing: `backend/igny8_core/modules/system/urls.py` - Views: `backend/igny8_core/modules/system/views.py` - Models/serializers: `backend/igny8_core/modules/system/models.py`, `serializers.py` ## High-Level Responsibilities - Manage account-scoped AI prompts, author profiles, and strategies. - Expose system/user/module/AI settings endpoints. - Provide prompt retrieval by type and save/reset helpers with role checks. ## Detailed Behavior - Base path: `/api/v1/system/` - Routers register: - `prompts/` → `AIPromptViewSet` (CRUD, `by_type`, `save_prompt`, `reset_prompt`) - `author-profiles/` → `AuthorProfileViewSet` (CRUD) - `strategies/` → `StrategyViewSet` (CRUD) - `settings/system`, `settings/account`, `settings/user`, `settings/modules`, `settings/ai` → respective settings viewsets - AIPromptViewSet: - Permissions: `IsAuthenticatedAndActive`, `HasTenantAccess`; throttle scope `system`; paginated. - `by_type` returns prompt by prompt_type, or default when missing. - `save_prompt`/`reset_prompt` require editor-or-above; set/read account from request/user or first account fallback (dev). - Queryset ordered by prompt_type. - Settings viewsets expose retrieve/update for their scope (system/account/user/modules/ai). Permissions and scoping follow AccountModelViewSet. - AuthorProfile/Strategy viewsets provide standard CRUD under account scoping. ## Data Structures / Models Involved (no code) - `AIPrompt` (prompt_type, prompt_value, default_prompt, is_active), `AuthorProfile`, `Strategy`, settings models. ## Execution Flow - Requests → DRF auth → AccountModelViewSet filtering → serializer validation → model CRUD → unified responses. Custom actions handle prompt save/reset/type lookups. ## Cross-Module Interactions - Prompts are consumed by AI functions; settings may influence module behavior (e.g., AI config). ## State Transitions - Prompt updates, resets; settings updates; author profile/strategy CRUD. ## Error Handling - Unified errors; 403 when lacking editor role for prompt save/reset; 400 on missing prompt_type/value. ## Tenancy Rules - All resources are account scoped via AccountModelViewSet and permissions. ## Billing Rules - None; prompts/settings do not affect credits directly. ## Background Tasks / Schedulers - None. ## Key Design Considerations - Prompt defaults are returned when custom prompt missing to keep AI flows resilient. - Editor-or-above requirement protects prompt modifications. ## How Developers Should Work With This Module - Use provided viewsets/actions; ensure account context is set. Extend settings endpoints by adding serializers/models and wiring to the router.