5.4 KiB
5.4 KiB
Wireframe Persistence System
This document explains the new wireframe persistence system that automatically saves and loads wireframes to prevent data loss on page refresh.
Overview
The wireframe persistence system consists of:
- PostgreSQL Database Schema - Stores wireframes, elements, and versions
- Backend API Endpoints - Handle CRUD operations for wireframes
- Frontend Auto-save - Automatically saves wireframes every 30 seconds
- Manual Save Controls - Manual save button and keyboard shortcuts
Database Schema
Tables Created
-
wireframes- Main wireframe metadataid- Unique identifieruser_id- Reference to userproject_id- Optional project referencename- Wireframe namedescription- Wireframe descriptiondevice_type- mobile/tablet/desktopdimensions- Width and heightmetadata- Additional data (prompt, generation settings)is_active- Soft delete flag
-
wireframe_elements- Individual shapes/elementsid- Element identifierwireframe_id- Reference to wireframeelement_type- Type of element (shape, text, image, group)element_data- Complete TLDraw element dataposition- X, Y coordinatessize- Width and heightstyle- Color, stroke width, fillparent_id- For grouped elementsz_index- Layering order
-
wireframe_versions- Version controlid- Version identifierwireframe_id- Reference to wireframeversion_number- Sequential version numberversion_name- Human-readable version namesnapshot_data- Complete wireframe state at versioncreated_by- User who created version
Setup Instructions
1. Database Setup
# Install PostgreSQL dependencies
cd backend
pip install -r requirements.txt
# Copy and configure environment variables
cp env.example .env
# Edit .env with your database credentials
# Run database setup script
python setup_database.py
2. Environment Variables
Create a .env file in the backend/ directory:
# Claude API Configuration
CLAUDE_API_KEY=your-claude-api-key-here
# Flask Configuration
FLASK_ENV=development
PORT=5000
# Database Configuration
DB_HOST=localhost
DB_NAME=tech4biz_wireframes
DB_USER=postgres
DB_PASSWORD=your-database-password
DB_PORT=5432
3. Start Backend
cd backend
python app.py
API Endpoints
Save Wireframe
POST /api/wireframes
Content-Type: application/json
{
"wireframe": {
"name": "Wireframe Name",
"description": "Description",
"device_type": "desktop",
"dimensions": {"width": 1440, "height": 1024},
"metadata": {"prompt": "User prompt"}
},
"elements": [...],
"user_id": "user-uuid",
"project_id": "project-uuid"
}
Get Wireframe
GET /api/wireframes/{wireframe_id}
Update Wireframe
PUT /api/wireframes/{wireframe_id}
Content-Type: application/json
{
"name": "Updated Name",
"description": "Updated Description",
"elements": [...],
"user_id": "user-uuid"
}
Delete Wireframe
DELETE /api/wireframes/{wireframe_id}
Get User Wireframes
GET /api/wireframes/user/{user_id}
Frontend Features
Auto-save
- Wireframes are automatically saved every 30 seconds
- Auto-save can be toggled on/off
- Last save time is displayed
Manual Save
- Manual save button in top-right corner
- Keyboard shortcut:
Ctrl+S(orCmd+Son Mac)
Save Status
- Green indicator shows last save time
- Auto-save toggle checkbox
- Manual save button
Usage
Creating Wireframes
- Generate wireframe using AI prompt
- Wireframe is automatically saved to database
- Continue editing - changes are auto-saved
Loading Wireframes
- Wireframes are automatically loaded on page refresh
- Use API endpoints to load specific wireframes
- Version history is maintained
Keyboard Shortcuts
Ctrl+S- Save wireframeCtrl+K- Trigger prompt input (planned)Ctrl+Delete- Clear canvas
Data Flow
- User creates/edits wireframe → TLDraw editor
- Auto-save triggers → Every 30 seconds
- Data serialized → Convert TLDraw shapes to database format
- API call → Send to backend
- Database storage → Save to PostgreSQL
- Version created → New version entry for tracking
Benefits
- No data loss on page refresh
- Automatic backup every 30 seconds
- Version control for wireframe changes
- User isolation - each user sees only their wireframes
- Project organization - wireframes can be grouped by project
- Scalable storage - PostgreSQL handles large wireframes efficiently
Troubleshooting
Database Connection Issues
- Check PostgreSQL is running
- Verify database credentials in
.env - Ensure database
tech4biz_wireframesexists
Auto-save Not Working
- Check browser console for errors
- Verify backend is running on correct port
- Check network tab for failed API calls
Wireframes Not Loading
- Check if wireframe exists in database
- Verify user_id matches
- Check API endpoint responses
Future Enhancements
- Real-time collaboration - Multiple users editing same wireframe
- Export formats - PNG, PDF, HTML export
- Template library - Reusable wireframe components
- Advanced versioning - Branch and merge wireframes
- Search and filtering - Find wireframes by content or metadata