Files
ALwrity/backend/services/blog_writer
ajaysi 923fa671fe feat: ContentGuardianAgent, onboarding UX, Team Activity action wiring, docs, agent help modal
ContentGuardianAgent consolidation:
- Merge 3 duplicate classes into single source in specialized/content_guardian.py
- Watchdog audit_committee() with heuristic scoring, coverage gaps, overlaps, alerts
- Remove misleading rejection_rate() helper; use acceptance_rate directly
- Integrate audit + alerts + trend signals into today_workflow_service.py

Team Activity page:
- QualityAuditPanel: health ring, per-agent critiques, coverage gaps, overlaps
- TrendSignalsPanel: opportunity cards with urgency/impact/coverage bars
- AlertBanner: persistent dismiss via POST /alerts/{id}/mark-read
- AgentHelpModal: dialog showing all 8 agents with descriptions, tools, schedule
- QualityAuditPanel action buttons: Fill gap -> /content-planning, Resolve overlap, View CTA on alerts/issues
- TrendSignalsPanel action buttons: Create content from this trend -> /blog-writer with trend context state

Onboarding system:
- Step 4 validation: no auto-pass via basic_ready; requires persona data or explicit progression
- Step 5 validation: logs warning on auto-pass without integration data
- OnboardingCompletionService: single DB session, transactional task creation, upsert pattern
- Business-without-website: nullable website_url on SIFIndexingTask and MarketTrendsTask
- DeepCompetitorAnalysisExecutor: 5-min timeout, 10-competitor cap, asyncio.wait_for
- Persona generation: async with 30s timeout, falls back to scheduler
- OnboardingProgressService.reset_onboarding(): resets session + pauses all DB tasks
- OnboardingControlService.reset_onboarding(): also cancels APScheduler jobs
- FinalStep TaskSchedulingPanel: shows scheduled/failed tasks after completion, 8s auto-redirect
- onboarding_completed agent activity event logged to feed

Documentation:
- docs-site/features/onboarding/: overview, steps, scheduler-tasks, technical-reference (4 pages)
- docs-site/mkdocs.yml: added Onboarding System nav section
- docs-site/features/sif-agents/: overview, agent-directory, committee-system, content-guardian (4 pages)
- docs-site/features/team-activity/: overview, quality-audit, trend-signals, alert-system (4 pages)
- docs-site/features/todays-workflow/: updated overview, technical-architecture, workflow-guide, api-reference
2026-06-01 12:24:31 +05:30
..
2026-05-23 13:09:41 +05:30

AI Blog Writer Service Architecture

This directory contains the refactored AI Blog Writer service with a clean, modular architecture.

📁 Directory Structure

blog_writer/
├── README.md                    # This file
├── blog_service.py             # Main entry point (imports from core)
├── core/                       # Core service orchestrator
│   ├── __init__.py
│   └── blog_writer_service.py  # Main service coordinator
├── research/                   # Research functionality
│   ├── __init__.py
│   ├── research_service.py     # Main research orchestrator
│   ├── keyword_analyzer.py     # AI-powered keyword analysis
│   ├── competitor_analyzer.py  # Competitor intelligence
│   └── content_angle_generator.py # Content angle discovery
├── outline/                    # Outline generation
│   ├── __init__.py
│   ├── outline_service.py      # Main outline orchestrator
│   ├── outline_generator.py    # AI-powered outline generation
│   ├── outline_optimizer.py    # Outline optimization
│   └── section_enhancer.py     # Section enhancement
├── content/                    # Content generation (TODO)
└── optimization/               # SEO & optimization (TODO)

🏗️ Architecture Overview

Core Module (core/)

  • BlogWriterService: Main orchestrator that coordinates all blog writing functionality
  • Provides a unified interface for research, outline generation, and content creation
  • Delegates to specialized modules for specific functionality

Research Module (research/)

  • ResearchService: Orchestrates comprehensive research using Exa neural search (currently Exa-only for testing)
  • KeywordAnalyzer: AI-powered keyword analysis and extraction
  • CompetitorAnalyzer: Competitor intelligence and market analysis
  • ContentAngleGenerator: Strategic content angle discovery

Outline Module (outline/)

  • OutlineService: Manages outline generation, refinement, and optimization
  • OutlineGenerator: AI-powered outline generation from research data
  • OutlineOptimizer: Optimizes outlines for flow, SEO, and engagement
  • SectionEnhancer: Enhances individual sections using AI

🔄 Service Flow

  1. Research Phase: ResearchServiceKeywordAnalyzer + CompetitorAnalyzer + ContentAngleGenerator
  2. Outline Phase: OutlineServiceOutlineGeneratorOutlineOptimizer
  3. Content Phase: (TODO) Content generation and optimization
  4. Publishing Phase: (TODO) Platform integration and publishing

🚀 Usage

from services.blog_writer.blog_service import BlogWriterService

# Initialize the service
service = BlogWriterService()

# Research a topic
research_result = await service.research(research_request)

# Generate outline from research
outline_result = await service.generate_outline(outline_request)

# Enhance sections
enhanced_section = await service.enhance_section_with_ai(section, "SEO optimization")

🎯 Key Benefits

1. Modularity

  • Each module has a single responsibility
  • Easy to test, maintain, and extend
  • Clear separation of concerns

2. Reusability

  • Components can be used independently
  • Easy to swap implementations
  • Shared utilities and helpers

3. Scalability

  • New features can be added as separate modules
  • Existing modules can be enhanced without affecting others
  • Clear interfaces between modules

4. Maintainability

  • Smaller, focused files are easier to understand
  • Changes are isolated to specific modules
  • Clear dependency relationships

🔧 Development Guidelines

Adding New Features

  1. Identify the appropriate module (research, outline, content, optimization)
  2. Create new classes following the existing patterns
  3. Update the module's __init__.py to export new classes
  4. Add methods to the appropriate service orchestrator
  5. Update the main BlogWriterService if needed

Testing

  • Each module should have its own test suite
  • Mock external dependencies (AI providers, APIs)
  • Test both success and failure scenarios
  • Maintain high test coverage

Error Handling

  • Use graceful degradation with fallbacks
  • Log errors appropriately
  • Return meaningful error messages to users
  • Don't let one module's failure break the entire flow

📈 Future Enhancements

Content Module (content/)

  • Section content generation
  • Content optimization and refinement
  • Multi-format output (HTML, Markdown, etc.)

Optimization Module (optimization/)

  • SEO analysis and recommendations
  • Readability optimization
  • Performance metrics and analytics

Integration Module (integration/)

  • Platform-specific adapters (WordPress, Wix, etc.)
  • Publishing workflows
  • Content management system integration

🔍 Code Quality

  • Type Hints: All methods use proper type annotations
  • Documentation: Comprehensive docstrings for all public methods
  • Error Handling: Graceful failure with meaningful error messages
  • Logging: Structured logging with appropriate levels
  • Testing: Unit tests for all major functionality
  • Performance: Efficient caching and API usage

📝 Migration Notes

The original blog_service.py has been refactored into this modular structure:

  • Research functionalityresearch/ module
  • Outline generationoutline/ module
  • Service orchestrationcore/ module
  • Main entry pointblog_service.py (now just imports from core)

All existing API endpoints continue to work without changes due to the maintained interface in BlogWriterService.