# 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 (
);
};
```
#### **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