docs: add system architecture specification for AI orchestration engine#5
Open
mihf05 wants to merge 3 commits into
Open
docs: add system architecture specification for AI orchestration engine#5mihf05 wants to merge 3 commits into
mihf05 wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a comprehensive system architecture specification document for the ContentWatch AI Orchestration Engine, covering component interactions, data model, concurrency controls, real-time streaming, and QA references.
Changes:
- Introduces high-level flow diagrams (Mermaid) and component responsibilities (Nuxt 3, DRF, Celery, Redis, Channels).
- Documents data schema (ER diagram) and deep technical specs (locking + RAG scoring + WS protocol).
- Adds an implementation mapping matrix and test verification pointers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+303
to
+315
| | Architectural Component | Logical Function | Code File Path | Core Lines / Hooks | | ||
| | :--- | :--- | :--- | :--- | | ||
| | **API Trigger Point** | REST Trigger View | [views.py](file:///d:/open-source/ContentWatch/server/ai_workflows/views.py#L84-L129) | `AIPipelineRunViewSet.trigger` | | ||
| | **Redis Memory Lock** | Double-Click Protection | [views.py](file:///d:/open-source/ContentWatch/server/ai_workflows/views.py#L108-L114) | `cache.add("ai_pipeline_trigger_lock_...", ...)` | | ||
| | **Row Transaction Lock** | Write concurrency safe lock | [views.py](file:///d:/open-source/ContentWatch/server/ai_workflows/views.py#L98-L106) | `select_for_update()` inside `transaction.atomic()` | | ||
| | **Task Scheduler** | Offloading to Celery Worker | [views.py](file:///d:/open-source/ContentWatch/server/ai_workflows/views.py#L125) | `execute_ai_pipeline.delay(run.id)` | | ||
| | **Workflow Task Runner** | State Driver / Step Engine | [tasks.py](file:///d:/open-source/ContentWatch/server/ai_workflows/tasks.py#L97-L261) | `@shared_task(name="ai_workflows.execute_pipeline")` | | ||
| | **RAG Retrieval Engine** | Scored Guidelines Context | [tasks.py](file:///d:/open-source/ContentWatch/server/ai_workflows/tasks.py#L42-L94) | `retrieve_rag_context(...)` | | ||
| | **RAG Knowledge Store** | Schema configuration | [models.py](file:///d:/open-source/ContentWatch/server/ai_workflows/models.py#L36-L61) | `AIKnowledgeDocument` | | ||
| | **Multi-Agent Taskforce** | Specialized Agent Profile Schema | [models.py](file:///d:/open-source/ContentWatch/server/ai_workflows/models.py#L5-L34) | `AIAgentProfile` (Writer, Reviewer, Designer, SEO) | | ||
| | **Live Broadcast Utility** | Channels layer event wrapper | [tasks.py](file:///d:/open-source/ContentWatch/server/ai_workflows/tasks.py#L18-L33) | `broadcast_ai_event(...)` | | ||
| | **WebSocket Consumer** | Event stream broker | [consumers.py](file:///d:/open-source/ContentWatch/server/ai_workflows/consumers.py#L5-L66) | `AIConsumer(AsyncJsonWebsocketConsumer)` | | ||
| | **WS Routing Table** | URL Pattern registration | [routing.py](file:///d:/open-source/ContentWatch/server/ai_workflows/routing.py#L4-L6) | `ws/ai/run/<int:run_id>/` | |
Comment on lines
+303
to
+305
| | Architectural Component | Logical Function | Code File Path | Core Lines / Hooks | | ||
| | :--- | :--- | :--- | :--- | | ||
| | **API Trigger Point** | REST Trigger View | [views.py](file:///d:/open-source/ContentWatch/server/ai_workflows/views.py#L84-L129) | `AIPipelineRunViewSet.trigger` | |
Comment on lines
+175
to
+190
| * **Implementation**: Uses Redis `cache.add(lock_key, "locked", timeout=15)` which is an atomic `SETNX` operation under the hood. If the key already exists, the request immediately terminates with an error. | ||
| 2. **Database Row-Level Transaction Lock (PostgreSQL/SQL Server)**: | ||
| * **Purpose**: Ensures database-level serialization and status integrity. | ||
| * **Implementation**: Uses Django's `select_for_update()` inside an atomic transaction block (`transaction.atomic()`). This acquires a write-intent row lock (`SELECT ... FOR UPDATE`), blocking subsequent threads until the active transaction completes and commits the transition status to `pending`. | ||
|
|
||
| ```python | ||
| # Detailed execution path inside views.py | ||
| with transaction.atomic(): | ||
| run = AIPipelineRun.objects.select_for_update().get(id=run.id) | ||
| if run.status in ['pending', 'in_progress']: | ||
| return Response({"error": "Cannot trigger pipeline run in active state."}, status=400) | ||
|
|
||
| lock_key = f"ai_pipeline_trigger_lock_{run.id}" | ||
| if not cache.add(lock_key, "locked", timeout=15): | ||
| return Response({"error": "Execution is already in progress."}, status=400) | ||
|
|
|
|
||
| 1. **Distributed Memory Cache Lock (Redis)**: | ||
| * **Purpose**: Blocks rapid, sub-second "double-click" requests from the client. | ||
| * **Implementation**: Uses Redis `cache.add(lock_key, "locked", timeout=15)` which is an atomic `SETNX` operation under the hood. If the key already exists, the request immediately terminates with an error. |
| * **Role**: Serves as the interactive dashboard for the creator or creative manager. | ||
| * **Key Features**: | ||
| * Triggers workflows and manages inputs (e.g. topic, audience targets, format choices). | ||
| * Opens a persistent bidirectional **WebSocket (WSS)** connection to `ws/ai/run/<run_id>/` upon triggering execution. |
| | **Multi-Agent Taskforce** | Specialized Agent Profile Schema | [models.py](file:///d:/open-source/ContentWatch/server/ai_workflows/models.py#L5-L34) | `AIAgentProfile` (Writer, Reviewer, Designer, SEO) | | ||
| | **Live Broadcast Utility** | Channels layer event wrapper | [tasks.py](file:///d:/open-source/ContentWatch/server/ai_workflows/tasks.py#L18-L33) | `broadcast_ai_event(...)` | | ||
| | **WebSocket Consumer** | Event stream broker | [consumers.py](file:///d:/open-source/ContentWatch/server/ai_workflows/consumers.py#L5-L66) | `AIConsumer(AsyncJsonWebsocketConsumer)` | | ||
| | **WS Routing Table** | URL Pattern registration | [routing.py](file:///d:/open-source/ContentWatch/server/ai_workflows/routing.py#L4-L6) | `ws/ai/run/<int:run_id>/` | |
…ttern path parameters
…documentation for concurrency locks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.