Skip to content

About

Production-grade FastAPI backend with JWT auth, PostgreSQL, and Docker

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

15 Commits

Folders and files

Repository files navigation

Task Management API

CI Python 3.11+ FastAPI License: MIT

Production-grade FastAPI backend with JWT authentication, PostgreSQL database, Alembic migrations, and Docker support.

Features

  • FastAPI framework for high-performance async APIs
  • JWT Authentication with secure password hashing
  • PostgreSQL database with SQLAlchemy ORM
  • Alembic for database migrations
  • Docker and Docker Compose for containerization
  • Pydantic schemas for request/response validation
  • Comprehensive testing with pytest
  • CI/CD with GitHub Actions
  • Structured logging for production monitoring
  • CORS configuration for frontend integration

Quick Start

Prerequisites

  • Python 3.11+
  • PostgreSQL 14+
  • Docker and Docker Compose (optional)

Installation

  1. Clone the repository:
git clone https://github.com/akalmaliky-spec/task-management-api.git
cd task-management-api
  1. Create virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\\Scripts\\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your configuration
  1. Run database migrations:
alembic upgrade head
  1. Start the development server:
uvicorn app.main:app --reload

API will be available at http://localhost:8000

API documentation: http://localhost:8000/docs

Docker Setup

Run with Docker Compose:

docker-compose up -d

This starts:

  • FastAPI application on port 8000
  • PostgreSQL database on port 5432
  • Redis (optional) on port 6379

Project Structure

task-management-api/
├── app/
│   ├── api/                 # API routes
│   │   └── v1/
│   │       ├── auth.py      # Authentication endpoints
│   │       ├── users.py     # User management
│   │       └── tasks.py     # Task CRUD
│   ├── models/              # SQLAlchemy models
│   ├── schemas/             # Pydantic schemas
│   ├── core/                # Core utilities
│   ├── config.py            # Application configuration
│   ├── database.py          # Database setup
│   ├── security.py          # Security utilities
│   └── main.py              # FastAPI application
├── alembic/                 # Database migrations
├── tests/                   # Test suite
├── docker-compose.yml       # Docker Compose configuration
├── Dockerfile               # Docker image definition
└── requirements.txt         # Python dependencies

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register new user
  • POST /api/v1/auth/login - Login and get access token

Users

  • GET /api/v1/users/me - Get current user profile
  • PATCH /api/v1/users/me - Update current user

Tasks

  • GET /api/v1/tasks/ - List all tasks
  • POST /api/v1/tasks/ - Create new task
  • GET /api/v1/tasks/{id} - Get task by ID
  • PATCH /api/v1/tasks/{id} - Update task
  • DELETE /api/v1/tasks/{id} - Delete task

Development

Running Tests

make test

Or with coverage:

pytest --cov=app --cov-report=html

Code Quality

Lint code:

make lint

Format code:

ruff format .

Database Migrations

Create new migration:

alembic revision --autogenerate -m "description"

Apply migrations:

alembic upgrade head

Rollback migration:

alembic downgrade -1

Configuration

Environment variables (see .env.example):

SECRET_KEY=your-secret-key-here
DATABASE_URL=postgresql://user:password@localhost/dbname
REDIS_URL=redis://localhost:6379/0
ENVIRONMENT=development
DEBUG=True

Deployment

Docker Production

docker build -t task-management-api .
docker run -p 8000:8000 --env-file .env task-management-api

Health Check

API includes health check endpoint:

curl http://localhost:8000/health

Security

  • Passwords hashed with bcrypt
  • JWT tokens with configurable expiration
  • CORS configuration for frontend
  • SQL injection protection via SQLAlchemy
  • Input validation with Pydantic

Testing

Comprehensive test suite covering:

  • Authentication flows
  • CRUD operations
  • Input validation
  • Error handling
  • Database transactions

Run tests:

pytest -v

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

MIT License - see LICENSE file for details.

Support

Acknowledgments

About

Production-grade FastAPI backend with JWT auth, PostgreSQL, and Docker

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages