# ALwrity It - Content Strategy Analysis Customization Feature ## ๐ŸŽฏ **Feature Overview** **ALwrity It** allows users to customize AI-generated analysis components when they don't meet expectations. Users can manually edit data or use AI to regenerate with custom prompts, maintaining context from other analysis components. ### **Key Benefits:** - โœ… **User Control**: Full control over AI-generated analysis - โœ… **Flexibility**: Manual editing or AI-powered regeneration - โœ… **Context Awareness**: AI considers other analysis components - โœ… **Structured Output**: Consistent JSON responses via Gemini - โœ… **Version History**: Track and revert changes - โœ… **Preview Mode**: Compare original vs modified analysis ## ๐Ÿ—๏ธ **Technical Architecture** ### **File Structure** ``` frontend/src/components/ContentPlanningDashboard/components/StrategyIntelligence/ โ”œโ”€โ”€ components/ โ”‚ โ”œโ”€โ”€ content_strategy_alwrityit/ โ”‚ โ”‚ โ”œโ”€โ”€ ALwrityItButton.tsx # Main button component โ”‚ โ”‚ โ”œโ”€โ”€ ALwrityItModal.tsx # Main modal container โ”‚ โ”‚ โ”œโ”€โ”€ ManualEditForm.tsx # Manual editing form โ”‚ โ”‚ โ”œโ”€โ”€ AIEditForm.tsx # AI prompt form โ”‚ โ”‚ โ”œโ”€โ”€ QuickRegenerateForm.tsx # Quick AI regeneration โ”‚ โ”‚ โ”œโ”€โ”€ AnalysisPreview.tsx # Preview changes โ”‚ โ”‚ โ”œโ”€โ”€ ModeSelector.tsx # Mode selection interface โ”‚ โ”‚ โ”œโ”€โ”€ VersionHistory.tsx # Version tracking โ”‚ โ”‚ โ””โ”€โ”€ TemplateLibrary.tsx # Saved templates โ”‚ โ””โ”€โ”€ [existing analysis cards] โ”œโ”€โ”€ hooks/ โ”‚ โ”œโ”€โ”€ content_strategy_alwrityit/ โ”‚ โ”‚ โ”œโ”€โ”€ useALwrityIt.ts # Main hook for ALwrity It functionality โ”‚ โ”‚ โ”œโ”€โ”€ useAnalysisRegeneration.ts # AI regeneration logic โ”‚ โ”‚ โ”œโ”€โ”€ useManualEditing.ts # Manual editing logic โ”‚ โ”‚ โ””โ”€โ”€ useVersionHistory.ts # Version management โ”œโ”€โ”€ types/ โ”‚ โ”œโ”€โ”€ content_strategy_alwrityit/ โ”‚ โ”‚ โ”œโ”€โ”€ alwrityIt.types.ts # TypeScript types โ”‚ โ”‚ โ”œโ”€โ”€ analysisSchemas.ts # JSON schemas for each component โ”‚ โ”‚ โ””โ”€โ”€ promptTemplates.ts # AI prompt templates โ”œโ”€โ”€ utils/ โ”‚ โ”œโ”€โ”€ content_strategy_alwrityit/ โ”‚ โ”‚ โ”œโ”€โ”€ analysisTransformers.ts # Data transformation utilities โ”‚ โ”‚ โ”œโ”€โ”€ promptGenerators.ts # AI prompt generation โ”‚ โ”‚ โ”œโ”€โ”€ schemaValidators.ts # JSON schema validation โ”‚ โ”‚ โ””โ”€โ”€ versionManager.ts # Version control utilities โ””โ”€โ”€ providers/ โ””โ”€โ”€ ALwrityItProvider.tsx # Context provider for state management ``` ### **Backend Structure** ``` backend/api/content_planning/api/content_strategy/ โ”œโ”€โ”€ endpoints/ โ”‚ โ”œโ”€โ”€ alwrityit_endpoints.py # ALwrity It API endpoints โ”‚ โ””โ”€โ”€ [existing endpoints] โ”œโ”€โ”€ services/ โ”‚ โ”œโ”€โ”€ alwrityit_service.py # ALwrity It business logic โ”‚ โ”œโ”€โ”€ analysis_regeneration_service.py # AI regeneration service โ”‚ โ””โ”€โ”€ version_management_service.py # Version control service โ””โ”€โ”€ models/ โ”œโ”€โ”€ alwrityit_models.py # Database models for versions/templates โ””โ”€โ”€ [existing models] ``` ## ๐Ÿ“‹ **Implementation Phases** ### **Phase 1: Core Infrastructure (2-3 days)** #### **1.1 Backend API Endpoints** ```python # backend/api/content_planning/api/content_strategy/endpoints/alwrityit_endpoints.py @router.post("/regenerate-analysis-component") async def regenerate_analysis_component(request: RegenerateAnalysisRequest): """Regenerate specific analysis component with AI""" @router.post("/update-analysis-component-manual") async def update_analysis_component_manual(request: ManualUpdateRequest): """Update analysis component with manual edits""" @router.get("/analysis-component-schema/{component_type}") async def get_analysis_component_schema(component_type: str): """Get JSON schema for specific component type""" @router.get("/analysis-versions/{strategy_id}/{component_type}") async def get_analysis_versions(strategy_id: int, component_type: str): """Get version history for analysis component""" ``` #### **1.2 Frontend Core Components** ```typescript // ALwrityItButton.tsx const ALwrityItButton = ({ componentType, currentData, onUpdate }) => { return ( setModalOpen(true)} > ); }; ``` ### **Phase 2: Modal & Mode Selection (1-2 days)** #### **2.1 Main Modal Component** ```typescript // ALwrityItModal.tsx const ALwrityItModal = ({ open, onClose, componentType, currentData, onUpdate }) => { const [mode, setMode] = useState('manual'); return ( ALwrity It - {getComponentDisplayName(componentType)} {mode === 'manual' && ( )} {mode === 'ai' && ( )} {mode === 'regenerate' && ( )} ); }; ``` #### **2.2 Mode Selector Component** ```typescript // ModeSelector.tsx const ModeSelector = ({ mode, onModeChange }) => { const modes = [ { id: 'manual', title: 'Manual Edit', description: 'Edit analysis data manually', icon: , color: '#4caf50' }, { id: 'ai', title: 'AI Custom', description: 'Provide custom prompt for AI regeneration', icon: , color: '#667eea' }, { id: 'regenerate', title: 'Quick Regenerate', description: 'Regenerate with improved AI analysis', icon: , color: '#ff9800' } ]; return ( {modes.map((modeOption) => ( onModeChange(modeOption.id)}> {modeOption.icon} {modeOption.title} {modeOption.description} ))} ); }; ``` ### **Phase 3: Manual Editing Interface (1-2 days)** #### **3.1 Manual Edit Form** ```typescript // ManualEditForm.tsx const ManualEditForm = ({ componentType, currentData, onSave }) => { const schema = useAnalysisSchema(componentType); const [formData, setFormData] = useState(currentData); return ( Manual Edit - {getComponentDisplayName(componentType)} {Object.entries(schema.properties).map(([field, fieldSchema]) => ( setFormData(prev => ({ ...prev, [field]: value }))} /> ))} ); }; ``` ### **Phase 4: AI Integration (2-3 days)** #### **4.1 AI Edit Form** ```typescript // AIEditForm.tsx const AIEditForm = ({ componentType, currentData, onGenerate }) => { const [prompt, setPrompt] = useState(''); const [suggestedPrompts, setSuggestedPrompts] = useState([]); return ( AI Custom Regeneration setPrompt(e.target.value)} placeholder="Describe how you want to improve this analysis..." /> {suggestedPrompts.map((suggestion, index) => ( setPrompt(suggestion)} sx={{ mr: 1, mb: 1 }} /> ))} ); }; ``` #### **4.2 Backend AI Service** ```python # backend/services/alwrityit_service.py class ALwrityItService: async def regenerate_analysis_component( self, component_type: str, current_data: dict, user_prompt: str = None, context_data: dict = None ) -> dict: prompt = self._build_regeneration_prompt( component_type, current_data, user_prompt, context_data ) schema = self._get_component_schema(component_type) response = await self.gemini_provider.generate_structured_response( prompt=prompt, schema=schema, context={ "current_analysis": current_data, "other_components": context_data, "user_requirements": user_prompt, "component_type": component_type } ) return response ``` ### **Phase 5: Preview & Version Management (1-2 days)** #### **5.1 Analysis Preview Component** ```typescript // AnalysisPreview.tsx const AnalysisPreview = ({ original, modified, componentType, onApply, onRevert }) => { return ( Preview Changes Original Analysis Modified Analysis ); }; ``` ## ๐ŸŽจ **UI/UX Design Specifications** ### **Color Scheme** ```typescript const ALWRITY_IT_COLORS = { primary: '#667eea', secondary: '#764ba2', success: '#4caf50', warning: '#ff9800', error: '#f44336', background: { modal: 'linear-gradient(135deg, #0f0f23 0%, #1a1a2e 100%)', card: 'rgba(255, 255, 255, 0.05)', button: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)' } }; ``` ## ๐Ÿ”ง **Database Schema** ### **Version History Table** ```sql CREATE TABLE analysis_versions ( id SERIAL PRIMARY KEY, strategy_id INTEGER NOT NULL, component_type VARCHAR(50) NOT NULL, version_data JSONB NOT NULL, change_type VARCHAR(20) NOT NULL, user_prompt TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_by INTEGER, description TEXT ); ``` ### **Templates Table** ```sql CREATE TABLE analysis_templates ( id SERIAL PRIMARY KEY, name VARCHAR(100) NOT NULL, component_type VARCHAR(50) NOT NULL, template_data JSONB NOT NULL, description TEXT, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_by INTEGER, is_public BOOLEAN DEFAULT FALSE ); ``` ## ๐Ÿš€ **Implementation Timeline** ### **Week 1: Core Infrastructure** - **Day 1-2**: Backend API endpoints and database models - **Day 3-4**: Frontend component structure and basic modal - **Day 5**: Integration with existing analysis cards ### **Week 2: AI Integration** - **Day 1-2**: Gemini structured response integration - **Day 3-4**: Prompt engineering and context handling - **Day 5**: Testing and refinement ### **Week 3: Manual Editing & Polish** - **Day 1-2**: Dynamic form generation and validation - **Day 3-4**: Preview and comparison features - **Day 5**: Version history and advanced features ## ๐Ÿงช **Testing Strategy** ### **Unit Tests** - Component rendering and interactions - Form validation and data transformation - AI prompt generation and response parsing ### **Integration Tests** - API endpoint functionality - Database operations - AI service integration ### **End-to-End Tests** - Complete user workflows - Error handling scenarios - Performance testing ## ๐Ÿ“Š **Success Metrics** ### **User Engagement** - Number of ALwrity It button clicks per analysis - Most frequently modified components - User satisfaction with customization options ### **Technical Performance** - AI generation response times - Modal load times - Error rates and recovery ## ๐Ÿ”„ **Future Enhancements** ### **Phase 2 Features** 1. **Collaboration Tools**: Team comments and approvals 2. **Advanced AI**: Multi-step regeneration with user feedback 3. **Integration**: Connect with external data sources 4. **Analytics**: Detailed usage analytics and insights 5. **Templates**: Community template sharing --- **Next Steps**: 1. Review and approve this implementation plan 2. Set up development environment 3. Begin Phase 1 implementation 4. Create project milestones and tracking 5. Set up testing infrastructure