Here’s a clean and professional README.md for your FastAPI Auth Service repository:
A lightweight and secure authentication microservice built with FastAPI, PostgreSQL, and Docker. It provides essential authentication and authorization functionalities such as user registration, login, and JWT-based token management.
- 🔑 User Authentication — Secure login and registration with hashed passwords.
- 🛡️ JWT Tokens — Access and refresh token management for user sessions.
- 👥 Role-Based Access — Manage user roles and permissions (optional).
- 🧱 Database Integration — PostgreSQL with SQLAlchemy ORM and Alembic migrations.
- 🐳 Dockerized Setup — Easy deployment with Docker and docker-compose.
- 🧪 Scalable Structure — Modular, extensible, and production-ready architecture.
fastapi-auth-service/
│
├── app/
│ ├── api/ # Route handlers
│ ├── core/ # Configs and JWT utilities
│ ├── db/ # Database models and session setup
│ ├── schemas/ # Pydantic models
│ ├── services/ # Authentication and user logic
│ └── main.py # FastAPI entry point
│
├── alembic/ # Database migrations
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── README.md
git clone https://github.com/Sahith-03/fastapi-auth-service.git
cd fastapi-auth-serviceCreate a .env file:
DATABASE_URL=postgresql://postgres:password@db:5432/auth_db
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30docker-compose up --buildOpen your browser or API client:
http://localhost:8000/docs
| Method | Endpoint | Description |
|---|---|---|
| POST | /register |
Register a new user |
| POST | /login |
Authenticate and get token |
| GET | /users/me |
Get current user profile |
| POST | /refresh |
Refresh access token |
- Backend: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy + Alembic
- Auth: JWT (PyJWT / jose)
- Containerization: Docker, docker-compose
Run locally without Docker:
pip install -r requirements.txt
alembic upgrade head
uvicorn app.main:app --reload