🧱 LEGO Instructions Manager

A Python web application for organizing and managing your LEGO instruction manuals. Upload PDFs and images, search by theme, set number, or year, and integrate with Brickset API for automatic set details.

LEGO Instructions Manager Flask License

Features

  • 📤 Upload & Organize: Upload instruction PDFs and images for your LEGO sets
  • 🔍 Advanced Search: Search and filter by theme, year, set number, or name
  • 🎨 Theme Organization: Organize sets by LEGO themes automatically
  • 🔗 Brickset Integration: Auto-populate set details using Brickset API v3
  • 👤 User Authentication: Secure login and user management
  • 📱 Responsive Design: Works on desktop, tablet, and mobile
  • 📊 Statistics Dashboard: View collection statistics and insights
  • 🖼️ Image Gallery: View instruction images in an organized gallery
  • 📄 PDF Support: View and download PDF instructions directly

🚀 Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)
  • Git

Installation

  1. Clone the repository
git clone https://gitea.hideawaygaming.com.au/jessikitty/lego-instructions-manager.git
cd lego-instructions-manager
  1. Create a virtual environment
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Configure environment variables
cp .env.example .env
# Edit .env with your settings
  1. Initialize the database
flask --app run.py init-db
  1. Create an admin user
flask --app run.py create-admin
  1. Run the application
python run.py

The application will be available at http://localhost:5000

⚙️ Configuration

Environment Variables

Edit the .env file with your configuration:

# Flask Configuration
SECRET_KEY=your-secret-key-here
FLASK_ENV=development

# Database (SQLite by default)
DATABASE_URL=sqlite:///lego_instructions.db

# Brickset API (optional but recommended)
BRICKSET_API_KEY=your-api-key
BRICKSET_USERNAME=your-username
BRICKSET_PASSWORD=your-password

# Upload Settings
MAX_CONTENT_LENGTH=52428800  # 50MB
SETS_PER_PAGE=20

Brickset API Setup

  1. Register for a free account at Brickset.com
  2. Request an API key at Brickset API Documentation
  3. Add your credentials to the .env file

The application works without Brickset, but you'll miss out on automatic set data population.

📖 Usage

Adding a Set

  1. Click "Add Set" in the navigation
  2. Enter set details manually OR search using Brickset
  3. Save the set to your collection

Uploading Instructions

  1. Navigate to a set's detail page
  2. Click "Upload Instructions"
  3. Select PDF or image files
  4. Files are automatically organized by set number

Searching & Filtering

  • Use the search bar to find sets by name or number
  • Filter by theme or year using the dropdowns
  • Sort by set number, name, theme, year, or newest first

🗂️ Project Structure

lego-instructions-manager/
├── app/
│   ├── models/           # Database models
│   ├── routes/           # Application routes/views
│   ├── services/         # Business logic (API, file handling)
│   ├── templates/        # HTML templates
│   └── static/           # CSS, JS, uploaded files
├── migrations/           # Database migrations
├── tests/                # Unit tests
├── requirements.txt      # Python dependencies
├── run.py               # Application entry point
└── README.md            # This file

🛠️ Development

Database Migrations

When you modify database models:

flask --app run.py db init       # Initialize migrations (first time only)
flask --app run.py db migrate -m "Description"  # Create migration
flask --app run.py db upgrade    # Apply migration

Running Tests

pytest tests/

Flask Shell

Access the Flask shell for debugging:

flask --app run.py shell

📊 Database Schema

User

  • id, username, email, password_hash, created_at

Set

  • id, set_number, set_name, theme, year_released, piece_count
  • brickset_id, image_url, user_id, created_at, updated_at

Instruction

  • id, set_id, file_type, file_path, file_name, file_size
  • page_number, user_id, uploaded_at

🔒 Security Notes

  • Passwords are hashed using bcrypt
  • File uploads are validated and sanitized
  • User authentication required for all operations
  • CSRF protection enabled on all forms

🚢 Deployment

Production Considerations

  1. Use PostgreSQL instead of SQLite:
DATABASE_URL=postgresql://user:password@localhost/lego_db
  1. Set a strong SECRET_KEY:
import secrets
print(secrets.token_hex(32))
  1. Use gunicorn for production:
gunicorn -w 4 -b 0.0.0.0:8000 "run:app"
  1. Set up nginx as a reverse proxy
  2. Enable HTTPS with Let's Encrypt
  3. Regular backups of database and uploads folder

🐛 Troubleshooting

Database Errors

# Reset database
rm lego_instructions.db
flask --app run.py init-db

File Upload Issues

# Check permissions
chmod -R 755 app/static/uploads

Brickset Connection Issues

  • Verify API credentials in .env
  • Check Brickset API status
  • Review application logs

📝 License

This project is licensed under the MIT License.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📧 Support

For issues and questions:

  • Open an issue on Gitea
  • Check existing documentation
  • Review Brickset API docs

🙏 Acknowledgments


Built with ❤️ for LEGO enthusiasts

Description
No description provided
Readme 125 KiB
Languages
HTML 55.2%
Python 40.9%
Batchfile 3.1%
CSS 0.8%