@@ -1 +0,0 @@
|
|||||||
{"mcpServers":{}}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,718 +0,0 @@
|
|||||||
# IGNY8 System Complete Overview
|
|
||||||
|
|
||||||
## Executive Summary
|
|
||||||
|
|
||||||
IGNY8 is a comprehensive AI-powered content generation and management platform built on Django (backend) and React (frontend). The system enables automated content creation workflows from keyword research through publication, with WordPress integration for seamless content distribution.
|
|
||||||
|
|
||||||
## System Architecture
|
|
||||||
|
|
||||||
### Core Technology Stack
|
|
||||||
|
|
||||||
**Backend:**
|
|
||||||
- Django 4.2+ with Django REST Framework
|
|
||||||
- PostgreSQL database
|
|
||||||
- Celery for async task processing
|
|
||||||
- Redis for caching and message broker
|
|
||||||
- JWT authentication
|
|
||||||
|
|
||||||
**Frontend:**
|
|
||||||
- React 18+ with TypeScript
|
|
||||||
- Vite build system
|
|
||||||
- Zustand for state management
|
|
||||||
- TailwindCSS for styling
|
|
||||||
- React Router for navigation
|
|
||||||
|
|
||||||
**AI Integration:**
|
|
||||||
- OpenAI GPT-4 for content generation
|
|
||||||
- Runware for image generation
|
|
||||||
- Custom AI orchestration layer
|
|
||||||
|
|
||||||
## Multi-Tenant Architecture
|
|
||||||
|
|
||||||
### Account Hierarchy
|
|
||||||
|
|
||||||
```
|
|
||||||
Account (Organization)
|
|
||||||
└── Site (Website/Project)
|
|
||||||
└── Sector (Content Category)
|
|
||||||
└── Content/Keywords/Tasks
|
|
||||||
```
|
|
||||||
|
|
||||||
**Key Models:**
|
|
||||||
- [`Account`](backend/igny8_core/auth/models.py:15): Top-level organization
|
|
||||||
- [`Site`](backend/igny8_core/auth/models.py:45): Individual website/project
|
|
||||||
- [`Sector`](backend/igny8_core/auth/models.py:75): Content category within site
|
|
||||||
- [`User`](backend/igny8_core/auth/models.py:105): User with role-based permissions
|
|
||||||
|
|
||||||
### Data Isolation
|
|
||||||
|
|
||||||
All business models inherit from:
|
|
||||||
- [`AccountBaseModel`](backend/igny8_core/auth/models.py:135): Account-level isolation
|
|
||||||
- [`SiteSectorBaseModel`](backend/igny8_core/auth/models.py:155): Site/Sector-level isolation
|
|
||||||
|
|
||||||
## Authentication & Authorization
|
|
||||||
|
|
||||||
### JWT Authentication Flow
|
|
||||||
|
|
||||||
1. User logs in via [`/api/v1/auth/login/`](backend/igny8_core/modules/auth/views.py:25)
|
|
||||||
2. Backend validates credentials and returns JWT tokens
|
|
||||||
3. Frontend stores tokens in localStorage
|
|
||||||
4. [`AccountContextMiddleware`](backend/igny8_core/auth/middleware.py:15) extracts account from token
|
|
||||||
5. All requests include JWT in Authorization header
|
|
||||||
|
|
||||||
### Permission System
|
|
||||||
|
|
||||||
**Roles (Hierarchical):**
|
|
||||||
- Owner: Full access
|
|
||||||
- Admin: Manage users and settings
|
|
||||||
- Editor: Create and edit content
|
|
||||||
- Viewer: Read-only access
|
|
||||||
|
|
||||||
**Implementation:**
|
|
||||||
- [`IsAuthenticatedAndActive`](backend/igny8_core/api/permissions.py:10): Base permission
|
|
||||||
- [`IsViewerOrAbove`](backend/igny8_core/api/permissions.py:25): Minimum viewer role
|
|
||||||
- [`IsEditorOrAbove`](backend/igny8_core/api/permissions.py:40): Minimum editor role
|
|
||||||
|
|
||||||
## API Architecture
|
|
||||||
|
|
||||||
### Unified API Standard v1.0
|
|
||||||
|
|
||||||
All API responses follow this format:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"data": { /* response data */ },
|
|
||||||
"message": "Operation completed successfully",
|
|
||||||
"request_id": "uuid-v4",
|
|
||||||
"timestamp": "2024-01-01T00:00:00Z"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Error Response:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": false,
|
|
||||||
"error": "Error message",
|
|
||||||
"error_code": "ERROR_CODE",
|
|
||||||
"request_id": "uuid-v4",
|
|
||||||
"timestamp": "2024-01-01T00:00:00Z"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Base ViewSets
|
|
||||||
|
|
||||||
**[`AccountModelViewSet`](backend/igny8_core/api/base.py:25):**
|
|
||||||
- Automatic account filtering
|
|
||||||
- Used for account-level resources
|
|
||||||
|
|
||||||
**[`SiteSectorModelViewSet`](backend/igny8_core/api/base.py:65):**
|
|
||||||
- Automatic site/sector filtering
|
|
||||||
- Used for content-related resources
|
|
||||||
- Supports site/sector switching
|
|
||||||
|
|
||||||
## Core Modules
|
|
||||||
|
|
||||||
### 1. Planner Module
|
|
||||||
|
|
||||||
**Purpose:** Keyword research and content planning
|
|
||||||
|
|
||||||
**Key Components:**
|
|
||||||
- [`Keyword`](backend/igny8_core/business/planning/models.py:15): Individual keywords with metrics
|
|
||||||
- [`Cluster`](backend/igny8_core/business/planning/models.py:85): Grouped keywords by topic
|
|
||||||
- [`Task`](backend/igny8_core/business/planning/models.py:155): Content creation tasks
|
|
||||||
|
|
||||||
**AI Functions:**
|
|
||||||
- [`auto_cluster()`](backend/igny8_core/ai/functions/auto_cluster.py:15): Automatic keyword clustering
|
|
||||||
- [`generate_ideas()`](backend/igny8_core/ai/functions/generate_ideas.py:15): Content idea generation
|
|
||||||
|
|
||||||
**API Endpoints:**
|
|
||||||
- `GET/POST /api/v1/planner/keywords/`
|
|
||||||
- `GET/POST /api/v1/planner/clusters/`
|
|
||||||
- `GET/POST /api/v1/planner/tasks/`
|
|
||||||
- `POST /api/v1/planner/keywords/bulk-import/`
|
|
||||||
- `POST /api/v1/planner/clusters/{id}/auto-cluster/`
|
|
||||||
|
|
||||||
### 2. Writer Module
|
|
||||||
|
|
||||||
**Purpose:** AI-powered content generation
|
|
||||||
|
|
||||||
**Key Components:**
|
|
||||||
- [`Content`](backend/igny8_core/business/content/models.py:15): Generated content with metadata
|
|
||||||
- [`ContentVersion`](backend/igny8_core/business/content/models.py:125): Version history
|
|
||||||
- [`ImagePrompt`](backend/igny8_core/business/content/models.py:195): AI image generation prompts
|
|
||||||
- [`GeneratedImage`](backend/igny8_core/business/content/models.py:265): Generated images
|
|
||||||
|
|
||||||
**AI Functions:**
|
|
||||||
- [`generate_content()`](backend/igny8_core/ai/functions/generate_content.py:15): Article generation
|
|
||||||
- [`generate_image_prompts()`](backend/igny8_core/ai/functions/generate_image_prompts.py:15): Image prompt creation
|
|
||||||
- [`generate_images()`](backend/igny8_core/ai/functions/generate_images.py:15): Image generation via Runware
|
|
||||||
|
|
||||||
**API Endpoints:**
|
|
||||||
- `GET/POST /api/v1/writer/content/`
|
|
||||||
- `POST /api/v1/writer/content/{id}/generate/`
|
|
||||||
- `POST /api/v1/writer/content/{id}/regenerate/`
|
|
||||||
- `GET/POST /api/v1/writer/image-prompts/`
|
|
||||||
- `POST /api/v1/writer/images/generate/`
|
|
||||||
|
|
||||||
### 3. Integration Module
|
|
||||||
|
|
||||||
**Purpose:** WordPress bidirectional sync
|
|
||||||
|
|
||||||
**Key Components:**
|
|
||||||
- [`Integration`](backend/igny8_core/business/integration/models.py:15): WordPress site connection
|
|
||||||
- [`SyncLog`](backend/igny8_core/business/integration/models.py:85): Sync operation history
|
|
||||||
|
|
||||||
**WordPress Plugin:**
|
|
||||||
- REST API endpoints for content sync
|
|
||||||
- Webhook notifications for changes
|
|
||||||
- Authentication via API keys
|
|
||||||
|
|
||||||
**API Endpoints:**
|
|
||||||
- `GET/POST /api/v1/integration/integrations/`
|
|
||||||
- `POST /api/v1/integration/integrations/{id}/test-connection/`
|
|
||||||
- `POST /api/v1/integration/integrations/{id}/sync/`
|
|
||||||
- `POST /api/v1/integration/integrations/{id}/publish/`
|
|
||||||
|
|
||||||
**Sync Flow:**
|
|
||||||
1. User creates Integration with WordPress URL and credentials
|
|
||||||
2. System validates connection
|
|
||||||
3. Content can be pushed to WordPress
|
|
||||||
4. WordPress plugin sends webhooks on changes
|
|
||||||
5. System pulls updates and maintains sync
|
|
||||||
|
|
||||||
### 4. Automation Module
|
|
||||||
|
|
||||||
**Purpose:** Automated workflow execution
|
|
||||||
|
|
||||||
**Key Components:**
|
|
||||||
- [`AutomationRule`](backend/igny8_core/business/automation/models.py:11): Workflow definitions
|
|
||||||
- [`ScheduledTask`](backend/igny8_core/business/automation/models.py:93): Scheduled executions
|
|
||||||
|
|
||||||
**Services:**
|
|
||||||
- [`AutomationService`](backend/igny8_core/business/automation/services/automation_service.py:15): Main orchestrator
|
|
||||||
- [`RuleEngine`](backend/igny8_core/business/automation/services/rule_engine.py:15): Condition evaluation
|
|
||||||
- [`ActionExecutor`](backend/igny8_core/business/automation/services/action_executor.py:13): Action execution
|
|
||||||
|
|
||||||
**Rule Structure:**
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"name": "Auto Content Pipeline",
|
|
||||||
"trigger": "schedule",
|
|
||||||
"schedule": "0 0 * * *",
|
|
||||||
"conditions": [
|
|
||||||
{
|
|
||||||
"field": "task.status",
|
|
||||||
"operator": "equals",
|
|
||||||
"value": "pending"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"actions": [
|
|
||||||
{
|
|
||||||
"type": "generate_content",
|
|
||||||
"params": {
|
|
||||||
"task_ids": ["task-id"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "generate_images",
|
|
||||||
"params": {
|
|
||||||
"content_id": "content-id"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
**API Endpoints:**
|
|
||||||
- `GET/POST /api/v1/automation/rules/`
|
|
||||||
- `POST /api/v1/automation/rules/{id}/execute/`
|
|
||||||
- `GET /api/v1/automation/scheduled-tasks/`
|
|
||||||
|
|
||||||
## AI Framework
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
**[`AIEngine`](backend/igny8_core/ai/engine.py:25):**
|
|
||||||
- Central orchestrator for all AI operations
|
|
||||||
- Manages function registry and execution
|
|
||||||
- Handles progress tracking and error handling
|
|
||||||
|
|
||||||
**[`AICore`](backend/igny8_core/ai/core.py:15):**
|
|
||||||
- Low-level API client for OpenAI/Runware
|
|
||||||
- Request/response handling
|
|
||||||
- Rate limiting and retry logic
|
|
||||||
|
|
||||||
**[`AI Function Registry`](backend/igny8_core/ai/registry.py:15):**
|
|
||||||
- Lazy loading of AI functions
|
|
||||||
- Function metadata and validation
|
|
||||||
- Dependency injection
|
|
||||||
|
|
||||||
### AI Function Structure
|
|
||||||
|
|
||||||
Each AI function follows this pattern:
|
|
||||||
|
|
||||||
```python
|
|
||||||
@ai_function(
|
|
||||||
name="function_name",
|
|
||||||
description="Function description",
|
|
||||||
cost_credits=10
|
|
||||||
)
|
|
||||||
def my_ai_function(account, **kwargs):
|
|
||||||
"""
|
|
||||||
AI function implementation
|
|
||||||
|
|
||||||
Args:
|
|
||||||
account: Account instance
|
|
||||||
**kwargs: Function-specific parameters
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: Result with success status
|
|
||||||
"""
|
|
||||||
# Implementation
|
|
||||||
pass
|
|
||||||
```
|
|
||||||
|
|
||||||
### Progress Tracking
|
|
||||||
|
|
||||||
**Celery Integration:**
|
|
||||||
- Each AI operation runs as Celery task
|
|
||||||
- Progress updates via task state
|
|
||||||
- Real-time updates to frontend
|
|
||||||
|
|
||||||
**Progress Phases:**
|
|
||||||
1. Initializing: Setup and validation
|
|
||||||
2. Processing: Main AI operation
|
|
||||||
3. AI Analysis: Post-processing
|
|
||||||
4. Saving: Database persistence
|
|
||||||
5. Completed: Final state
|
|
||||||
|
|
||||||
### Cost Management
|
|
||||||
|
|
||||||
**Credit System:**
|
|
||||||
- [`CreditService`](backend/igny8_core/business/billing/services/credit_service.py:15): Credit management
|
|
||||||
- Pre-execution credit checks
|
|
||||||
- Post-execution credit deduction
|
|
||||||
- Usage tracking and reporting
|
|
||||||
|
|
||||||
**Credit Costs:**
|
|
||||||
- Content generation: 1 credit per 500 words
|
|
||||||
- Image prompts: 0.5 credits per prompt
|
|
||||||
- Image generation: 1-4 credits (provider-dependent)
|
|
||||||
- Keyword clustering: 10 credits per operation
|
|
||||||
|
|
||||||
## Frontend Architecture
|
|
||||||
|
|
||||||
### State Management (Zustand)
|
|
||||||
|
|
||||||
**Global Stores:**
|
|
||||||
- [`authStore`](frontend/src/stores/authStore.ts:10): Authentication state
|
|
||||||
- [`siteStore`](frontend/src/stores/siteStore.ts:10): Site/sector selection
|
|
||||||
- [`contentStore`](frontend/src/stores/contentStore.ts:10): Content management
|
|
||||||
|
|
||||||
**Store Pattern:**
|
|
||||||
```typescript
|
|
||||||
interface Store {
|
|
||||||
// State
|
|
||||||
data: any[];
|
|
||||||
loading: boolean;
|
|
||||||
error: string | null;
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
fetchData: () => Promise<void>;
|
|
||||||
createItem: (item: any) => Promise<void>;
|
|
||||||
updateItem: (id: string, item: any) => Promise<void>;
|
|
||||||
deleteItem: (id: string) => Promise<void>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### API Client
|
|
||||||
|
|
||||||
**[`apiClient`](frontend/src/api/client.ts:15):**
|
|
||||||
- Axios-based HTTP client
|
|
||||||
- Automatic JWT token injection
|
|
||||||
- Request/response interceptors
|
|
||||||
- Error handling and retry logic
|
|
||||||
|
|
||||||
### Component Structure
|
|
||||||
|
|
||||||
**Layout Components:**
|
|
||||||
- [`DefaultLayout`](frontend/src/components/shared/layouts/DefaultLayout.tsx:10): Main app layout
|
|
||||||
- [`Header`](frontend/src/components/header/Header.tsx:10): Top navigation
|
|
||||||
- [`Sidebar`](frontend/src/components/sidebar/Sidebar.tsx:10): Side navigation
|
|
||||||
|
|
||||||
**Common Components:**
|
|
||||||
- [`ProgressModal`](frontend/src/components/common/ProgressModal.tsx:10): AI operation progress
|
|
||||||
- [`ConfirmDialog`](frontend/src/components/common/ConfirmDialog.tsx:10): Confirmation dialogs
|
|
||||||
- [`FormModal`](frontend/src/components/common/FormModal.tsx:10): Generic form modals
|
|
||||||
|
|
||||||
### Routing
|
|
||||||
|
|
||||||
**Protected Routes:**
|
|
||||||
```typescript
|
|
||||||
<ProtectedRoute>
|
|
||||||
<Route path="/planner" element={<PlannerPage />} />
|
|
||||||
<Route path="/writer" element={<WriterPage />} />
|
|
||||||
<Route path="/integration" element={<IntegrationPage />} />
|
|
||||||
<Route path="/automation" element={<AutomationPage />} />
|
|
||||||
</ProtectedRoute>
|
|
||||||
```
|
|
||||||
|
|
||||||
## Database Schema
|
|
||||||
|
|
||||||
### Core Tables
|
|
||||||
|
|
||||||
**Authentication:**
|
|
||||||
- `igny8_accounts`: Organizations
|
|
||||||
- `igny8_sites`: Websites/projects
|
|
||||||
- `igny8_sectors`: Content categories
|
|
||||||
- `igny8_users`: User accounts
|
|
||||||
|
|
||||||
**Planning:**
|
|
||||||
- `igny8_keywords`: Keyword data
|
|
||||||
- `igny8_clusters`: Keyword clusters
|
|
||||||
- `igny8_tasks`: Content tasks
|
|
||||||
|
|
||||||
**Content:**
|
|
||||||
- `igny8_content`: Generated content
|
|
||||||
- `igny8_content_versions`: Version history
|
|
||||||
- `igny8_image_prompts`: Image prompts
|
|
||||||
- `igny8_generated_images`: Generated images
|
|
||||||
|
|
||||||
**Integration:**
|
|
||||||
- `igny8_integrations`: WordPress connections
|
|
||||||
- `igny8_sync_logs`: Sync history
|
|
||||||
|
|
||||||
**Automation:**
|
|
||||||
- `igny8_automation_rules`: Workflow rules
|
|
||||||
- `igny8_scheduled_tasks`: Scheduled executions
|
|
||||||
|
|
||||||
**Billing:**
|
|
||||||
- `igny8_credit_transactions`: Credit usage
|
|
||||||
- `igny8_subscriptions`: Subscription plans
|
|
||||||
|
|
||||||
## Deployment
|
|
||||||
|
|
||||||
### Docker Configuration
|
|
||||||
|
|
||||||
**Services:**
|
|
||||||
- `backend`: Django application
|
|
||||||
- `frontend`: React application
|
|
||||||
- `postgres`: PostgreSQL database
|
|
||||||
- `redis`: Redis cache/broker
|
|
||||||
- `celery`: Celery worker
|
|
||||||
- `celery-beat`: Celery scheduler
|
|
||||||
|
|
||||||
**[`docker-compose.app.yml`](docker-compose.app.yml:1):**
|
|
||||||
```yaml
|
|
||||||
services:
|
|
||||||
backend:
|
|
||||||
build: ./backend
|
|
||||||
ports:
|
|
||||||
- "8000:8000"
|
|
||||||
environment:
|
|
||||||
- DATABASE_URL=postgresql://...
|
|
||||||
- REDIS_URL=redis://...
|
|
||||||
|
|
||||||
frontend:
|
|
||||||
build: ./frontend
|
|
||||||
ports:
|
|
||||||
- "3000:3000"
|
|
||||||
|
|
||||||
postgres:
|
|
||||||
image: postgres:15
|
|
||||||
volumes:
|
|
||||||
- postgres_data:/var/lib/postgresql/data
|
|
||||||
|
|
||||||
redis:
|
|
||||||
image: redis:7-alpine
|
|
||||||
|
|
||||||
celery:
|
|
||||||
build: ./backend
|
|
||||||
command: celery -A igny8_core worker -l info
|
|
||||||
|
|
||||||
celery-beat:
|
|
||||||
build: ./backend
|
|
||||||
command: celery -A igny8_core beat -l info
|
|
||||||
```
|
|
||||||
|
|
||||||
### Environment Variables
|
|
||||||
|
|
||||||
**Backend (.env):**
|
|
||||||
```
|
|
||||||
DEBUG=False
|
|
||||||
SECRET_KEY=your-secret-key
|
|
||||||
DATABASE_URL=postgresql://user:pass@host:5432/db
|
|
||||||
REDIS_URL=redis://host:6379/0
|
|
||||||
OPENAI_API_KEY=sk-...
|
|
||||||
RUNWARE_API_KEY=...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Frontend (.env):**
|
|
||||||
```
|
|
||||||
VITE_API_URL=http://localhost:8000/api/v1
|
|
||||||
VITE_WS_URL=ws://localhost:8000/ws
|
|
||||||
```
|
|
||||||
|
|
||||||
## Security Considerations
|
|
||||||
|
|
||||||
### Authentication Security
|
|
||||||
|
|
||||||
1. **JWT Tokens:**
|
|
||||||
- Access token: 1 hour expiry
|
|
||||||
- Refresh token: 7 days expiry
|
|
||||||
- Secure HTTP-only cookies (optional)
|
|
||||||
|
|
||||||
2. **Password Security:**
|
|
||||||
- Django's PBKDF2 hashing
|
|
||||||
- Minimum 8 characters
|
|
||||||
- Complexity requirements
|
|
||||||
|
|
||||||
3. **API Security:**
|
|
||||||
- Rate limiting per endpoint
|
|
||||||
- CORS configuration
|
|
||||||
- CSRF protection
|
|
||||||
|
|
||||||
### Data Security
|
|
||||||
|
|
||||||
1. **Multi-Tenant Isolation:**
|
|
||||||
- Automatic account filtering
|
|
||||||
- Row-level security
|
|
||||||
- No cross-account data access
|
|
||||||
|
|
||||||
2. **Permission Checks:**
|
|
||||||
- Role-based access control
|
|
||||||
- Object-level permissions
|
|
||||||
- Audit logging
|
|
||||||
|
|
||||||
3. **Sensitive Data:**
|
|
||||||
- API keys encrypted at rest
|
|
||||||
- WordPress credentials secured
|
|
||||||
- PII data protection
|
|
||||||
|
|
||||||
## Performance Optimization
|
|
||||||
|
|
||||||
### Backend Optimization
|
|
||||||
|
|
||||||
1. **Database:**
|
|
||||||
- Indexed foreign keys
|
|
||||||
- Composite indexes for common queries
|
|
||||||
- Query optimization with select_related/prefetch_related
|
|
||||||
|
|
||||||
2. **Caching:**
|
|
||||||
- Redis for session storage
|
|
||||||
- API response caching
|
|
||||||
- Database query caching
|
|
||||||
|
|
||||||
3. **Async Processing:**
|
|
||||||
- Celery for long-running tasks
|
|
||||||
- Background job processing
|
|
||||||
- Task prioritization
|
|
||||||
|
|
||||||
### Frontend Optimization
|
|
||||||
|
|
||||||
1. **Code Splitting:**
|
|
||||||
- Route-based splitting
|
|
||||||
- Lazy loading components
|
|
||||||
- Dynamic imports
|
|
||||||
|
|
||||||
2. **State Management:**
|
|
||||||
- Zustand for minimal re-renders
|
|
||||||
- Selective subscriptions
|
|
||||||
- Memoization
|
|
||||||
|
|
||||||
3. **Asset Optimization:**
|
|
||||||
- Image lazy loading
|
|
||||||
- SVG optimization
|
|
||||||
- Bundle size monitoring
|
|
||||||
|
|
||||||
## Monitoring & Logging
|
|
||||||
|
|
||||||
### Backend Logging
|
|
||||||
|
|
||||||
**Log Levels:**
|
|
||||||
- DEBUG: Development debugging
|
|
||||||
- INFO: General information
|
|
||||||
- WARNING: Warning messages
|
|
||||||
- ERROR: Error conditions
|
|
||||||
- CRITICAL: Critical failures
|
|
||||||
|
|
||||||
**Log Destinations:**
|
|
||||||
- Console output
|
|
||||||
- File rotation
|
|
||||||
- External logging service (optional)
|
|
||||||
|
|
||||||
### Frontend Monitoring
|
|
||||||
|
|
||||||
**Error Tracking:**
|
|
||||||
- React Error Boundaries
|
|
||||||
- API error logging
|
|
||||||
- User action tracking
|
|
||||||
|
|
||||||
**Performance Monitoring:**
|
|
||||||
- Page load times
|
|
||||||
- API response times
|
|
||||||
- Component render times
|
|
||||||
|
|
||||||
## Testing Strategy
|
|
||||||
|
|
||||||
### Backend Testing
|
|
||||||
|
|
||||||
**Unit Tests:**
|
|
||||||
- Model validation
|
|
||||||
- Service logic
|
|
||||||
- Utility functions
|
|
||||||
|
|
||||||
**Integration Tests:**
|
|
||||||
- API endpoints
|
|
||||||
- Database operations
|
|
||||||
- External API calls
|
|
||||||
|
|
||||||
**Test Coverage:**
|
|
||||||
- Minimum 80% coverage
|
|
||||||
- Critical paths 100% coverage
|
|
||||||
|
|
||||||
### Frontend Testing
|
|
||||||
|
|
||||||
**Component Tests:**
|
|
||||||
- React Testing Library
|
|
||||||
- Component rendering
|
|
||||||
- User interactions
|
|
||||||
|
|
||||||
**Integration Tests:**
|
|
||||||
- API integration
|
|
||||||
- State management
|
|
||||||
- Routing
|
|
||||||
|
|
||||||
## Development Workflow
|
|
||||||
|
|
||||||
### Local Development
|
|
||||||
|
|
||||||
1. **Backend Setup:**
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
python -m venv venv
|
|
||||||
source venv/bin/activate # Windows: venv\Scripts\activate
|
|
||||||
pip install -r requirements.txt
|
|
||||||
python manage.py migrate
|
|
||||||
python manage.py runserver
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **Frontend Setup:**
|
|
||||||
```bash
|
|
||||||
cd frontend
|
|
||||||
npm install
|
|
||||||
npm run dev
|
|
||||||
```
|
|
||||||
|
|
||||||
3. **Celery Worker:**
|
|
||||||
```bash
|
|
||||||
cd backend
|
|
||||||
celery -A igny8_core worker -l info
|
|
||||||
```
|
|
||||||
|
|
||||||
### Git Workflow
|
|
||||||
|
|
||||||
1. Create feature branch from `develop`
|
|
||||||
2. Implement changes with tests
|
|
||||||
3. Create pull request
|
|
||||||
4. Code review and approval
|
|
||||||
5. Merge to `develop`
|
|
||||||
6. Deploy to staging
|
|
||||||
7. Merge to `main` for production
|
|
||||||
|
|
||||||
## API Documentation
|
|
||||||
|
|
||||||
### Interactive Documentation
|
|
||||||
|
|
||||||
**Swagger UI:**
|
|
||||||
- URL: `/api/schema/swagger-ui/`
|
|
||||||
- Interactive API testing
|
|
||||||
- Request/response examples
|
|
||||||
|
|
||||||
**ReDoc:**
|
|
||||||
- URL: `/api/schema/redoc/`
|
|
||||||
- Clean documentation view
|
|
||||||
- Searchable endpoints
|
|
||||||
|
|
||||||
### API Versioning
|
|
||||||
|
|
||||||
Current version: **v1.0**
|
|
||||||
|
|
||||||
All endpoints prefixed with `/api/v1/`
|
|
||||||
|
|
||||||
Future versions will use `/api/v2/`, etc.
|
|
||||||
|
|
||||||
## Troubleshooting
|
|
||||||
|
|
||||||
### Common Issues
|
|
||||||
|
|
||||||
**1. Database Connection Errors:**
|
|
||||||
- Check DATABASE_URL in .env
|
|
||||||
- Verify PostgreSQL is running
|
|
||||||
- Check network connectivity
|
|
||||||
|
|
||||||
**2. Celery Task Failures:**
|
|
||||||
- Check Redis connection
|
|
||||||
- Verify Celery worker is running
|
|
||||||
- Check task logs
|
|
||||||
|
|
||||||
**3. Authentication Issues:**
|
|
||||||
- Verify JWT token validity
|
|
||||||
- Check token expiration
|
|
||||||
- Validate user permissions
|
|
||||||
|
|
||||||
**4. WordPress Sync Failures:**
|
|
||||||
- Test WordPress connection
|
|
||||||
- Verify API credentials
|
|
||||||
- Check WordPress plugin version
|
|
||||||
|
|
||||||
## Future Enhancements
|
|
||||||
|
|
||||||
### Planned Features
|
|
||||||
|
|
||||||
1. **Advanced Automation:**
|
|
||||||
- Conditional workflows
|
|
||||||
- Multi-step pipelines
|
|
||||||
- Error recovery
|
|
||||||
|
|
||||||
2. **Enhanced AI:**
|
|
||||||
- Multiple AI providers
|
|
||||||
- Custom model fine-tuning
|
|
||||||
- Advanced prompt engineering
|
|
||||||
|
|
||||||
3. **Collaboration:**
|
|
||||||
- Team workspaces
|
|
||||||
- Content approval workflows
|
|
||||||
- Comment system
|
|
||||||
|
|
||||||
4. **Analytics:**
|
|
||||||
- Content performance tracking
|
|
||||||
- SEO metrics
|
|
||||||
- Usage analytics
|
|
||||||
|
|
||||||
5. **Integrations:**
|
|
||||||
- Additional CMS platforms
|
|
||||||
- Social media publishing
|
|
||||||
- Email marketing tools
|
|
||||||
|
|
||||||
## Support & Resources
|
|
||||||
|
|
||||||
### Documentation
|
|
||||||
|
|
||||||
- System Architecture: [`docs/00-SYSTEM-ARCHITECTURE-MASTER-REFERENCE.md`](docs/00-SYSTEM-ARCHITECTURE-MASTER-REFERENCE.md:1)
|
|
||||||
- REST API: [`docs/01-IGNY8-REST-API-COMPLETE-REFERENCE.md`](docs/01-IGNY8-REST-API-COMPLETE-REFERENCE.md:1)
|
|
||||||
- WordPress Integration: [`docs/03-WORDPRESS-PLUGIN-API-INTEGRATION-GUIDE.md`](docs/03-WORDPRESS-PLUGIN-API-INTEGRATION-GUIDE.md:1)
|
|
||||||
- Automation: [`docs/automation-designer-mode-specification.md`](docs/automation-designer-mode-specification.md:1)
|
|
||||||
|
|
||||||
### Contact
|
|
||||||
|
|
||||||
- Technical Support: support@igny8.com
|
|
||||||
- Documentation: docs.igny8.com
|
|
||||||
- GitHub: github.com/igny8/igny8-app
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Document Version:** 1.0
|
|
||||||
**Last Updated:** 2024-11-30
|
|
||||||
**Maintained By:** IGNY8 Development Team
|
|
||||||
@@ -1,927 +0,0 @@
|
|||||||
# IGNY8 Automation System Implementation Plan
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
This document provides a detailed, step-by-step implementation plan for completing the IGNY8 Automation system. The backend infrastructure is already in place; this plan focuses on extending functionality and building the frontend interface.
|
|
||||||
|
|
||||||
## Current State Analysis
|
|
||||||
|
|
||||||
### ✅ Already Implemented (Backend)
|
|
||||||
|
|
||||||
1. **Data Models** ([`backend/igny8_core/business/automation/models.py`](backend/igny8_core/business/automation/models.py:1))
|
|
||||||
- [`AutomationRule`](backend/igny8_core/business/automation/models.py:11): Complete with trigger types, conditions, actions
|
|
||||||
- [`ScheduledTask`](backend/igny8_core/business/automation/models.py:93): Task scheduling and tracking
|
|
||||||
|
|
||||||
2. **Core Services** ([`backend/igny8_core/business/automation/services/`](backend/igny8_core/business/automation/services/))
|
|
||||||
- [`AutomationService`](backend/igny8_core/business/automation/services/automation_service.py:15): Main orchestrator
|
|
||||||
- [`RuleEngine`](backend/igny8_core/business/automation/services/rule_engine.py:15): Condition evaluation
|
|
||||||
- [`ConditionEvaluator`](backend/igny8_core/business/automation/services/condition_evaluator.py:15): Field path resolution
|
|
||||||
- [`ActionExecutor`](backend/igny8_core/business/automation/services/action_executor.py:13): Action execution (partial)
|
|
||||||
|
|
||||||
3. **API Endpoints** ([`backend/igny8_core/modules/automation/views.py`](backend/igny8_core/modules/automation/views.py:1))
|
|
||||||
- [`AutomationRuleViewSet`](backend/igny8_core/modules/automation/views.py:29): CRUD + execute endpoint
|
|
||||||
- [`ScheduledTaskViewSet`](backend/igny8_core/modules/automation/views.py:76): Task management
|
|
||||||
|
|
||||||
### ❌ Missing Components
|
|
||||||
|
|
||||||
1. **Backend Extensions:**
|
|
||||||
- ActionExecutor only supports 3 actions (cluster_keywords, generate_ideas, generate_content)
|
|
||||||
- Missing: generate_images, generate_site_structure, generate_page_content, optimize_content, publish_to_wordpress
|
|
||||||
- No Celery task integration for async execution
|
|
||||||
- No progress tracking integration
|
|
||||||
- No webhook support for event triggers
|
|
||||||
|
|
||||||
2. **Frontend (Complete):**
|
|
||||||
- No automation module pages
|
|
||||||
- No rule management interface
|
|
||||||
- No workflow visualizer
|
|
||||||
- No execution monitor
|
|
||||||
- No progress tracking UI
|
|
||||||
|
|
||||||
3. **Integration:**
|
|
||||||
- No connection to existing AI functions
|
|
||||||
- No WordPress publish integration
|
|
||||||
- No credit cost estimation
|
|
||||||
|
|
||||||
## Implementation Phases
|
|
||||||
|
|
||||||
### Phase 1: Backend Extensions (Week 1)
|
|
||||||
|
|
||||||
#### 1.1 Extend ActionExecutor
|
|
||||||
|
|
||||||
**File:** [`backend/igny8_core/business/automation/services/action_executor.py`](backend/igny8_core/business/automation/services/action_executor.py:1)
|
|
||||||
|
|
||||||
**Changes Required:**
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Add new action methods to ActionExecutor class
|
|
||||||
|
|
||||||
def _execute_generate_images(self, params, rule):
|
|
||||||
"""Execute generate images action"""
|
|
||||||
content_id = params.get('content_id')
|
|
||||||
provider = params.get('provider', 'dall-e')
|
|
||||||
|
|
||||||
try:
|
|
||||||
from igny8_core.business.content.services.image_generation_service import ImageGenerationService
|
|
||||||
service = ImageGenerationService()
|
|
||||||
|
|
||||||
result = service.generate_images(
|
|
||||||
content_id=content_id,
|
|
||||||
provider=provider,
|
|
||||||
account=rule.account
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error generating images: {str(e)}", exc_info=True)
|
|
||||||
return {'success': False, 'error': str(e)}
|
|
||||||
|
|
||||||
def _execute_generate_site_structure(self, params, rule):
|
|
||||||
"""Execute generate site structure action"""
|
|
||||||
site_id = params.get('site_id') or (rule.site.id if rule.site else None)
|
|
||||||
|
|
||||||
try:
|
|
||||||
from igny8_core.business.sites.services.site_generation_service import SiteGenerationService
|
|
||||||
service = SiteGenerationService()
|
|
||||||
|
|
||||||
result = service.generate_structure(
|
|
||||||
site_id=site_id,
|
|
||||||
account=rule.account
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error generating site structure: {str(e)}", exc_info=True)
|
|
||||||
return {'success': False, 'error': str(e)}
|
|
||||||
|
|
||||||
def _execute_generate_page_content(self, params, rule):
|
|
||||||
"""Execute generate page content action"""
|
|
||||||
page_ids = params.get('page_ids', [])
|
|
||||||
|
|
||||||
try:
|
|
||||||
from igny8_core.business.sites.services.page_generation_service import PageGenerationService
|
|
||||||
service = PageGenerationService()
|
|
||||||
|
|
||||||
result = service.generate_content(
|
|
||||||
page_ids=page_ids,
|
|
||||||
account=rule.account
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error generating page content: {str(e)}", exc_info=True)
|
|
||||||
return {'success': False, 'error': str(e)}
|
|
||||||
|
|
||||||
def _execute_optimize_content(self, params, rule):
|
|
||||||
"""Execute optimize content action"""
|
|
||||||
content_ids = params.get('content_ids', [])
|
|
||||||
|
|
||||||
try:
|
|
||||||
from igny8_core.business.optimizer.services.optimization_service import OptimizationService
|
|
||||||
service = OptimizationService()
|
|
||||||
|
|
||||||
result = service.optimize_content(
|
|
||||||
content_ids=content_ids,
|
|
||||||
account=rule.account
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error optimizing content: {str(e)}", exc_info=True)
|
|
||||||
return {'success': False, 'error': str(e)}
|
|
||||||
|
|
||||||
def _execute_publish_to_wordpress(self, params, rule):
|
|
||||||
"""Execute publish to WordPress action"""
|
|
||||||
content_ids = params.get('content_ids', [])
|
|
||||||
integration_id = params.get('integration_id')
|
|
||||||
|
|
||||||
try:
|
|
||||||
from igny8_core.business.integration.services.wordpress_service import WordPressService
|
|
||||||
service = WordPressService()
|
|
||||||
|
|
||||||
result = service.publish_content(
|
|
||||||
content_ids=content_ids,
|
|
||||||
integration_id=integration_id,
|
|
||||||
account=rule.account
|
|
||||||
)
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error publishing to WordPress: {str(e)}", exc_info=True)
|
|
||||||
return {'success': False, 'error': str(e)}
|
|
||||||
|
|
||||||
# Update execute() method to handle new action types
|
|
||||||
def execute(self, action, context, rule):
|
|
||||||
"""Execute a single action"""
|
|
||||||
action_type = action.get('type')
|
|
||||||
params = action.get('params', {})
|
|
||||||
|
|
||||||
action_map = {
|
|
||||||
'cluster_keywords': self._execute_cluster_keywords,
|
|
||||||
'generate_ideas': self._execute_generate_ideas,
|
|
||||||
'generate_content': self._execute_generate_content,
|
|
||||||
'generate_images': self._execute_generate_images,
|
|
||||||
'generate_site_structure': self._execute_generate_site_structure,
|
|
||||||
'generate_page_content': self._execute_generate_page_content,
|
|
||||||
'optimize_content': self._execute_optimize_content,
|
|
||||||
'publish_to_wordpress': self._execute_publish_to_wordpress,
|
|
||||||
}
|
|
||||||
|
|
||||||
executor = action_map.get(action_type)
|
|
||||||
if executor:
|
|
||||||
return executor(params, rule)
|
|
||||||
else:
|
|
||||||
logger.warning(f"Unknown action type: {action_type}")
|
|
||||||
return {'success': False, 'error': f'Unknown action type: {action_type}'}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 4 hours
|
|
||||||
|
|
||||||
#### 1.2 Create Celery Tasks
|
|
||||||
|
|
||||||
**File:** [`backend/igny8_core/business/automation/tasks.py`](backend/igny8_core/business/automation/tasks.py:1)
|
|
||||||
|
|
||||||
**Changes Required:**
|
|
||||||
|
|
||||||
```python
|
|
||||||
"""
|
|
||||||
Celery tasks for automation
|
|
||||||
"""
|
|
||||||
from celery import shared_task
|
|
||||||
from django.utils import timezone
|
|
||||||
from igny8_core.business.automation.models import AutomationRule, ScheduledTask
|
|
||||||
from igny8_core.business.automation.services.automation_service import AutomationService
|
|
||||||
import logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task(bind=True, name='automation.execute_rule')
|
|
||||||
def execute_rule_task(self, rule_id, context=None):
|
|
||||||
"""
|
|
||||||
Execute an automation rule asynchronously
|
|
||||||
|
|
||||||
Args:
|
|
||||||
rule_id: AutomationRule ID
|
|
||||||
context: Optional context dict
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
rule = AutomationRule.objects.get(id=rule_id)
|
|
||||||
service = AutomationService()
|
|
||||||
|
|
||||||
# Update task progress
|
|
||||||
self.update_state(
|
|
||||||
state='PROGRESS',
|
|
||||||
meta={'phase': 'Initializing', 'progress': 0}
|
|
||||||
)
|
|
||||||
|
|
||||||
result = service.execute_rule(rule, context or {})
|
|
||||||
|
|
||||||
self.update_state(
|
|
||||||
state='SUCCESS',
|
|
||||||
meta={'phase': 'Completed', 'progress': 100, 'result': result}
|
|
||||||
)
|
|
||||||
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Error executing rule {rule_id}: {str(e)}", exc_info=True)
|
|
||||||
self.update_state(
|
|
||||||
state='FAILURE',
|
|
||||||
meta={'error': str(e)}
|
|
||||||
)
|
|
||||||
raise
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task(name='automation.execute_scheduled_rules')
|
|
||||||
def execute_scheduled_rules_task():
|
|
||||||
"""
|
|
||||||
Execute all scheduled rules that are due
|
|
||||||
Called by Celery Beat
|
|
||||||
"""
|
|
||||||
service = AutomationService()
|
|
||||||
result = service.execute_scheduled_rules()
|
|
||||||
logger.info(f"Scheduled rules execution: {result}")
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task(name='automation.cleanup_old_tasks')
|
|
||||||
def cleanup_old_tasks():
|
|
||||||
"""
|
|
||||||
Clean up old scheduled tasks
|
|
||||||
Keep last 30 days only
|
|
||||||
"""
|
|
||||||
from datetime import timedelta
|
|
||||||
cutoff_date = timezone.now() - timedelta(days=30)
|
|
||||||
|
|
||||||
deleted_count = ScheduledTask.objects.filter(
|
|
||||||
created_at__lt=cutoff_date,
|
|
||||||
status__in=['completed', 'failed', 'cancelled']
|
|
||||||
).delete()[0]
|
|
||||||
|
|
||||||
logger.info(f"Cleaned up {deleted_count} old scheduled tasks")
|
|
||||||
return {'deleted': deleted_count}
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 2 hours
|
|
||||||
|
|
||||||
#### 1.3 Add Progress Tracking
|
|
||||||
|
|
||||||
**File:** [`backend/igny8_core/business/automation/services/automation_service.py`](backend/igny8_core/business/automation/services/automation_service.py:1)
|
|
||||||
|
|
||||||
**Changes Required:**
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Add to execute_rule method
|
|
||||||
|
|
||||||
def execute_rule(self, rule, context=None):
|
|
||||||
"""Execute an automation rule with progress tracking"""
|
|
||||||
|
|
||||||
# ... existing code ...
|
|
||||||
|
|
||||||
# Execute via rule engine with progress tracking
|
|
||||||
try:
|
|
||||||
from celery import current_task
|
|
||||||
|
|
||||||
# Update progress for each action
|
|
||||||
total_actions = len(rule.actions)
|
|
||||||
for idx, action in enumerate(rule.actions):
|
|
||||||
if current_task:
|
|
||||||
current_task.update_state(
|
|
||||||
state='PROGRESS',
|
|
||||||
meta={
|
|
||||||
'phase': f'Executing action {idx + 1}/{total_actions}',
|
|
||||||
'progress': int((idx / total_actions) * 100),
|
|
||||||
'action': action.get('type')
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Execute action
|
|
||||||
action_result = self.rule_engine.execute_action(action, context, rule)
|
|
||||||
|
|
||||||
# Store result
|
|
||||||
results.append(action_result)
|
|
||||||
|
|
||||||
# ... rest of existing code ...
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 2 hours
|
|
||||||
|
|
||||||
#### 1.4 Add API Endpoints
|
|
||||||
|
|
||||||
**File:** [`backend/igny8_core/modules/automation/views.py`](backend/igny8_core/modules/automation/views.py:1)
|
|
||||||
|
|
||||||
**Changes Required:**
|
|
||||||
|
|
||||||
```python
|
|
||||||
# Add new endpoints to AutomationRuleViewSet
|
|
||||||
|
|
||||||
@action(detail=True, methods=['get'], url_path='progress', url_name='progress')
|
|
||||||
def get_progress(self, request, pk=None):
|
|
||||||
"""Get execution progress for a rule"""
|
|
||||||
rule = self.get_object()
|
|
||||||
|
|
||||||
# Get latest task for this rule
|
|
||||||
from celery.result import AsyncResult
|
|
||||||
from igny8_core.business.automation.models import ScheduledTask
|
|
||||||
|
|
||||||
latest_task = ScheduledTask.objects.filter(
|
|
||||||
automation_rule=rule,
|
|
||||||
status='running'
|
|
||||||
).order_by('-created_at').first()
|
|
||||||
|
|
||||||
if not latest_task or not latest_task.metadata.get('task_id'):
|
|
||||||
return success_response(
|
|
||||||
data={'status': 'idle'},
|
|
||||||
request=request
|
|
||||||
)
|
|
||||||
|
|
||||||
task_id = latest_task.metadata['task_id']
|
|
||||||
task_result = AsyncResult(task_id)
|
|
||||||
|
|
||||||
return success_response(
|
|
||||||
data={
|
|
||||||
'status': task_result.state,
|
|
||||||
'progress': task_result.info.get('progress', 0) if task_result.info else 0,
|
|
||||||
'phase': task_result.info.get('phase', 'Unknown') if task_result.info else 'Unknown',
|
|
||||||
'result': task_result.result if task_result.successful() else None
|
|
||||||
},
|
|
||||||
request=request
|
|
||||||
)
|
|
||||||
|
|
||||||
@action(detail=False, methods=['get'], url_path='action-types', url_name='action-types')
|
|
||||||
def get_action_types(self, request):
|
|
||||||
"""Get available action types"""
|
|
||||||
action_types = [
|
|
||||||
{
|
|
||||||
'type': 'cluster_keywords',
|
|
||||||
'name': 'Cluster Keywords',
|
|
||||||
'description': 'Automatically cluster keywords by topic',
|
|
||||||
'params': ['keyword_ids', 'sector_id']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'generate_ideas',
|
|
||||||
'name': 'Generate Ideas',
|
|
||||||
'description': 'Generate content ideas from clusters',
|
|
||||||
'params': ['cluster_ids']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'generate_content',
|
|
||||||
'name': 'Generate Content',
|
|
||||||
'description': 'Generate article content from tasks',
|
|
||||||
'params': ['task_ids']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'generate_images',
|
|
||||||
'name': 'Generate Images',
|
|
||||||
'description': 'Generate images for content',
|
|
||||||
'params': ['content_id', 'provider']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'generate_site_structure',
|
|
||||||
'name': 'Generate Site Structure',
|
|
||||||
'description': 'Generate website structure',
|
|
||||||
'params': ['site_id']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'generate_page_content',
|
|
||||||
'name': 'Generate Page Content',
|
|
||||||
'description': 'Generate content for pages',
|
|
||||||
'params': ['page_ids']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'optimize_content',
|
|
||||||
'name': 'Optimize Content',
|
|
||||||
'description': 'Optimize content for SEO',
|
|
||||||
'params': ['content_ids']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'type': 'publish_to_wordpress',
|
|
||||||
'name': 'Publish to WordPress',
|
|
||||||
'description': 'Publish content to WordPress',
|
|
||||||
'params': ['content_ids', 'integration_id']
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
return success_response(
|
|
||||||
data=action_types,
|
|
||||||
request=request
|
|
||||||
)
|
|
||||||
|
|
||||||
@action(detail=False, methods=['get'], url_path='execution-history', url_name='execution-history')
|
|
||||||
def get_execution_history(self, request):
|
|
||||||
"""Get execution history for all rules"""
|
|
||||||
from igny8_core.business.automation.models import ScheduledTask
|
|
||||||
|
|
||||||
tasks = ScheduledTask.objects.filter(
|
|
||||||
automation_rule__account=request.account
|
|
||||||
).select_related('automation_rule').order_by('-executed_at')[:50]
|
|
||||||
|
|
||||||
serializer = ScheduledTaskSerializer(tasks, many=True)
|
|
||||||
|
|
||||||
return success_response(
|
|
||||||
data=serializer.data,
|
|
||||||
request=request
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 3 hours
|
|
||||||
|
|
||||||
### Phase 2: Frontend Foundation (Week 2)
|
|
||||||
|
|
||||||
#### 2.1 Create Automation Store
|
|
||||||
|
|
||||||
**File:** `frontend/src/stores/automationStore.ts` (NEW)
|
|
||||||
|
|
||||||
**Implementation:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { create } from 'zustand';
|
|
||||||
import { automationApi } from '../api/automation.api';
|
|
||||||
|
|
||||||
interface AutomationRule {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
trigger: 'schedule' | 'event' | 'manual';
|
|
||||||
schedule?: string;
|
|
||||||
conditions: any[];
|
|
||||||
actions: any[];
|
|
||||||
is_active: boolean;
|
|
||||||
status: 'active' | 'inactive' | 'paused';
|
|
||||||
last_executed_at?: string;
|
|
||||||
execution_count: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ScheduledTask {
|
|
||||||
id: string;
|
|
||||||
automation_rule: string;
|
|
||||||
scheduled_at: string;
|
|
||||||
executed_at?: string;
|
|
||||||
status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
||||||
result: any;
|
|
||||||
error_message?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AutomationStore {
|
|
||||||
// State
|
|
||||||
rules: AutomationRule[];
|
|
||||||
tasks: ScheduledTask[];
|
|
||||||
actionTypes: any[];
|
|
||||||
loading: boolean;
|
|
||||||
error: string | null;
|
|
||||||
executionProgress: {
|
|
||||||
ruleId: string | null;
|
|
||||||
status: string;
|
|
||||||
progress: number;
|
|
||||||
phase: string;
|
|
||||||
} | null;
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
fetchRules: () => Promise<void>;
|
|
||||||
fetchRule: (id: string) => Promise<AutomationRule>;
|
|
||||||
createRule: (rule: Partial<AutomationRule>) => Promise<AutomationRule>;
|
|
||||||
updateRule: (id: string, rule: Partial<AutomationRule>) => Promise<AutomationRule>;
|
|
||||||
deleteRule: (id: string) => Promise<void>;
|
|
||||||
executeRule: (id: string, context?: any) => Promise<void>;
|
|
||||||
fetchActionTypes: () => Promise<void>;
|
|
||||||
fetchExecutionHistory: () => Promise<void>;
|
|
||||||
fetchProgress: (ruleId: string) => Promise<void>;
|
|
||||||
clearError: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useAutomationStore = create<AutomationStore>((set, get) => ({
|
|
||||||
// Initial state
|
|
||||||
rules: [],
|
|
||||||
tasks: [],
|
|
||||||
actionTypes: [],
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
executionProgress: null,
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
fetchRules: async () => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
const response = await automationApi.getRules();
|
|
||||||
set({ rules: response.data, loading: false });
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fetchRule: async (id: string) => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
const response = await automationApi.getRule(id);
|
|
||||||
set({ loading: false });
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
createRule: async (rule: Partial<AutomationRule>) => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
const response = await automationApi.createRule(rule);
|
|
||||||
set(state => ({
|
|
||||||
rules: [...state.rules, response.data],
|
|
||||||
loading: false
|
|
||||||
}));
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
updateRule: async (id: string, rule: Partial<AutomationRule>) => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
const response = await automationApi.updateRule(id, rule);
|
|
||||||
set(state => ({
|
|
||||||
rules: state.rules.map(r => r.id === id ? response.data : r),
|
|
||||||
loading: false
|
|
||||||
}));
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
deleteRule: async (id: string) => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
await automationApi.deleteRule(id);
|
|
||||||
set(state => ({
|
|
||||||
rules: state.rules.filter(r => r.id !== id),
|
|
||||||
loading: false
|
|
||||||
}));
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
executeRule: async (id: string, context?: any) => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
await automationApi.executeRule(id, context);
|
|
||||||
set({ loading: false });
|
|
||||||
|
|
||||||
// Start polling for progress
|
|
||||||
const pollProgress = setInterval(async () => {
|
|
||||||
await get().fetchProgress(id);
|
|
||||||
const progress = get().executionProgress;
|
|
||||||
if (progress && (progress.status === 'SUCCESS' || progress.status === 'FAILURE')) {
|
|
||||||
clearInterval(pollProgress);
|
|
||||||
}
|
|
||||||
}, 2000);
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fetchActionTypes: async () => {
|
|
||||||
try {
|
|
||||||
const response = await automationApi.getActionTypes();
|
|
||||||
set({ actionTypes: response.data });
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fetchExecutionHistory: async () => {
|
|
||||||
set({ loading: true, error: null });
|
|
||||||
try {
|
|
||||||
const response = await automationApi.getExecutionHistory();
|
|
||||||
set({ tasks: response.data, loading: false });
|
|
||||||
} catch (error: any) {
|
|
||||||
set({ error: error.message, loading: false });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
fetchProgress: async (ruleId: string) => {
|
|
||||||
try {
|
|
||||||
const response = await automationApi.getProgress(ruleId);
|
|
||||||
set({ executionProgress: { ruleId, ...response.data } });
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('Error fetching progress:', error);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
clearError: () => set({ error: null })
|
|
||||||
}));
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 3 hours
|
|
||||||
|
|
||||||
#### 2.2 Create Automation API Client
|
|
||||||
|
|
||||||
**File:** `frontend/src/api/automation.api.ts` (NEW)
|
|
||||||
|
|
||||||
**Implementation:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import apiClient from './client';
|
|
||||||
|
|
||||||
export const automationApi = {
|
|
||||||
// Rules
|
|
||||||
getRules: () => apiClient.get('/automation/rules/'),
|
|
||||||
getRule: (id: string) => apiClient.get(`/automation/rules/${id}/`),
|
|
||||||
createRule: (data: any) => apiClient.post('/automation/rules/', data),
|
|
||||||
updateRule: (id: string, data: any) => apiClient.patch(`/automation/rules/${id}/`, data),
|
|
||||||
deleteRule: (id: string) => apiClient.delete(`/automation/rules/${id}/`),
|
|
||||||
executeRule: (id: string, context?: any) =>
|
|
||||||
apiClient.post(`/automation/rules/${id}/execute/`, { context }),
|
|
||||||
|
|
||||||
// Progress
|
|
||||||
getProgress: (ruleId: string) =>
|
|
||||||
apiClient.get(`/automation/rules/${ruleId}/progress/`),
|
|
||||||
|
|
||||||
// Action types
|
|
||||||
getActionTypes: () => apiClient.get('/automation/rules/action-types/'),
|
|
||||||
|
|
||||||
// Execution history
|
|
||||||
getExecutionHistory: () => apiClient.get('/automation/rules/execution-history/'),
|
|
||||||
|
|
||||||
// Scheduled tasks
|
|
||||||
getTasks: () => apiClient.get('/automation/scheduled-tasks/'),
|
|
||||||
getTask: (id: string) => apiClient.get(`/automation/scheduled-tasks/${id}/`)
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
**Estimated Time:** 1 hour
|
|
||||||
|
|
||||||
### Phase 3: Frontend UI Components (Week 3)
|
|
||||||
|
|
||||||
#### 3.1 Rule List Page
|
|
||||||
|
|
||||||
**File:** `frontend/src/pages/automation/AutomationRulesPage.tsx` (NEW)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- Table view of all automation rules
|
|
||||||
- Status indicators (active/inactive/paused)
|
|
||||||
- Last execution time and count
|
|
||||||
- Quick actions (execute, edit, delete)
|
|
||||||
- Create new rule button
|
|
||||||
|
|
||||||
**Estimated Time:** 6 hours
|
|
||||||
|
|
||||||
#### 3.2 Rule Editor Modal
|
|
||||||
|
|
||||||
**File:** `frontend/src/components/automation/RuleEditorModal.tsx` (NEW)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- Form for rule name, description, trigger type
|
|
||||||
- Schedule configuration (cron expression builder)
|
|
||||||
- Condition builder (field, operator, value)
|
|
||||||
- Action builder (type selector, parameter inputs)
|
|
||||||
- Save/cancel buttons
|
|
||||||
|
|
||||||
**Estimated Time:** 8 hours
|
|
||||||
|
|
||||||
#### 3.3 Workflow Visualizer
|
|
||||||
|
|
||||||
**File:** `frontend/src/components/automation/WorkflowVisualizer.tsx` (NEW)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- Visual flowchart of rule actions
|
|
||||||
- Drag-and-drop action reordering
|
|
||||||
- Action configuration panel
|
|
||||||
- Connection lines between actions
|
|
||||||
- Status indicators during execution
|
|
||||||
|
|
||||||
**Estimated Time:** 12 hours
|
|
||||||
|
|
||||||
#### 3.4 Execution Monitor
|
|
||||||
|
|
||||||
**File:** `frontend/src/components/automation/ExecutionMonitor.tsx` (NEW)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- Real-time progress display
|
|
||||||
- Current phase indicator
|
|
||||||
- Progress percentage
|
|
||||||
- Action-by-action status
|
|
||||||
- Error display
|
|
||||||
- Cancel execution button
|
|
||||||
|
|
||||||
**Estimated Time:** 6 hours
|
|
||||||
|
|
||||||
#### 3.5 Execution History
|
|
||||||
|
|
||||||
**File:** `frontend/src/components/automation/ExecutionHistory.tsx` (NEW)
|
|
||||||
|
|
||||||
**Features:**
|
|
||||||
- Table of past executions
|
|
||||||
- Status badges (completed/failed/cancelled)
|
|
||||||
- Execution time and duration
|
|
||||||
- Result summary
|
|
||||||
- Error details (if failed)
|
|
||||||
- Re-run button
|
|
||||||
|
|
||||||
**Estimated Time:** 4 hours
|
|
||||||
|
|
||||||
### Phase 4: Integration & Testing (Week 4)
|
|
||||||
|
|
||||||
#### 4.1 Backend Integration Tests
|
|
||||||
|
|
||||||
**File:** `backend/igny8_core/business/automation/tests/test_automation.py` (NEW)
|
|
||||||
|
|
||||||
**Test Cases:**
|
|
||||||
- Rule creation and validation
|
|
||||||
- Condition evaluation
|
|
||||||
- Action execution
|
|
||||||
- Progress tracking
|
|
||||||
- Error handling
|
|
||||||
- Credit checking
|
|
||||||
|
|
||||||
**Estimated Time:** 8 hours
|
|
||||||
|
|
||||||
#### 4.2 Frontend Component Tests
|
|
||||||
|
|
||||||
**File:** `frontend/src/components/automation/__tests__/` (NEW)
|
|
||||||
|
|
||||||
**Test Cases:**
|
|
||||||
- Rule list rendering
|
|
||||||
- Rule editor form validation
|
|
||||||
- Workflow visualizer interactions
|
|
||||||
- Execution monitor updates
|
|
||||||
- API integration
|
|
||||||
|
|
||||||
**Estimated Time:** 6 hours
|
|
||||||
|
|
||||||
#### 4.3 End-to-End Testing
|
|
||||||
|
|
||||||
**Manual Testing:**
|
|
||||||
- Create automation rule
|
|
||||||
- Execute rule manually
|
|
||||||
- Monitor progress
|
|
||||||
- Verify results
|
|
||||||
- Test scheduled execution
|
|
||||||
- Test error scenarios
|
|
||||||
|
|
||||||
**Estimated Time:** 4 hours
|
|
||||||
|
|
||||||
#### 4.4 Documentation
|
|
||||||
|
|
||||||
**Files to Update:**
|
|
||||||
- User guide for automation module
|
|
||||||
- API documentation
|
|
||||||
- Developer guide for adding new actions
|
|
||||||
|
|
||||||
**Estimated Time:** 4 hours
|
|
||||||
|
|
||||||
## Implementation Timeline
|
|
||||||
|
|
||||||
### Week 1: Backend Extensions
|
|
||||||
- **Day 1-2:** Extend ActionExecutor with all action types
|
|
||||||
- **Day 3:** Create Celery tasks
|
|
||||||
- **Day 4:** Add progress tracking
|
|
||||||
- **Day 5:** Add API endpoints and testing
|
|
||||||
|
|
||||||
### Week 2: Frontend Foundation
|
|
||||||
- **Day 1:** Create automation store
|
|
||||||
- **Day 2:** Create API client
|
|
||||||
- **Day 3:** Setup routing and page structure
|
|
||||||
- **Day 4-5:** Build rule list page
|
|
||||||
|
|
||||||
### Week 3: Frontend UI
|
|
||||||
- **Day 1-2:** Build rule editor modal
|
|
||||||
- **Day 3-4:** Build workflow visualizer
|
|
||||||
- **Day 5:** Build execution monitor and history
|
|
||||||
|
|
||||||
### Week 4: Integration & Polish
|
|
||||||
- **Day 1-2:** Backend integration tests
|
|
||||||
- **Day 3:** Frontend component tests
|
|
||||||
- **Day 4:** End-to-end testing
|
|
||||||
- **Day 5:** Documentation and polish
|
|
||||||
|
|
||||||
## Resource Requirements
|
|
||||||
|
|
||||||
### Development Team
|
|
||||||
- 1 Backend Developer (Full-time, 4 weeks)
|
|
||||||
- 1 Frontend Developer (Full-time, 4 weeks)
|
|
||||||
- 1 QA Engineer (Part-time, Week 4)
|
|
||||||
|
|
||||||
### Infrastructure
|
|
||||||
- Development environment
|
|
||||||
- Staging environment for testing
|
|
||||||
- Celery worker and beat scheduler
|
|
||||||
- Redis for task queue
|
|
||||||
|
|
||||||
## Risk Assessment
|
|
||||||
|
|
||||||
### High Risk
|
|
||||||
1. **Workflow Visualizer Complexity**
|
|
||||||
- Mitigation: Use existing React Flow library
|
|
||||||
- Fallback: Simpler list-based interface
|
|
||||||
|
|
||||||
2. **Real-time Progress Tracking**
|
|
||||||
- Mitigation: Implement polling with WebSocket fallback
|
|
||||||
- Fallback: Manual refresh button
|
|
||||||
|
|
||||||
### Medium Risk
|
|
||||||
1. **Action Execution Failures**
|
|
||||||
- Mitigation: Comprehensive error handling and retry logic
|
|
||||||
- Fallback: Manual intervention and re-execution
|
|
||||||
|
|
||||||
2. **Credit Estimation Accuracy**
|
|
||||||
- Mitigation: Conservative estimates with buffer
|
|
||||||
- Fallback: Manual credit approval for large operations
|
|
||||||
|
|
||||||
### Low Risk
|
|
||||||
1. **UI/UX Complexity**
|
|
||||||
- Mitigation: Iterative design with user feedback
|
|
||||||
- Fallback: Simplified interface
|
|
||||||
|
|
||||||
## Success Criteria
|
|
||||||
|
|
||||||
### Functional Requirements
|
|
||||||
- ✅ Users can create automation rules with conditions and actions
|
|
||||||
- ✅ Rules can be executed manually or on schedule
|
|
||||||
- ✅ Real-time progress tracking during execution
|
|
||||||
- ✅ Execution history with success/failure status
|
|
||||||
- ✅ All AI functions available as actions
|
|
||||||
- ✅ WordPress publishing integration
|
|
||||||
|
|
||||||
### Performance Requirements
|
|
||||||
- ✅ Rule execution starts within 2 seconds
|
|
||||||
- ✅ Progress updates every 2 seconds
|
|
||||||
- ✅ UI remains responsive during execution
|
|
||||||
- ✅ Support for 100+ concurrent rule executions
|
|
||||||
|
|
||||||
### Quality Requirements
|
|
||||||
- ✅ 80%+ test coverage
|
|
||||||
- ✅ Zero critical bugs
|
|
||||||
- ✅ Comprehensive documentation
|
|
||||||
- ✅ User acceptance testing passed
|
|
||||||
|
|
||||||
## Post-Implementation
|
|
||||||
|
|
||||||
### Monitoring
|
|
||||||
- Track rule execution success rate
|
|
||||||
- Monitor execution duration
|
|
||||||
- Track credit consumption
|
|
||||||
- Monitor error rates
|
|
||||||
|
|
||||||
### Optimization
|
|
||||||
- Optimize slow-running actions
|
|
||||||
- Improve credit estimation accuracy
|
|
||||||
- Enhance error messages
|
|
||||||
- Add more action types based on usage
|
|
||||||
|
|
||||||
### Future Enhancements
|
|
||||||
- Conditional branching (if/else logic)
|
|
||||||
- Parallel action execution
|
|
||||||
- Action templates and presets
|
|
||||||
- Rule sharing and marketplace
|
|
||||||
- Advanced scheduling (multiple schedules per rule)
|
|
||||||
- Webhook triggers for external events
|
|
||||||
|
|
||||||
## Appendix
|
|
||||||
|
|
||||||
### Action Type Reference
|
|
||||||
|
|
||||||
| Action Type | Description | Parameters | Credits |
|
|
||||||
|------------|-------------|------------|---------|
|
|
||||||
| cluster_keywords | Cluster keywords by topic | keyword_ids, sector_id | 10 |
|
|
||||||
| generate_ideas | Generate content ideas | cluster_ids | 15 |
|
|
||||||
| generate_content | Generate article content | task_ids | 50 |
|
|
||||||
| generate_images | Generate images | content_id, provider | 1-4 |
|
|
||||||
| generate_site_structure | Generate site structure | site_id | 20 |
|
|
||||||
| generate_page_content | Generate page content | page_ids | 30 |
|
|
||||||
| optimize_content | Optimize for SEO | content_ids | 10 |
|
|
||||||
| publish_to_wordpress | Publish to WordPress | content_ids, integration_id | 5 |
|
|
||||||
|
|
||||||
### Condition Operators
|
|
||||||
|
|
||||||
| Operator | Description | Example |
|
|
||||||
|----------|-------------|---------|
|
|
||||||
| equals | Exact match | status equals "draft" |
|
|
||||||
| not_equals | Not equal | status not_equals "published" |
|
|
||||||
| contains | String contains | title contains "guide" |
|
|
||||||
| greater_than | Numeric > | word_count greater_than 1000 |
|
|
||||||
| less_than | Numeric < | word_count less_than 5000 |
|
|
||||||
| in | Value in list | status in ["draft", "pending"] |
|
|
||||||
| not_in | Value not in list | status not_in ["archived"] |
|
|
||||||
|
|
||||||
### API Endpoint Summary
|
|
||||||
|
|
||||||
| Method | Endpoint | Description |
|
|
||||||
|--------|----------|-------------|
|
|
||||||
| GET | /api/v1/automation/rules/ | List all rules |
|
|
||||||
| POST | /api/v1/automation/rules/ | Create new rule |
|
|
||||||
| GET | /api/v1/automation/rules/{id}/ | Get rule details |
|
|
||||||
| PUT | /api/v1/automation/rules/{id}/ | Update rule |
|
|
||||||
| DELETE | /api/v1/automation/rules/{id}/ | Delete rule |
|
|
||||||
| POST | /api/v1/automation/rules/{id}/execute/ | Execute rule |
|
|
||||||
| GET | /api/v1/automation/rules/{id}/progress/ | Get execution progress |
|
|
||||||
| GET | /api/v1/automation/rules/action-types/ | Get available actions |
|
|
||||||
| GET | /api/v1/automation/rules/execution-history/ | Get execution history |
|
|
||||||
| GET | /api/v1/automation/scheduled-tasks/ | List scheduled tasks |
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Document Version:** 1.0
|
|
||||||
**Created:** 2024-11-30
|
|
||||||
**Author:** IGNY8 Development Team
|
|
||||||
**Status:** Ready for Implementation
|
|
||||||
@@ -1,196 +0,0 @@
|
|||||||
# IGNY8 Automation Designer Mode Specification
|
|
||||||
|
|
||||||
## Mode Details
|
|
||||||
- **Slug**: `automation-designer`
|
|
||||||
- **Name**: Automation Designer
|
|
||||||
- **Description**: Visual automation workflow designer
|
|
||||||
|
|
||||||
## Role Definition
|
|
||||||
You are Kilo Code, an expert in designing visual automation workflows for AI-powered content generation systems. Your expertise includes:
|
|
||||||
- Designing end-to-end automation pipelines for content creation workflows
|
|
||||||
- Integrating existing system functions into visual automation interfaces
|
|
||||||
- Creating intuitive user interfaces for complex multi-step processes
|
|
||||||
- Mapping manual operations to automated triggers with proper state tracking
|
|
||||||
- Ensuring seamless integration with existing AI frameworks and backend services
|
|
||||||
- Designing real-time progress visualization systems
|
|
||||||
|
|
||||||
## When to Use
|
|
||||||
Use this mode when designing visual automation workflows for the IGNY8 platform, particularly for creating the Automation module interface that will visually execute the complete content generation pipeline from task to publication. This mode is essential for:
|
|
||||||
- Designing the automation rule system
|
|
||||||
- Planning the frontend interface components
|
|
||||||
- Mapping existing manual functions to automation triggers
|
|
||||||
- Creating progress tracking and visualization systems
|
|
||||||
- Designing API extensions for automation control
|
|
||||||
- Integrating with the existing AI framework
|
|
||||||
|
|
||||||
## Tool Groups
|
|
||||||
- `read`: Read files (read_file, fetch_instructions, search_files, list_files, list_code_definition_names)
|
|
||||||
- `edit`: Edit files (apply_diff, write_to_file) - restricted to Markdown files only
|
|
||||||
- `browser`: Browser actions (browser_action)
|
|
||||||
- `command`: Execute commands (execute_command)
|
|
||||||
- `mcp`: MCP operations (use_mcp_tool, access_mcp_resource)
|
|
||||||
|
|
||||||
## Custom Instructions
|
|
||||||
- Always reference the existing IGNY8 system architecture and documentation
|
|
||||||
- Design the automation system to use existing backend functions without duplication
|
|
||||||
- Ensure the visual interface provides real-time feedback using the existing progress tracking system
|
|
||||||
- Maintain consistency with the existing UI patterns and design system
|
|
||||||
- Prioritize user experience and clarity in the automation workflow visualization
|
|
||||||
- Document all integration points with existing modules (Planner, Writer, Integration)
|
|
||||||
- Consider both immediate visual execution and future background processing capabilities
|
|
||||||
- Ensure proper security and permission handling for automation rules
|
|
||||||
|
|
||||||
## Technical Implementation Plan
|
|
||||||
|
|
||||||
### 1. Automation Rule Structure
|
|
||||||
Create a new `AutomationRule` model in the backend with these fields:
|
|
||||||
- `name`: String (required) - Display name for the rule
|
|
||||||
- `description`: Text (optional) - Detailed description
|
|
||||||
- `trigger_type`: Enum ('manual', 'scheduled') - How the rule is initiated
|
|
||||||
- `status`: Enum ('active', 'inactive') - Rule activation status
|
|
||||||
- `workflow_config`: JSONField (required) - Configuration for the automation workflow
|
|
||||||
- `created_by`: ForeignKey(User) - User who created the rule
|
|
||||||
- `created_at`: DateTime - Creation timestamp
|
|
||||||
- `updated_at`: DateTime - Last update timestamp
|
|
||||||
|
|
||||||
The `workflow_config` will contain:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"steps": [
|
|
||||||
{
|
|
||||||
"step_id": "generate_content",
|
|
||||||
"name": "Generate Content",
|
|
||||||
"enabled": true,
|
|
||||||
"source": "task",
|
|
||||||
"parameters": {
|
|
||||||
"task_id": "current_task_id",
|
|
||||||
"model": "gpt-4",
|
|
||||||
"max_retries": 3
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"step_id": "generate_image_prompts",
|
|
||||||
"name": "Generate Image Prompts",
|
|
||||||
"enabled": true,
|
|
||||||
"source": "content",
|
|
||||||
"parameters": {
|
|
||||||
"content_id": "generated_content_id",
|
|
||||||
"max_images": 5
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"step_id": "generate_images",
|
|
||||||
"name": "Generate Images",
|
|
||||||
"enabled": true,
|
|
||||||
"source": "image_prompts",
|
|
||||||
"parameters": {
|
|
||||||
"provider": "dall-e",
|
|
||||||
"model": "dall-e-3",
|
|
||||||
"quality": "high"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"step_id": "review_and_publish",
|
|
||||||
"name": "Review and Publish",
|
|
||||||
"enabled": true,
|
|
||||||
"source": "images",
|
|
||||||
"parameters": {
|
|
||||||
"publish_to": "wordpress",
|
|
||||||
"auto_approve": true,
|
|
||||||
"publish_status": "publish"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"on_completion": "notify_user",
|
|
||||||
"on_failure": "notify_user_and_retry"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Frontend Automation Interface
|
|
||||||
Create a new page at `/automation/rules` with these components:
|
|
||||||
- **Rule List View**: Table showing all automation rules with status indicators
|
|
||||||
- **Rule Editor**: Form to create/edit rules with visual workflow builder
|
|
||||||
- **Workflow Visualizer**: Drag-and-drop interface to arrange steps in sequence
|
|
||||||
- **Execution Monitor**: Real-time progress tracking panel showing current execution
|
|
||||||
- **Execution History**: Log of past executions with success/failure status
|
|
||||||
|
|
||||||
The workflow visualizer will use a flowchart-like interface with:
|
|
||||||
- **Nodes**: Representing each step in the workflow
|
|
||||||
- **Connections**: Arrows showing the sequence of execution
|
|
||||||
- **Status Indicators**: Color-coded dots showing current status (pending, in-progress, completed, failed)
|
|
||||||
- **Parameters Panel**: Configuration options for each step
|
|
||||||
|
|
||||||
### 3. Mapping Manual Functions to Automation Triggers
|
|
||||||
Integrate existing backend functions as automation steps:
|
|
||||||
- `auto_generate_content()` → "Generate Content" step
|
|
||||||
- `generate_image_prompts()` → "Generate Image Prompts" step
|
|
||||||
- `generate_images()` → "Generate Images" step
|
|
||||||
- `publish_content()` → "Review and Publish" step
|
|
||||||
|
|
||||||
Each step will use the same backend services as the manual functions but with additional:
|
|
||||||
- Progress tracking via existing Celery task system
|
|
||||||
- Error handling with retry logic
|
|
||||||
- State persistence between steps
|
|
||||||
|
|
||||||
### 4. Progress Tracking and Visualization
|
|
||||||
Leverage the existing AI progress tracking system:
|
|
||||||
- Each automation rule execution creates a Celery task with unique ID
|
|
||||||
- Progress updates are sent to the frontend via WebSocket or polling
|
|
||||||
- Frontend displays real-time progress using the existing ProgressModal component
|
|
||||||
- Each step shows:
|
|
||||||
- Current phase (Initializing, Processing, AI Analysis, Saving, Completed)
|
|
||||||
- Percentage completion
|
|
||||||
- Detailed step logs
|
|
||||||
- Time elapsed
|
|
||||||
- Error messages (if any)
|
|
||||||
|
|
||||||
### 5. API Endpoint Extensions
|
|
||||||
Add new endpoints to the Automation module:
|
|
||||||
- `POST /api/v1/automation/rules/` - Create new rule
|
|
||||||
- `GET /api/v1/automation/rules/` - List all rules
|
|
||||||
- `GET /api/v1/automation/rules/{id}/` - Get rule details
|
|
||||||
- `PUT /api/v1/automation/rules/{id}/` - Update rule
|
|
||||||
- `DELETE /api/v1/automation/rules/{id}/` - Delete rule
|
|
||||||
- `POST /api/v1/automation/rules/{id}/execute/` - Execute rule manually
|
|
||||||
- `GET /api/v1/automation/executions/` - List execution history
|
|
||||||
- `GET /api/v1/automation/executions/{id}/progress/` - Get real-time progress
|
|
||||||
|
|
||||||
### 6. Integration with Existing AI Framework
|
|
||||||
The automation system will use the existing AI framework components:
|
|
||||||
- `AIEngine` for orchestrating multi-step workflows
|
|
||||||
- `AICore` for making API calls to OpenAI/Runware
|
|
||||||
- `AI Functions Registry` for accessing available functions
|
|
||||||
- `Progress Tracking` for monitoring execution status
|
|
||||||
- `Cost Tracking` for credit consumption
|
|
||||||
|
|
||||||
Each step will consume credits according to existing pricing:
|
|
||||||
- Content generation: 1 credit per 500 words
|
|
||||||
- Image prompts: 0.5 credits per prompt
|
|
||||||
- Image generation: 1-4 credits per image (provider-dependent)
|
|
||||||
|
|
||||||
### 7. Security and Permission Considerations
|
|
||||||
- Only users with Editor or higher role can create/edit automation rules
|
|
||||||
- Rule execution requires appropriate permissions for all steps
|
|
||||||
- Audit logs will track rule creation, modification, and execution
|
|
||||||
- API keys and credentials will be securely stored and accessed
|
|
||||||
- Rate limiting will be applied to prevent abuse
|
|
||||||
|
|
||||||
### 8. Implementation Plan
|
|
||||||
1. Create `AutomationRule` model and migrations
|
|
||||||
2. Implement API endpoints for rule management
|
|
||||||
3. Create backend service to execute automation workflows
|
|
||||||
4. Develop frontend components for rule editor and visualizer
|
|
||||||
5. Integrate with existing AI framework and progress tracking
|
|
||||||
6. Implement WebSocket/polling for real-time updates
|
|
||||||
7. Add security and permission checks
|
|
||||||
8. Test end-to-end workflow with sample data
|
|
||||||
9. Document usage and best practices
|
|
||||||
|
|
||||||
### 9. Future Enhancements
|
|
||||||
- Scheduled execution (cron-like scheduling)
|
|
||||||
- Conditional logic (if/else branches in workflow)
|
|
||||||
- Error handling with fallback steps
|
|
||||||
- User notifications (email, in-app)
|
|
||||||
- Template system for reusable workflows
|
|
||||||
- Import/export of automation rules
|
|
||||||
- Collaboration features (shared rules)
|
|
||||||
Reference in New Issue
Block a user