Production-grade FastAPI backend with JWT authentication, PostgreSQL database, Alembic migrations, and Docker support.
- 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
- Python 3.11+
- PostgreSQL 14+
- Docker and Docker Compose (optional)
- Clone the repository:
git clone https://github.com/akalmaliky-spec/task-management-api.git
cd task-management-api- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\\Scripts\\activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your configuration- Run database migrations:
alembic upgrade head- Start the development server:
uvicorn app.main:app --reloadAPI will be available at http://localhost:8000
API documentation: http://localhost:8000/docs
Run with Docker Compose:
docker-compose up -dThis starts:
- FastAPI application on port 8000
- PostgreSQL database on port 5432
- Redis (optional) on port 6379
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
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login and get access token
GET /api/v1/users/me- Get current user profilePATCH /api/v1/users/me- Update current user
GET /api/v1/tasks/- List all tasksPOST /api/v1/tasks/- Create new taskGET /api/v1/tasks/{id}- Get task by IDPATCH /api/v1/tasks/{id}- Update taskDELETE /api/v1/tasks/{id}- Delete task
make testOr with coverage:
pytest --cov=app --cov-report=htmlLint code:
make lintFormat code:
ruff format .Create new migration:
alembic revision --autogenerate -m "description"Apply migrations:
alembic upgrade headRollback migration:
alembic downgrade -1Environment 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
docker build -t task-management-api .
docker run -p 8000:8000 --env-file .env task-management-apiAPI includes health check endpoint:
curl http://localhost:8000/health- Passwords hashed with bcrypt
- JWT tokens with configurable expiration
- CORS configuration for frontend
- SQL injection protection via SQLAlchemy
- Input validation with Pydantic
Comprehensive test suite covering:
- Authentication flows
- CRUD operations
- Input validation
- Error handling
- Database transactions
Run tests:
pytest -v- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
MIT License - see LICENSE file for details.
- Issues: GitHub Issues
- Documentation: API Docs
- FastAPI - Modern Python web framework
- SQLAlchemy - SQL toolkit and ORM
- Alembic - Database migrations
- Pydantic - Data validation