Legacy Modules & Migration
Relevant source files
The following files were used as context for generating this wiki page:
- backend/services/CONTENT_PLANNING_MODULARITY_PLAN.md
- backend/README_LINKEDIN_MIGRATION.md
- backend/api/content_planning/services/content_strategy/IMPLEMENTATION_STATUS.md
- ToBeMigrated/chatbot_custom/README.md
- backend/api/content_planning/tests/README.md
- ToBeMigrated/ai_writers/ai_blog_faqs_writer/README.md
- ToBeMigrated/ai_writers/ai_outline_writer/README.md
The "Legacy Modules & Migration" initiative represents a comprehensive effort to transition ALwrity from a monolithic, Streamlit-based prototype into a modular, enterprise-ready FastAPI backend architecture. The primary objective is to reorganize organically grown services—specifically content planning, AI writing, and chatbot interactions—into a structured system that supports scalability, reusability, and maintainability.
This process involves moving files from the ToBeMigrated/ directory into the backend/ services layer, breaking down monolithic files exceeding 1000 lines into focused modules, and establishing a robust testing foundation to ensure 100% feature preservation during the transition.
Sources: backend/services/CONTENT_PLANNING_MODULARITY_PLAN.md, backend/README_LINKEDIN_MIGRATION.md, backend/api/content_planning/tests/README.md
Migration Strategy & Framework
The migration follows a phased approach to ensure system stability. It begins with the establishment of core infrastructure, followed by the modularization of specific services such as the Content Gap Analyzer and LinkedIn Content Generation.
Phase-Based Migration Flow
The following diagram illustrates the six-week core migration cycle used for content planning and general service modularization.
Technical Objectives for Refactoring
The migration targets specific architectural improvements across all legacy modules:
- Modular Architecture: Moving from single-file scripts to nested package structures (e.g.,
backend/services/content_planning/core/). - Dependency Management: Centralizing scattered dependencies into shared utilities.
- Standardized Error Handling: Implementing consistent try/except patterns with fallback mechanisms.
- Performance Optimization: Reducing memory usage by 20% and optimizing database queries by 25%.
Sources: backend/services/CONTENT_PLANNING_MODULARITY_PLAN.md:11-20, 606-615
Core Service Migrations
Several key modules have either completed or are currently undergoing migration from the Streamlit ToBeMigrated/ source to the FastAPI backend.
LinkedIn Content Generation
Successfully migrated from ToBeMigrated/ai_writers/linkedin_writer/ to a new modular structure in the backend/ router and service layer.
| Feature | Legacy Status (Streamlit) | Migrated Status (FastAPI) |
|---|---|---|
| Architecture | Monolithic app | Modular RESTful service |
| Concurrency | Synchronous | Async/await support |
| Validation | Minimal manual check | Pydantic model enforcement |
| Monitoring | None | Database-backed analytics |
Sources: backend/README_LINKEDIN_MIGRATION.md:10-50, 105-130
Content Strategy & Planning
The transition of content strategy involves breaking down large files like content_planning_service.py (505 lines) and ai_analytics_service.py (974 lines) into a twelve-module system.
Legacy Writing Modules (Pending Migration)
Legacy writers currently reside in ToBeMigrated/ and utilize specialized configurations that must be mapped to the new service interfaces.
AI Blog Outline & FAQ Generators
These modules feature complex data structures such as OutlineConfig and FAQConfig to manage content depth and research levels.
- Outline Generator: Supports multiple "Content Depths" (Basic, Intermediate, Advanced, Expert) and integrated image generation engines (DALL-E 3, Gemini-AI).
- FAQ Generator: Utilizes three-tiered research depth:
- Basic: Google Search.
- Comprehensive: Tavily AI.
- Expert: Metaphor AI.
Sources: ToBeMigrated/ai_writers/ai_outline_writer/README.md:10-40, ToBeMigrated/ai_writers/ai_blog_faqs_writer/README.md:15-30, 100-115
Chatbot Transformation
The migration of the chatbot system involves moving from a "Basic RAG" implementation to an "Intelligent workflow-driven assistant."
Intent Analysis & Tool Routing
The enhanced version implements a routing logic that analyzes user queries to select the appropriate ALwrity backend tool.
Testing Foundation for Migration
To prevent regressions during refactoring, a "Testing Foundation" has been established. This ensures that the refactored FastAPI endpoints produce identical results to the legacy Streamlit outputs.
Validation Scripts
functionality_test.py: Establishes a baseline by testing all existing CRUD operations and AI generation endpoints.before_after_test.py: Automated comparison that loads baseline JSON data and compares it against the responses from the refactored API.- Performance Baseline: Sets a response time threshold of 0.5 seconds for all migrated endpoints.
Sources: backend/api/content_planning/tests/README.md:15-50, 120-130
Success Metrics for Migrated Code
Migration is considered successful only when it meets the following KPIs:
- File Size: Reduction from 1000+ lines to <500 lines per file.
- Coverage: Achieve 90%+ unit test coverage.
- Duplication: 60% reduction in code duplication through shared utility extraction.
- Consistency: Identical API response structures before and after migration.
Sources: backend/services/CONTENT_PLANNING_MODULARITY_PLAN.md:600-610, backend/api/content_planning/tests/README.md:165-175
Summary
The migration of legacy modules is a critical evolution for ALwrity, transforming its core components—LinkedIn generation, content strategy, and specialized writing tools—into a modular FastAPI ecosystem. By utilizing a phased approach and a strict testing foundation, the project ensures that legacy logic is preserved while gaining the benefits of async performance, standardized error handling, and scalable service interfaces.