Development Workflow
Recommended day-to-day workflow for the backend.
Local Development Setup
Initial Setup
- Clone the repository
- Set up your Python environment (Python 3.10+)
- Install dependencies with UV:
uv pip install -e . - Set up your local PostgreSQL database
- Configure your
.envfile with local settings
Running the Application
Start the FastAPI development server:
The --reload flag enables auto-reloading when code changes are detected.
Code Style and Quality
Formatting
The project uses ruff for code formatting. Format your code using:
This ensures consistent code style across the project.
Linting
Run the linter to check for code quality issues:
Fix automatically fixable issues:
Type Checking
Type hints are encouraged for readability and IDE support; enforcement is not strict everywhere.
Database Changes
Creating Models
When creating new database models:
- Define your model in
app/models/ - Import it in
app/models/__init__.py - Create corresponding Pydantic schemas in
app/schemas/ - Add CRUD operations in
app/crud.py
Database Migrations
For schema changes:
- Make changes to your SQLAlchemy models
- Generate a migration:
alembic revision --autogenerate -m "Description of changes" - Review the generated migration file in
alembic/versions/ - Apply the migration:
alembic upgrade head
API Development
Creating New Endpoints
When adding new API endpoints:
- Create or modify a router file in
app/routers/ - Define your endpoint functions with appropriate decorators
- Import and register your router in
app/routers/__init__.py - Add necessary schemas, models, and CRUD operations
Testing Endpoints
Test your endpoints using:
- FastAPI’s interactive documentation (Swagger UI) at
/docs - API client tools like Postman or Insomnia
- Automated tests (see Testing section)
Background Tasks
Creating Celery Tasks
When creating new background tasks:
- Define your task in an appropriate file in
tasks/ - Import and register your task in
tasks/__init__.py - Add any necessary database models and schemas
Testing Tasks
Test your tasks using:
- Direct invocation in development mode
- Running a local Celery worker:
celery -A rhesis.backend.worker worker --loglevel=info
Testing
Writing Tests
Tests are located in the tests/backend/ directory. When writing tests:
- Create test files that mirror the structure of the code being tested
- Use pytest fixtures for common setup and teardown
- Use a test database (configured in
conftest.py)
Running Tests
Run the test suite:
Run specific tests:
Debugging
Logging
Use the application’s logging system for debugging:
Interactive Debugging
For interactive debugging:
- Add breakpoints using
breakpoint()or your IDE’s debugging tools - Run the application in debug mode through your IDE
- Use
print()statements judiciously for quick debugging
Git Workflow
Use short-lived branches from the integration branch your team uses, conventional commit messages (present tense, ~50-char subject), PRs with description and linked issues, and green tests before merge.
Deployment
See Deployment. Before release: tests green, dependency review if you bumped packages, env vars and migrations checked.
Troubleshooting
Typical issues: bad SQLALCHEMY_DATABASE_URL or Postgres not running, missing .env keys, wrong PYTHONPATH/venv, or JWT/auth misconfiguration. Check logs and Environment configuration.