Files
lego-instructions-manager/README.md

255 lines
6.1 KiB
Markdown

# 🧱 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](https://img.shields.io/badge/Python-3.8+-blue.svg)
![Flask](https://img.shields.io/badge/Flask-3.0.0-green.svg)
![License](https://img.shields.io/badge/license-MIT-orange.svg)
## ✨ 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**
```bash
git clone https://gitea.hideawaygaming.com.au/jessikitty/lego-instructions-manager.git
cd lego-instructions-manager
```
2. **Create a virtual environment**
```bash
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**
```bash
pip install -r requirements.txt
```
4. **Configure environment variables**
```bash
cp .env.example .env
# Edit .env with your settings
```
5. **Initialize the database**
```bash
flask --app run.py init-db
```
6. **Create an admin user**
```bash
flask --app run.py create-admin
```
7. **Run the application**
```bash
python run.py
```
The application will be available at `http://localhost:5000`
## ⚙️ Configuration
### Environment Variables
Edit the `.env` file with your configuration:
```env
# 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](https://brickset.com)
2. Request an API key at [Brickset API Documentation](https://brickset.com/article/52664/api-version-3-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:
```bash
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
```bash
pytest tests/
```
### Flask Shell
Access the Flask shell for debugging:
```bash
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:
```env
DATABASE_URL=postgresql://user:password@localhost/lego_db
```
2. **Set a strong SECRET_KEY**:
```python
import secrets
print(secrets.token_hex(32))
```
3. **Use gunicorn** for production:
```bash
gunicorn -w 4 -b 0.0.0.0:8000 "run:app"
```
4. **Set up nginx** as a reverse proxy
5. **Enable HTTPS** with Let's Encrypt
6. **Regular backups** of database and uploads folder
## 🐛 Troubleshooting
### Database Errors
```bash
# Reset database
rm lego_instructions.db
flask --app run.py init-db
```
### File Upload Issues
```bash
# 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
- [Brickset](https://brickset.com) for the excellent LEGO database API
- [Bootstrap](https://getbootstrap.com) for the UI framework
- [Flask](https://flask.palletsprojects.com) for the web framework
---
**Built with ❤️ for LEGO enthusiasts**