Skip to main content
This guide outlines the recommended development workflow for the Definable backend project. Following these practices will help maintain code quality and ensure smooth collaboration.

Development Environment

Before starting development, ensure you have:
  1. Completed the installation process
  2. Set up your environment variables
  3. Installed pre-commit hooks with pre-commit install

Git Workflow

We follow a branch-based workflow to manage code changes:

Branching Strategy

  • Main Branch: Always contains stable, production-ready code
  • Dev Branch: All new features and bug fixes are merged in the dev branch then escalated further.
  • Feature Branches: For new features (feat/feature-name)
  • Bugfix Branches: For bug fixes (fix/issue-id)
  • Release Branches: For preparing releases (release/v1.2.3)

Branch Naming Convention

  • feat/short-description - For new features
  • fix/issue-id - For bug fixes
  • refactor/component-name - For code refactoring
  • docs/what-changed - For documentation updates

Code Change Process

1. Create a New Branch

2. Make Changes

Write your code following the projectโ€™s coding standards (enforced by Ruff and Mypy).

3. Run Tests Locally

4. Commit Changes

The pre-commit hooks will run Ruff for linting and Mypy for type checking. Fix any issues before proceeding.

5. Push Changes

6. Create a Pull Request

Create a pull request on GitHub with:
  • Clear title describing the change
  • Detailed description of what was changed and why
  • References to any related issues
  • Ensure the PR is directed to the dev branch for review.

7. Code Review

All pull requests require at least one review before merging into dev. Reviewers should check:
  • Code correctness
  • Test coverage
  • Adherence to project standards
  • Documentation

8. Merge

Once approved, the PR can be merged into the dev branch. After sufficient testing and validation, changes can be merged into master and then into the release branch.

Code Quality Standards

Style Guide

We use Ruff for linting with the following key rules:
  • 2-space indentation
  • 150 character line length
  • Python 3.10+ features allowed

Type Annotations

All code should use type annotations and pass Mypy checks:

Documentation

All modules, classes, and functions should have docstrings following Googleโ€™s style guide:

Adding New Components

Adding a New Service

  1. Create a new directory in src/services/[service_name]/
  2. Add the required files:
    • service.py - Main service implementation
    • schema.py - Pydantic models
Example service structure:

Adding a New Model

  1. Create a new file in src/models/ named [model_name]_model.py
  2. Define your SQLAlchemy model
  3. Update src/models/__init__.py to export your model
Example model:
  1. Create a migration:

Database Migrations

Creating Migrations

Debugging

Logging

Use the logger provided by the Acquire class:

FastAPI Debug Mode

For local development, use FastAPIโ€™s debug mode:
This enables auto-reload on code changes.

Deployment Pipeline

Our code follows this deployment pipeline:
1

Development

Local development and testing
2

Continuous Integration

Automated tests and checks run on GitHub Actions
3

Staging Deployment

Automatic deployment to the staging environment after merging into the dev branch.
4

Production Deployment

Manual approval and deployment to production

Troubleshooting

If pre-commit hooks are failing:
  • Check Ruff errors: ruff check src/
  • Check Mypy errors: mypy src/
  • Fix the issues before committing again
If you encounter migration errors:
  • Check for model conflicts or circular imports
  • Try recreating the migration with alembic revision --autogenerate -m "Fixed migration"
  • In worst case, you can reset: alembic downgrade base then alembic upgrade head
If you encounter new dependency issues:
  • Update Poetry: poetry update
  • Check for locked versions: poetry show -o
  • Add specific dependency: poetry add package-name
  • Update lock file: poetry lock --no-update

Best Practices

  1. Write tests first: Follow test-driven development when possible
  2. Keep services focused: Each service should have a single responsibility
  3. Use async properly: Ensure all I/O operations are async
  4. Handle exceptions: Always catch and handle exceptions appropriately
  5. Validate inputs: Use Pydantic models for data validation
  6. Document your code: Write clear docstrings and comments
  7. Review your own code: Do a self-review before requesting reviews
By following this development workflow, youโ€™ll contribute high-quality code to the Definable backend project while maintaining a smooth collaborative process.