A backend project for OTP-based authentication using FastAPI, Redis, Celery, and JWT. Built with scalability, modularity, and real-world patterns in mind.
- Register users with email OTP verification
- Login flow secured via access & refresh tokens
- Password hashing with bcrypt
- OTP sending using Celery + Redis in background
- Async SQLAlchemy + SQLite (swap with PostgreSQL easily)
- Clean folder structure and reusable components
- FastAPI (async web framework)
- Redis (task queue backend)
- Celery (background OTP sender)
- SQLite + SQLAlchemy (async)
- JWT for secure token handling
- Uvicorn as the ASGI server
- Passlib for password hashing
- Pydantic v2
- Clone the repository:
git clone https://github.com/jishnu70/FastAPI-OTP-Auth-Backend.git
-
Install dependencies
uv pip install
-
Set environment variables Create a
.env
file at root:DATABASE_URL=sqlite+aiosqlite:///./data.db SECRET_KEY=your-secret-key JWT_ALGORITHM=HS256 MAIL_ACCOUNT=[email protected] MAIL_PASSWORD=your-app-password
-
Run Redis
redis-server
-
Run Celery
celery -A app.background.celery_app worker --loglevel=info
-
Start the API
uv run app/main.py
app/
βββ authentication/ # Services & token logic
βββ background/ # Celery tasks & OTP logic
βββ dependencies/ # DI utils (e.g., current user)
βββ infrastructure/ # Redis client setup
βββ models/ # SQLAlchemy models
βββ routes/ # API routes
βββ schemas/ # Pydantic schemas
βββ config.py # App settings
βββ database.py # DB engine/session
βββ main.py # App entry point
- You can test this with Postman, Thunder Client, etc.
- Uses
uv
instead ofrequirements.txt
for dependency management - OTPs expire in 5 minutes (set in Redis)
- Designed for learning, but with production-aligned structure
- Add rate limiting
- Add resend OTP flow
- Add password reset via OTP
- Add logging in JSON format
Built with learning, intention, and a focus on writing clean backend code. Think of it as your backend backpack β light, useful, and ready for the road ahead.