Skip to content

πŸ” OTP-based authentication backend with FastAPI, Celery, Redis, and JWT β€” built for learning, ready to extend.

Notifications You must be signed in to change notification settings

jishnu70/FastAPI-OTP-Auth-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FastAPI OTP Auth Backend πŸš€

A backend project for OTP-based authentication using FastAPI, Redis, Celery, and JWT. Built with scalability, modularity, and real-world patterns in mind.


✨ Features

  • 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

πŸ“¦ Stack

  • 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

πŸš€ Getting Started

  1. Clone the repository:
git clone https://github.com/jishnu70/FastAPI-OTP-Auth-Backend.git
  1. Install dependencies

    uv pip install
  2. 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
  3. Run Redis

    redis-server
  4. Run Celery

    celery -A app.background.celery_app worker --loglevel=info
  5. Start the API

    uv run app/main.py

πŸ“ Folder Structure

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

πŸ§ͺ Notes

  • You can test this with Postman, Thunder Client, etc.
  • Uses uv instead of requirements.txt for dependency management
  • OTPs expire in 5 minutes (set in Redis)
  • Designed for learning, but with production-aligned structure

πŸ“Œ Next Steps

  • 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.

About

πŸ” OTP-based authentication backend with FastAPI, Celery, Redis, and JWT β€” built for learning, ready to extend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages