A FastAPI application for task management with database integration
Project description
Stacked PR FastAPI Task Tracker
A clean, professional-grade backend project built with FastAPI, Docker, PostgreSQL, and SQLAlchemy.
Built in a stacked PR workflow, step-by-step, from in-memory to production-ready DB logic.
Stacked PR Structure • Tech Stack • Testing • Usage • API • CI/CD
🌟 Stacked PRs
This repo is structured into clearly defined Pull Requests:
feat: add Task schema and in-memory task endpointsfeat: integrate PostgreSQL with SQLAlchemy and Alembicfeat: replace in-memory task store with PostgreSQL CRUD
Each PR builds cleanly on top of the previous, keeping history modular and understandable.
🚀 Tech Stack
- FastAPI: Web framework
- SQLAlchemy: ORM for PostgreSQL
- Alembic: Schema migrations
- Docker + Compose: Containerized dev environment
- PostgreSQL: Relational database
- Pytest: Testing framework with coverage
- GitHub Actions: CI/CD pipeline
- Black/isort/flake8: Code formatting and linting
📃 Project Structure
stacking_pr/
├── app/ # Main application package
│ ├── __init__.py
│ ├── main.py # FastAPI app and entrypoint
│ ├── db.py # Database engine/session
│ ├── dependencies.py # FastAPI dependencies
│ ├── api/ # API routers
│ │ └── task_router.py
│ ├── models/ # SQLAlchemy models
│ │ └── task.py
│ └── schemas/ # Pydantic schemas
│ └── task.py
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Shared test fixtures
│ ├── test_main.py # Main app tests
│ ├── api/ # API endpoint tests
│ ├── models/ # Model tests
│ ├── schemas/ # Schema validation tests
│ └── integration/ # Integration tests
├── alembic/ # Database migrations
├── .github/
│ └── workflows/ # CI/CD pipelines
├── alembic.ini # Alembic configuration
├── docker-compose.yml # Docker services
├── Dockerfile # App containerization
├── pyproject.toml # Project metadata & config
├── requirements.txt # Python dependencies
├── Makefile # Development commands
└── README.md # Project documentation
🚧 Usage
⚡ Run Locally
git clone https://github.com/yourname/stacking_pr.git
cd stacking_pr
# Build and run containers
make docker
# Run alembic migrations
make migrate
# Follow logs
make logs
Open browser:
http://localhost:8000/docs
To stop:
make docker-down
📊 API
Create a Task
POST /tasks
Content-Type: application/json
{
"id": 1,
"title": "Stacked PRs FTW!",
"is_completed": false
}
Get All Tasks
GET /tasks
🧪 Testing
Running Tests
# Install test dependencies
pip install -e ".[test,dev]"
# Run all tests
make test
# Run tests with coverage report
make test-cov
# Run specific test file
make test-file
# Run tests matching a pattern
make test-pattern
Test Structure
- Unit Tests: Individual component testing
- API Tests: FastAPI endpoint testing with TestClient
- Model Tests: SQLAlchemy model validation
- Schema Tests: Pydantic schema validation
- Integration Tests: End-to-end workflow testing
Coverage
Tests maintain 80% minimum coverage with HTML reports generated in htmlcov/.
📄 Makefile Commands
make setup # Create virtual environment and install dependencies
make install # Install requirements into venv
make run # Run FastAPI locally (development)
make test # Run pytest test suite
make test-cov # Run tests with coverage report
make test-file # Run specific test file
make test-pattern # Run tests matching a pattern
make docker # Start Docker containers
make docker-down # Stop and remove containers
make migrate # Run alembic migrations
make logs # Follow Docker logs
make clean # Delete venv + __pycache__
make help # Show all available commands
🚀 CI/CD Pipeline
GitHub Actions Workflow
The project includes a comprehensive CI/CD pipeline that runs on:
- Push to
mainordevelopbranches - Pull Requests to
mainordevelop - Manual dispatch
Pipeline Stages:
-
Testing Matrix:
- Python versions: 3.8, 3.9, 3.10, 3.11
- PostgreSQL integration testing
- Code quality checks (Black, isort, flake8)
- Test coverage reporting
-
Security Scanning:
- Bandit security linting
- Safety vulnerability checking
- Security report artifacts
-
Build & Package:
- Python package building
- Package validation with twine
- Build artifact uploads
-
Docker:
- Multi-stage Docker builds
- Container health testing
- Image validation
Code Quality Standards
- Code Formatting: Black (88 char line length)
- Import Sorting: isort (Black compatible)
- Linting: flake8 with complexity checks
- Test Coverage: Minimum 80% required
✅ License
This project is licensed under the MIT License.
💻 Development Workflow
Getting Started
-
Clone and Setup:
git clone https://github.com/yourname/stacking_pr.git cd stacking_pr make setup
-
Install Dependencies:
# Production dependencies pip install -e . # Development dependencies pip install -e ".[dev]" # Test dependencies pip install -e ".[test]" # All dependencies pip install -e ".[dev,test]"
-
Run Tests:
make test-cov -
Start Development Server:
# Local development make run # Docker development make docker make migrate
Development Best Practices
- Code Formatting: Run
black app testsbefore committing - Import Sorting: Run
isort app testsbefore committing - Linting: Run
flake8 appto check code quality - Testing: Maintain 80%+ test coverage
- Commits: Use conventional commit messages
Pre-commit Checklist
black app tests # Format code
isort app tests # Sort imports
flake8 app # Lint code
make test-cov # Run tests with coverage
🚀 Coming Soon
- 🌐 Deployment configurations (Render/Railway/Docker)
- 📊 Advanced monitoring and logging
- 🔐 Authentication and authorization
- 👁️ Optional frontend in React or HTML
- 📈 Performance optimization guides
Made with ❤️ by Hitesh Arora.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stacking_pr-0.1.0.tar.gz.
File metadata
- Download URL: stacking_pr-0.1.0.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
562f6482835cf6594530b99ab57721f33a3ba01bcc1e0f231b091edad9a044ce
|
|
| MD5 |
b120fb2d3b063fa029cf901c3d426847
|
|
| BLAKE2b-256 |
525db3b784f11763ecf8bda9e9ccea3d5de83c994cf92a7f8e34a0b3cf674f4c
|
File details
Details for the file stacking_pr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stacking_pr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffe42d30beb2a31dc14fd4f5d6a2faa6e41b97be4d97245f4f8b7bc278d9cc32
|
|
| MD5 |
79f6521d51fea0043b6c2e41dddeb30f
|
|
| BLAKE2b-256 |
89bffa50b0e149bd0eaccd5b1f0fabbb5f47f12e5de8b67b3cc76c1e47aa0d47
|