Magento CMS Sync
May 31, 2025 ยท View on GitHub
A powerful web-based tool for synchronizing CMS content (blocks and pages) between multiple Magento 2 instances. Built with FastAPI (Python) backend and React (TypeScript) frontend.
Features
- ๐ Bi-directional Sync: Compare and sync CMS blocks and pages between Magento instances
- ๐ Visual Comparison: Side-by-side diff view with syntax highlighting
- ๐ฏ Selective Sync: Choose specific items to sync with granular control
- ๐ Real-time Dashboard: Monitor sync operations with live statistics
- ๐ Advanced Filtering: Filter by status, type, date range, and more
- ๐ Comprehensive History: Track all sync operations with detailed logs
- ๐ Secure API Integration: Connect to Magento instances using REST API tokens
- ๐ High Performance: Asynchronous operations with background task processing

Quick Start with Docker
# Clone the repository
git clone https://github.com/yourusername/magento-cms-sync.git
cd magento-cms-sync
# Start with Docker Compose
docker-compose up -d
# Access the application
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# API Docs: http://localhost:8000/docs
Manual Installation
Prerequisites
- Python 3.11+
- Node.js 18+
- npm or yarn
Backend Setup
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run database migrations
alembic upgrade head
# Start the server
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Frontend Setup
cd frontend
# Install dependencies
npm install
# Start the development server
npm start
Configuration
Backend Environment Variables
Create a .env file in the backend directory:
# Database
DATABASE_URL=sqlite:///./cmssync.db
# Security
SECRET_KEY=your-secret-key-here
# CORS Origins (comma-separated)
CORS_ORIGINS=http://localhost:3000,http://localhost:3001
# Logging
LOG_LEVEL=INFO
Frontend Environment Variables
Create a .env file in the frontend directory:
# API URL
REACT_APP_API_URL=http://localhost:8000
# Port (optional)
PORT=3000
Usage Guide
1. Add Magento Instances
- Navigate to the "Instances" page
- Click "Add Instance"
- Enter:
- Instance name
- Magento base URL (e.g., https://your-store.com)
- REST API Integration token
- Test the connection and save
2. Refresh Data
- Click the refresh icons to pull latest CMS content
- Data is cached locally for better performance
- Refresh on-demand when needed
3. Compare Content
- Navigate to "Compare Blocks" or "Compare Pages"
- Select source and destination instances
- Click "Compare" to see differences
- Use filters and search to find specific content
4. Sync Content
Individual Sync
- Click the "View Diff" button on any item
- Review the changes in the visual diff viewer
- Click "Push to Destination" to sync that item

Bulk Sync
- Select multiple items using checkboxes
- Click "Sync X items"
- Review the preview
- Confirm to execute the sync
5. Monitor Progress
- View active syncs in real-time on the Sync page
- Check sync history with detailed logs
- Export history to CSV for reporting
API Documentation
The backend provides a comprehensive REST API. Access the interactive documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Key Endpoints
GET /api/instances/- List all instancesPOST /api/instances/- Add new instancePOST /api/compare/blocks- Compare CMS blocksPOST /api/compare/pages- Compare CMS pagesPOST /api/sync/blocks- Sync CMS blocksPOST /api/sync/pages- Sync CMS pagesGET /api/history/- Get sync historyGET /api/history/statistics- Get sync statistics
Architecture
Backend (FastAPI)
- Asynchronous Python web framework
- SQLAlchemy for database ORM
- Pydantic for data validation
- Background tasks for sync operations
- JSON file storage for data caching
Frontend (React)
- TypeScript for type safety
- Material-UI component library
- Zustand for state management
- Axios for API communication
- React Router for navigation
Data Storage Strategy
- Configuration stored in SQLite database
- CMS content cached as JSON files
- Located in
backend/data/instances/{instance_id}/ - On-demand refresh for optimal performance
Development
Project Structure
magento-cms-sync/
โโโ backend/
โ โโโ api/ # API endpoints
โ โโโ models/ # Database models
โ โโโ services/ # Business logic
โ โโโ integrations/ # Magento API client
โ โโโ data/ # JSON data storage
โ โโโ main.py # FastAPI application
โโโ frontend/
โ โโโ src/
โ โ โโโ components/ # Reusable components
โ โ โโโ pages/ # Page components
โ โ โโโ services/ # API services
โ โ โโโ store/ # State management
โ โ โโโ types/ # TypeScript types
โ โโโ public/ # Static assets
โโโ docker-compose.yml # Docker configuration
โโโ start-dev.sh # Development startup script
Running Tests
# Backend tests
cd backend
pytest
# Frontend tests
cd frontend
npm test
Code Quality
# Backend
black . # Format code
flake8 # Lint code
mypy . # Type checking
# Frontend
npm run lint # ESLint
npm run format # Prettier
Troubleshooting
Common Issues
-
Connection refused to Magento API
- Verify the Magento URL is accessible
- Check if the API token has correct permissions
- Ensure Magento REST API is enabled
-
CORS errors in browser
- Update CORS_ORIGINS in backend .env
- Restart the backend server
-
Database errors
- Delete cmssync.db and restart backend
- Run migrations:
alembic upgrade head
-
Sync failures
- Check Magento API token permissions
- Verify network connectivity
- Review error logs in sync history
Security Considerations
- API tokens are stored encrypted in the database
- HTTPS recommended for production
- CORS configured for specific origins
- No direct database access from frontend
- All operations logged for audit trail
Performance Tips
- Use data refresh strategically - not needed for every comparison
- Filter large datasets before syncing
- Monitor sync history for failed operations
- Clean up old sync logs periodically
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with FastAPI
- UI powered by React and Material-UI
- Magento integration via REST API