Skip to content

docs: add system architecture specification for AI orchestration engine#5

Open
mihf05 wants to merge 3 commits into
XST-BD:mainfrom
mihf05:task-4
Open

docs: add system architecture specification for AI orchestration engine#5
mihf05 wants to merge 3 commits into
XST-BD:mainfrom
mihf05:task-4

Conversation

@mihf05
Copy link
Copy Markdown
Contributor

@mihf05 mihf05 commented May 26, 2026

No description provided.

Copilot AI review requested due to automatic review settings May 26, 2026 02:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 thread SYSTEM_ARCHITECTURE.md Outdated
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 thread SYSTEM_ARCHITECTURE.md Outdated
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 thread SYSTEM_ARCHITECTURE.md Outdated
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)

Comment thread SYSTEM_ARCHITECTURE.md Outdated

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.
Comment thread SYSTEM_ARCHITECTURE.md Outdated
* **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.
Comment thread SYSTEM_ARCHITECTURE.md Outdated
| **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>/` |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants