Spaces:
Running
Running
Migration Guide - Old to New Structure
This document explains the changes from the old structure to the new organized structure.
Structure Changes
Old Structure
project/
βββ ai_client.py
βββ app.py
βββ config.py
βββ html_generator.py
βββ screenshot_playwright.py
βββ system_prompt.txt
βββ template.html
βββ templates/index.html
βββ generated_html/
βββ screenshots/
New Structure
project/
βββ app.py # Updated with new imports
βββ start.py # New startup script
βββ requirements.txt # Updated dependencies
βββ README.md # Comprehensive documentation
βββ SETUP_GUIDE.md # Setup instructions
β
βββ src/ # NEW: Source code organization
β βββ core/
β β βββ ai_client.py # Moved from root
β β βββ html_generator.py # Moved from root
β βββ screenshot_engines/
β βββ playwright_engine.py # Renamed from screenshot_playwright.py
β
βββ config/ # NEW: Configuration folder
β βββ config.py # Moved from root
β βββ config.example.py # NEW: Template
β βββ system_prompt.txt # Moved from root
β βββ template.html # Moved from root
β
βββ static/ # Frontend assets
β βββ css/styles.css # NEW: Extracted from index.html
β βββ js/
β β βββ navigation.js # NEW: Extracted from index.html
β β βββ text-to-image.js # NEW: Extracted from index.html
β β βββ html-to-image.js # NEW: Extracted from index.html
β β βββ utils.js # NEW: Extracted from index.html
β βββ README.md # NEW: Frontend documentation
β
βββ templates/
β βββ index.html # Refactored to use external CSS/JS
β
βββ output/ # NEW: Organized output
βββ screenshots/ # Replaces root screenshots/
βββ html/ # Replaces generated_html/
Import Changes
Old Imports (app.py)
from ai_client import get_ai_response
from html_generator import generate_html
from screenshot_playwright import take_screenshot_playwright
New Imports (app.py)
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
from core.ai_client import get_ai_response
from core.html_generator import generate_html
from screenshot_engines.playwright_engine import take_screenshot_playwright
Path Changes
Output Folders
Old:
OUTPUT_FOLDER = "screenshots"
HTML_FOLDER = "generated_html"
New:
OUTPUT_FOLDER = "output/screenshots"
HTML_FOLDER = "output/html"
Config Files
Old:
# Direct import
import config
New:
# Import from config folder
sys.path.insert(0, 'config')
import config
Migration Steps
Automatic Migration (Recommended)
The new structure is already set up. Old files remain for reference.
Manual Migration (If needed)
Move core files:
mkdir -p src/core cp ai_client.py src/core/ cp html_generator.py src/core/Move screenshot engine:
mkdir -p src/screenshot_engines cp screenshot_playwright.py src/screenshot_engines/playwright_engine.pyMove config files:
mkdir -p config cp config.py config/ cp system_prompt.txt config/ cp template.html config/Create output folders:
mkdir -p output/screenshots output/htmlUpdate app.py with new imports (already done)
Test the application:
python start.py
Backward Compatibility
Old Files
Old files are kept in the root for reference:
ai_client.py(usesrc/core/ai_client.py)html_generator.py(usesrc/core/html_generator.py)screenshot_playwright.py(usesrc/screenshot_engines/playwright_engine.py)config.py(useconfig/config.py)
Old Output Folders
Old output folders still work:
screenshots/(useoutput/screenshots/)generated_html/(useoutput/html/)
You can safely delete old files after verifying the new structure works.
Benefits of New Structure
Organization
- β Clear separation of concerns
- β Modular code structure
- β Easy to navigate
Scalability
- β Easy to add new tools
- β Easy to add new screenshot engines
- β Easy to add new features
Maintainability
- β Easier to find files
- β Easier to update code
- β Easier to debug
Professional
- β Industry-standard structure
- β Better for collaboration
- β Better for version control
Cleanup (Optional)
After verifying everything works, you can remove old files:
# Remove old Python files (keep as backup first!)
# rm ai_client.py
# rm html_generator.py
# rm screenshot_playwright.py
# rm config.py
# rm system_prompt.txt
# rm template.html
# Remove old test files
rm test_*.py
rm check_*.py
rm list_models.py
rm main.py
rm css_template.txt
# Move old output (optional)
# mv screenshots/* output/screenshots/
# mv generated_html/* output/html/
# rmdir screenshots generated_html
Rollback (If needed)
If you need to go back to the old structure:
- The old files are still in the root directory
- Revert
app.pyto use old imports - Use old output folders
Testing Checklist
After migration, test:
- Server starts without errors
- Text to Image tool works
- HTML to Image tool works
- Screenshots are generated
- HTML files are saved
- Custom settings work
- Advanced settings work
- File serving works
Questions?
If you encounter issues:
- Check terminal for error messages
- Verify all files are in correct locations
- Check imports in
app.py - Review
SETUP_GUIDE.md