5.3 KiB
5.3 KiB
Migration Plan: Alwrity (AI-Writer) to Enterprise-Ready Architecture
1. Background & Motivation
Alwrity (AI-Writer) is currently an open-source, Streamlit-based project for AI-powered content creation, SEO, analytics, and more. To serve enterprise customers, we need to move to a scalable, secure, and maintainable architecture, reusing as much of the existing Python codebase as possible while replacing the UI and improving backend robustness.
2. Current State
- UI: Streamlit (great for prototyping, not for enterprise)
- Backend: Python modules for AI writing, SEO, analytics, chatbot, etc.
- Database: SQLite, ChromaDB, some service layers for Twitter and content
- AI/ML: Integrates with OpenAI, Gemini, and other providers
3. Design Directions & Tech Stack Recommendations
A. Frontend
- React (TypeScript) for scalable, maintainable UI
- UI Library: Material-UI (MUI) or Ant Design
- State/Data: React Query, Context API or Redux Toolkit
B. Backend
- FastAPI (Python): async, high-performance, easy to wrap existing modules
- Task Queue: Celery + Redis for background jobs (if needed)
C. Database & Storage
- PostgreSQL for structured data
- Redis for caching and task queue
- Vector DB: Pinecone, Weaviate, or Qdrant for semantic search (if needed)
- Blob Storage: AWS S3 or Azure Blob for files
D. AI/ML Integration
- Reuse existing Python modules
- Serve custom models via FastAPI endpoints
E. Authentication
- Auth0 or Keycloak for OAuth2/SSO, or FastAPI JWT for MVP
F. DevOps
- Docker for containerization
- GitHub Actions for CI/CD
- (Optional) Kubernetes for orchestration
G. Security & Compliance
- SSO, RBAC, audit logs, encryption, GDPR/SOC2 readiness
4. Migration Plan: Step-by-Step
Phase 1: Preparation
- Audit codebase for reusable business logic
- Separate UI code from backend logic
- Set up monorepo or separate repos for backend (Python/FastAPI) and frontend (React)
Phase 2: Backend API Layer
- Scaffold FastAPI app
- Wrap existing Python modules as API endpoints (content generation, SEO, analytics, etc.)
- Add authentication (JWT for MVP, SSO for production)
- Write unit/integration tests
Phase 3: Frontend Migration
- Scaffold React app (TypeScript)
- Set up routing, authentication, dashboard layout
- For each Streamlit feature, create a React page/component
- Use MUI/Ant Design for UI
- Fetch data from FastAPI using React Query
Phase 4: Feature Parity & Enhancements
- Migrate all features, one by one, to new stack
- Use Celery + Redis for long-running jobs
- Add UI/UX improvements (loading, error handling, feedback)
Phase 5: Productionization
- Dockerize frontend and backend
- Set up CI/CD with GitHub Actions
- Add logging, monitoring (Sentry, Prometheus, Grafana)
- Harden security (HTTPS, CORS, secure cookies, etc.)
Phase 6: Launch & Iterate
- Deploy to cloud
- Gather user feedback and iterate
5. Prioritized Modules for Migration
Best-fit modules to start with (already decoupled from UI):
- AI Writers (lib/ai_writers/): Blog, news, social, email, story, YouTube script writers
- SEO Tools (lib/ai_seo_tools/): Keyword analyzer, meta generator, content gap, enterprise SEO, content calendar
- Website Analyzer (lib/utils/website_analyzer/): Performance, SEO, content quality analysis
- Analytics/Performance (lib/content_performance_predictor/): Content analytics and prediction
- Chatbot Core (lib/chatbot_custom/core/): Workflow engine, tool router, intent analyzer, context manager
- Database Services (lib/database/): Twitter and content management service layers
- AI Marketing Tools (lib/ai_marketing_tools/ai_backlinker/): Backlinking and marketing automation
Modules to avoid for now:
- Streamlit UI scripts and thin wrappers
6. Summary Table
| Layer | Stack/Tooling | Why? |
|---|---|---|
| Frontend | React + TypeScript + MUI | Modern, scalable, huge ecosystem |
| Backend | FastAPI (Python) | Async, high-perf, easy to wrap old code |
| Auth | FastAPI JWT/Auth0/Keycloak | Secure, enterprise-ready |
| DB | PostgreSQL, Redis | Reliable, scalable, Python-friendly |
| AI/ML | Existing Python modules | Maximum code reuse |
| Task Queue | Celery + Redis | For background/async jobs |
| DevOps | Docker, GitHub Actions | Easy deployment, automation |
7. Next Steps
- Start with AI Writers and SEO Tools: wrap as FastAPI endpoints
- Gradually add Website Analyzer, Analytics, and Chatbot features
- Leave UI and Streamlit code aside; focus on modules that don’t depend on Streamlit
- Build React frontend to consume new API endpoints
8. Optional: Sample FastAPI Endpoint (for reference)
from fastapi import FastAPI
from lib.ai_writers.blog_writer import generate_blog_post
app = FastAPI()
@app.post("/generate-blog/")
def generate_blog(data: BlogRequest):
return generate_blog_post(data.topic, data.keywords)
This document should be updated as the migration progresses and new architectural decisions are made.