Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


FastAPI Secure Product Inventory Backend πŸ”πŸ“¦

FastAPI Python Redis PostgreSQL React Render Vercel

A production-oriented backend system built with FastAPI, demonstrating secure authentication, Redis-based security controls, rate limiting, and scalable API architecture.

This project focuses primarily on backend engineering, while the React frontend acts as a client interface used to interact with backend APIs.

The goal of this project is to demonstrate skills relevant for Backend / Python Developer roles, including authentication systems, Redis-based security mechanisms, modular backend architecture, and API development.


🌐 Live Demo

Full Application (Frontend + Backend)

[https://fastapi-jwt-redis-backend.vercel.app]

Backend API

[https://fastapi-jwt-redis-backend.onrender.com]

API Documentation

[https://fastapi-jwt-redis-backend.onrender.com/docs]


πŸ“Έ Application Screenshots

Inventory Dashboard

Inventory Dashboard

Users can browse products and add items to their cart.


API Documentation

Swagger Docs

Interactive API documentation generated by FastAPI.


πŸ— System Architecture

graph TD

User --> ReactFrontend
ReactFrontend --> FastAPIBackend
FastAPIBackend --> PostgreSQL
FastAPIBackend --> Redis

ReactFrontend[React Frontend - Vercel]
FastAPIBackend[FastAPI Backend - Render]
PostgreSQL[PostgreSQL Database - Neon]
Redis[Redis Security Layer - Upstash]
Loading

πŸš€ Backend Capabilities Demonstrated

This project demonstrates real-world backend engineering patterns:

β€’ Secure authentication system β€’ Redis security layers β€’ Rate limiting implementation β€’ Structured logging β€’ Modular API architecture β€’ Token lifecycle management β€’ Background task scheduling β€’ Role-based access control


πŸ”‘ Authentication & Security

The application uses a JWT-based authentication system.

Security features

β€’ Access Token authentication β€’ Refresh Token rotation β€’ Refresh token reuse detection β€’ HTTPOnly refresh token cookies β€’ Secure logout using Redis blacklist β€’ Secure logout using refresh token revokation β€’ Password hashing using bcrypt


πŸ”„ Authentication Flow

sequenceDiagram

User->>Frontend: Login Request
Frontend->>Backend: /auth/login
Backend->>Database: Verify credentials
Backend->>Frontend: Access Token + Refresh Token

Frontend->>Backend: API Request (Authorization Header)

Backend->>Frontend: Response

Frontend->>Backend: /auth/refresh
Backend->>Frontend: New Access Token
Loading

πŸ›‘ Authorization (RBAC)

Role-Based Access Control is implemented.

Roles:

Admin
User

Admin permissions:

β€’ Create products β€’ Update products β€’ Delete products

User permissions:

β€’ View products β€’ Add products to cart β€’ Manage cart items

Authorization is enforced through FastAPI dependencies.


⚑ Redis Security Layer

Redis is used to implement backend security features.

Redis enables:

β€’ Login rate limiting β€’ Refresh token rate limiting β€’ Token blacklist for logout β€’ Fast token validation β€’ Automatic expiration using TTL

Example Redis keys:

login:ip:<ip>
login:email:<email>
refresh:ip:<ip>
refresh:user_id:<id>
blacklist:<access_token>

🚫 Rate Limiting

Login and Refresh tokens attempts are limited to prevent brute-force attacks per Email or Username and IP address.

Example configuration:

Maximum attempts: 5
Window: 60 seconds

Exceeded attempts return:

HTTP 429 Too Many Requests

Redis automatically resets counters using TTL.


πŸ“Š Structured Logging

Security events are logged using structured logs.

Example logs:

event=login_attempt ip=103.x.x.x email=user@email.com
event=login_rate_limit_exceeded ip=103.x.x.x
event=login_success user_id=3

This demonstrates observability practices used in production systems.


πŸ›’ Cart Management

Each user maintains an isolated cart.

Features:

β€’ Add products to cart β€’ Update cart quantity β€’ Remove cart items β€’ User-specific cart isolation

Example endpoints:

POST /cart/add
PATCH /cart/update/{product_id}
DELETE /cart/remove/{product_id}

πŸ“¦ Product Inventory

Admin-controlled inventory system.

Endpoints:

GET /products
POST /products
PATCH /products/{id}
DELETE /products/{id}

Users can browse products and add them to their cart.


⏱ Background Task System

Background tasks are implemented using APScheduler.

Tasks include:

Cleanup of expired tokens
Maintenance of revoked tokens

This demonstrates backend background job scheduling.


πŸ›  Tech Stack

Backend

FastAPI Python PostgreSQL SQLAlchemy ORM Redis APScheduler python-jose (JWT) passlib / bcrypt


Frontend (Client Interface)

React Vite Axios

The frontend is intentionally lightweight because the primary focus of this project is backend architecture.


☁ Infrastructure

Database: Neon PostgreSQL Redis: Upstash Backend Deployment: Render Frontend Deployment: Vercel


πŸ“ Project Structure

fastapi-jwt-redis-backend
β”‚
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ core
β”‚   β”‚   β”œβ”€β”€ auth.py
β”‚   β”‚   β”œβ”€β”€ security.py
β”‚   β”‚   β”œβ”€β”€ redis_client.py
β”‚   β”‚   └── rate_limiter.py
β”‚   β”‚
β”‚   β”œβ”€β”€ db
β”‚   β”‚   β”œβ”€β”€ database.py
β”‚   β”‚   └── database_models.py
β”‚   β”‚
β”‚   β”œβ”€β”€ routers
β”‚   β”‚   β”œβ”€β”€ auth_router.py
β”‚   β”‚   β”œβ”€β”€ product_router.py
β”‚   β”‚   └── cart_router.py
β”‚   β”‚
β”‚   β”œβ”€β”€ services
β”‚   β”‚   β”œβ”€β”€ cart_service.py
β”‚   β”‚   └── product_service.py
β”‚   β”‚
β”‚   β”œβ”€β”€ tasks
β”‚   β”‚   └── token_cleanup.py
β”‚   β”‚
β”‚   └── main.py
β”‚
β”œβ”€β”€ frontend
β”‚   β”œβ”€β”€ src
β”‚   β”œβ”€β”€ pages
β”‚   β”œβ”€β”€ components
β”‚   └── api
β”‚
β”œβ”€β”€ screenshots
β”‚
β”œβ”€β”€ requirements.txt
└── README.md

βš™ Local Development Setup

Clone repository

git clone https://github.com/AkashAkuthota/fastapi-jwt-redis-backend.git
cd fastapi-jwt-redis-backend

Create virtual environment

python -m venv myenv
source myenv/bin/activate

Install dependencies

pip install -r requirements.txt

Environment variables

Create .env

SECRET_KEY=your_secret_key

DATABASE_URL=your_postgres_connection

REDIS_HOST=your_upstash_host
REDIS_PORT=6379
REDIS_PASSWORD=your_upstash_password

ACCESS_TOKEN_EXPIRE_MINUTES=30
REFRESH_TOKEN_EXPIRE_DAYS=7

Run backend

uvicorn app.main:app --reload

API docs:

http://localhost:8000/docs

Run frontend

cd frontend
npm install
npm run dev

🎯 Project Goal

This project demonstrates backend engineering practices such as:

β€’ Secure authentication systems β€’ Redis-based security controls β€’ Rate limiting implementation β€’ Scalable API design β€’ Modular backend architecture β€’ Token lifecycle management β€’ Background job scheduling β€’ Observability through structured logging

The project is designed to showcase capabilities relevant for Backend / Python Developer roles, while also demonstrating the ability to integrate backend APIs with a frontend client.


πŸ‘¨β€πŸ’» Author

Akash Akuthota

GitHub [https://github.com/AkashAkuthota]

LinkedIn [https://www.linkedin.com/in/akashakuthota/]


⭐ If you found this useful

Consider giving the repository a star ⭐ on GitHub.


About

Secure FastAPI backend implementing JWT access/refresh rotation, Redis-based rate limiting & token blacklisting, RBAC, and production-ready authentication architecture with PostgreSQL.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages