Skip to content

Latest commit

 

History

History
120 lines (94 loc) · 2.2 KB

File metadata and controls

120 lines (94 loc) · 2.2 KB

Task Manager API

FastAPI backend for task management, with JWT authentication, refresh token rotation, logout/revoke mechanism, and PostgreSQL persistence.

What This Project Does

The API supports:

  • User registration and login
  • Authentication with access token + refresh token
  • Refresh token flow with:
    • database persistence
    • refresh token hashing
    • rotation (old refresh token becomes invalid)
    • expiry/revoked checks
  • Logout that revokes:
    • the refresh token
    • the current access token (via JTI blacklist)
  • Task CRUD per user
  • Task pagination/filtering

Tech Stack

  • Python
  • FastAPI
  • SQLAlchemy
  • PostgreSQL
  • Alembic
  • Passlib (argon2/bcrypt)
  • Pytest

Project Structure

app/
  api/         # Routers (auth, tasks)
  core/        # Config, JWT, security, exceptions, logging, rate limiter
  db/          # Session/base
  models/      # SQLAlchemy models
  schemas/     # Request/response schemas
  services/    # Business logic
alembic/       # Migrations
tests/         # Test suite

Local Setup (From Scratch)

  1. Move to the project directory:
cd task-manager-api
  1. Create and activate a virtual environment (if it does not exist):
python -m venv .venv

Windows PowerShell:

.\.venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create .env:
  • Copy .env.example to .env
  • Set DATABASE_URL and SECRET_KEY
  1. Apply migrations:
alembic upgrade head
  1. Start the API:
uvicorn app.main:app --reload

How to Use It

  • Swagger UI: http://127.0.0.1:8000/docs
  • Health check: http://127.0.0.1:8000/health

Suggested test flow:

  1. POST /auth/register
  2. POST /auth/login
  3. GET /auth/me with Bearer access token
  4. POST /auth/refresh
  5. POST /auth/logout
  6. Task endpoints: POST /tasks/, GET /tasks/, PUT /tasks/{id}, DELETE /tasks/{id}

How to Stop It

  • Stop server: CTRL + C
  • Deactivate virtual environment:
deactivate

Tests

run:

pytest -q

Docker (Optional, For Future Use)

The project already includes:

  • Dockerfile
  • docker-compose.yml
  • .dockerignore

When needed:

docker compose up --build