Thank you for your interest in contributing! This document provides guidelines and instructions for contributing to this project.
- Docker Desktop (Windows, macOS, or Linux)
- Git
- Basic knowledge of Python, FastAPI, and MongoDB/DocumentDB
-
Clone the repository
git clone https://github.com/documentdb/fastapi-documentdb-demo.git cd fastapi-documentdb-demo -
Create environment file
copy .env.example .env # Windows # or cp .env.example .env # Linux/macOS
-
Start services
docker-compose up -d
-
Load sample data (optional)
docker-compose exec backend python scripts/load_sample_data.py
Start all services:
docker-compose up -dView logs:
docker-compose logs -f backendStop services:
docker-compose down- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
- DocumentDB: localhost:27017 (user:
docdb_user, password:docdb_password)
- Make changes to the code
- Changes are automatically reloaded (hot reload enabled)
- Test your changes using the interactive docs or automated tests
- Run tests before committing
fastapi-vscode/
├── backend/
│ ├── app/
│ │ ├── core/ # Configuration and database
│ │ ├── models/ # Beanie document models
│ │ ├── schemas/ # Pydantic schemas for API
│ │ ├── routers/ # API route handlers
│ │ └── main.py # FastAPI application
│ ├── tests/ # Pytest test files
│ ├── Dockerfile
│ └── requirements.txt
├── scripts/ # Utility scripts
├── docker-compose.yml
├── .env.example
└── README.md
- Models (
backend/app/models/): Beanie Document models representing MongoDB collections - Schemas (
backend/app/schemas/): Pydantic models for request/response validation - Routers (
backend/app/routers/): FastAPI route handlers with business logic - Tests (
backend/tests/): Pytest test files
We follow PEP 8 with some modifications:
- Line length: 100 characters
- Use type hints for function parameters and return values
- Use docstrings for all public functions and classes
Format code with Black and isort:
docker-compose exec backend black backend/app backend/tests
docker-compose exec backend isort backend/app backend/testsCheck formatting:
docker-compose exec backend black --check backend/app backend/tests
docker-compose exec backend isort --check-only backend/app backend/testsRun mypy for type checking:
docker-compose exec backend mypy backend/app- Files: lowercase with underscores (
product_service.py) - Classes: PascalCase (
ProductService) - Functions: lowercase with underscores (
get_product_by_id) - Constants: UPPERCASE with underscores (
MAX_PAGE_SIZE) - API endpoints: kebab-case (
/api/v1/products/by-category)
Run all tests:
docker-compose exec backend pytestRun tests with coverage:
docker-compose exec backend pytest --cov=backend/app --cov-report=term-missingRun specific test file:
docker-compose exec backend pytest backend/tests/test_products.pyRun specific test:
docker-compose exec backend pytest backend/tests/test_products.py::TestProductEndpoints::test_create_product- Place tests in
backend/tests/ - Name test files
test_*.py - Use fixtures from
conftest.py - Write clear test names that describe what is being tested
- Use AAA pattern: Arrange, Act, Assert
Example test:
async def test_create_product(client: AsyncClient):
"""Test creating a new product."""
# Arrange
product_data = {
"name": "Test Product",
"price": 99.99,
"sku": "TEST-001",
"category": "Test",
}
# Act
response = await client.post("/api/v1/products", json=product_data)
# Assert
assert response.status_code == 201
assert response.json()["name"] == product_data["name"]Maintain at least 80% code coverage. Check coverage report:
docker-compose exec backend pytest --cov=backend/app --cov-report=htmlOpen htmlcov/index.html in a browser to view detailed coverage.
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
- Write code following the coding standards
- Add tests for new functionality
- Update documentation as needed
-
Test your changes
docker-compose exec backend pytest docker-compose exec backend black --check backend/app backend/tests docker-compose exec backend isort --check-only backend/app backend/tests
-
Commit your changes
git add . git commit -m "Add feature: description of your changes"
-
Push to your fork
git push origin feature/your-feature-name
-
Create a Pull Request
- Go to GitHub and create a PR from your branch
- Fill in the PR template with details about your changes
- Link any related issues
Write clear commit messages:
- Use present tense ("Add feature" not "Added feature")
- First line: brief description (50 chars or less)
- Optional: detailed description after blank line
- Reference issues/PRs when relevant
Examples:
Add product search functionality
Implements search by name and description with case-insensitive
regex matching. Includes tests and updates to documentation.
Fixes #123
- All PRs require review before merging
- Address reviewer feedback promptly
- Keep PRs focused and reasonably sized
- Update your PR based on feedback
- FastAPI Documentation
- Beanie Documentation
- DocumentDB Documentation
- Pydantic Documentation
- Pytest Documentation
If you have questions or need help:
- Check existing issues on GitHub
- Review the project README and documentation
- Ask in discussions or create a new issue
Thank you for contributing! 🎉