Skip to main content

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.

Python 3.8+ FastAPI Coverage >80% Code Style: Black PyPI

Stacked PR StructureTech StackTestingUsageAPICI/CD




🌟 Stacked PRs

This repo is structured into clearly defined Pull Requests:

  1. feat: add Task schema and in-memory task endpoints
  2. feat: integrate PostgreSQL with SQLAlchemy and Alembic
  3. feat: 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/hitesharora1997/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 main or develop branches
  • Pull Requests to main or develop
  • Manual dispatch

Pipeline Stages:

  1. Testing Matrix:

    • Python versions: 3.9, 3.10, 3.11
    • PostgreSQL integration testing
    • Code quality checks (Black, isort, flake8)
    • Test coverage reporting
  2. Security Scanning:

    • Bandit security linting
    • Safety vulnerability checking
    • Security report artifacts
  3. Build & Package:

    • Python package building
    • Package validation with twine
    • Build artifact uploads
  4. 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

  1. Clone and Setup:

    git clone https://github.com/hitesharora1997/stacking_pr.git
    cd stacking_pr
    make setup
    
  2. 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]"
    
  3. Run Tests:

    make test-cov
    
  4. Start Development Server:

    # Local development
    make run
    
    # Docker development
    make docker
    make migrate
    

Development Best Practices

  • Code Formatting: Run black app tests before committing
  • Import Sorting: Run isort app tests before committing
  • Linting: Run flake8 app to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stacking_pr-0.1.1.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stacking_pr-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file stacking_pr-0.1.1.tar.gz.

File metadata

  • Download URL: stacking_pr-0.1.1.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

Hashes for stacking_pr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d04bff4036dd9f8b25661220d4fa220be5236d6feea3a58b81930f44f28082f
MD5 836f2d5d1a49d4005d23a2b4a1698242
BLAKE2b-256 a77b69a0535acf8b3b55b341350855fa95b4902260b0ceac022daf8f1fb67c5f

See more details on using hashes here.

File details

Details for the file stacking_pr-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: stacking_pr-0.1.1-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

Hashes for stacking_pr-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9db0471b248c3e57940784631224c4b221dfe4494d110bb228d79fcfb543cb11
MD5 edd1978eb8b23e1f1a29b87568c3944e
BLAKE2b-256 7de5b3467272c96bf1f2da7f839ca2335e5955ae3c87f44f03647827724ee666

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page