Development Setup¶
Set up a local development environment for FRacker.
Prerequisites¶
- Python 3.10 or higher
- MySQL 8.0+ or MariaDB 10.5+
- Redis 6.0+
- Git
Local Development Setup¶
1. Clone Repository¶
2. Create Virtual Environment¶
3. Install Dependencies¶
4. Set Up Database¶
Create a MySQL database:
CREATE DATABASE finance_tracker_dev;
CREATE USER 'finance_user'@'localhost' IDENTIFIED BY 'dev_password';
GRANT ALL PRIVILEGES ON finance_tracker_dev.* TO 'finance_user'@'localhost';
FLUSH PRIVILEGES;
5. Configure Environment¶
Create .env file:
FLASK_CONFIG=config.config.DevelopmentConfig
SECRET_KEY=dev-secret-key-change-in-production
DB_USER=finance_user
DB_PASSWORD=dev_password
DB_HOST=localhost
DB_PORT=3306
DB_NAME=finance_tracker_dev
REDIS_URL=redis://localhost:6379
FLASK_DEBUG=True
6. Initialize Database¶
Run migrations:
Seed initial data:
7. Start Development Server¶
The application will be available at http://localhost:5002
VS Code Development Container¶
For a consistent development environment, use the included Dev Container:
Prerequisites¶
Setup¶
- Open the project in VS Code
- Press
F1and select Dev Containers: Reopen in Container - Wait for the container to build and start
- The development environment is ready to use!
The Dev Container includes: - Python 3.11 - MySQL 8.0 - Redis 6.2 - All Python dependencies pre-installed - Database pre-configured
Running Tests¶
Run All Tests¶
Run with Coverage¶
View coverage report:
open htmlcov/index.html # macOS
xdg-open htmlcov/index.html # Linux
start htmlcov/index.html # Windows
Run Specific Tests¶
# Run a specific test file
pytest tests/routes/test_auth.py
# Run tests matching a pattern
pytest -k "test_login"
# Run a specific test class
pytest tests/services/test_auth.py::TestAuthService
Code Quality¶
Linting¶
Run flake8 to check code style:
Configuration in .flake8:
- Max line length: 200
- Excludes: migrations, venv, pycache
Format Code¶
The project follows PEP 8 style guidelines. Consider using:
Database Migrations¶
Create a New Migration¶
After modifying models:
Apply Migrations¶
Rollback Migration¶
Project Structure¶
finance_tracker/
├── app/ # Main application package
│ ├── __init__.py # App factory
│ ├── models/ # SQLAlchemy models
│ ├── routes/ # Flask blueprints
│ ├── services/ # Business logic
│ ├── forms/ # WTForms
│ ├── templates/ # Jinja2 templates
│ └── static/ # CSS, JS, images
├── config/ # Configuration classes
├── migrations/ # Alembic migrations
├── tests/ # Test suite
├── run.py # Development entry point
└── requirements.txt # Python dependencies
Common Development Tasks¶
Reset Database¶
Add a New Route¶
- Create route file in
app/routes/ - Define blueprint and routes
- Register blueprint in
app/__init__.py - Add tests in
tests/routes/
Add a New Model¶
- Create model in
app/models/ - Import in
app/models/__init__.py - Create migration:
flask db migrate - Apply migration:
flask db upgrade - Add tests in
tests/models/
Debug in VS Code¶
Add breakpoints and use the included launch configuration:
Press F5 or use Run → Start Debugging
Useful Flask Commands¶
# List all routes
flask routes
# Open Flask shell
flask shell
# Run custom CLI command
flask seed-db
Environment Variables¶
| Variable | Development Default | Description |
|---|---|---|
FLASK_CONFIG |
DevelopmentConfig |
Configuration class |
FLASK_DEBUG |
True |
Enable debug mode |
DB_HOST |
localhost |
Database host |
DB_PORT |
3306 |
Database port |
REDIS_URL |
redis://localhost:6379 |
Redis connection |
Troubleshooting¶
Port Already in Use¶
Change the port in run.py:
Database Connection Error¶
Ensure MySQL is running:
Redis Connection Error¶
Ensure Redis is running:
Next Steps¶
- Read the Architecture Guide
- Review Contributing Guidelines
- Check Code Style Guide