Skip to content

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

License

Notifications You must be signed in to change notification settings

AchuAshwath/full-stack-fastapi-payment-template

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Full Stack FastAPI Payment Template

Test Coverage

A production-ready Full Stack FastAPI template with integrated Razorpay payment gateway, ready-to-use checkout pages, payment analytics, and complete payment flow management.

πŸš€ Bootstrap your monetized app in minutes - Everything you need for payments is already integrated!

✨ Features

πŸ’³ Complete Payment Integration

  • Razorpay Gateway Integration - One-time payments with secure signature verification
  • Webhook Handling - Real-time payment status updates
  • Payment Analytics Dashboard - Track payments, success rates, and revenue
  • Checkout UI - Beautiful, responsive checkout page with Razorpay modal
  • Payment History - Complete order and payment tracking in database

🎨 Modern Tech Stack

  • Backend: FastAPI + SQLModel + PostgreSQL
  • Frontend: React + TypeScript + Chakra UI
  • DevOps: Docker Compose with hot-reload
  • Testing: Pytest + Playwright E2E tests
  • Deployment: Production-ready with Traefik & HTTPS

πŸ” Security & Authentication

  • JWT authentication
  • Secure password hashing
  • Email-based password recovery
  • Role-based access control
  • Payment signature verification

πŸ“Έ Screenshots

Payment Checkout Dashboard

Payment Checkout

Complete payment dashboard with integrated checkout form and payment analytics. Users can make payments and view their payment history all in one place.

Razorpay Integration

Razorpay Integration

Seamless Razorpay checkout modal integration with secure payment processing.

Dashboard Features

View all dashboard screenshots

Login Dashboard Create User Items User Settings Dark Mode API Docs

πŸš€ Quick Start

Prerequisites

1. Clone the Repository

git clone https://github.com/yourusername/full-stack-fastapi-payment-template.git
cd full-stack-fastapi-payment-template

2. Configure Environment Variables

Copy .env and update the following:

# Security Keys (generate with: python -c "import secrets; print(secrets.token_urlsafe(32))")
SECRET_KEY=your-secret-key-here
POSTGRES_PASSWORD=your-db-password
FIRST_SUPERUSER_PASSWORD=admin-password

# Razorpay Payment Gateway
RAZORPAY_KEY_ID=rzp_test_xxxxxxxxxxxxx
RAZORPAY_KEY_SECRET=your-razorpay-key-secret
RAZORPAY_WEBHOOK_SECRET=your-webhook-secret  # For production webhooks

3. Start the Application

docker compose watch

This will:

  • Start all services (backend, frontend, database)
  • Run database migrations automatically
  • Enable hot-reload for development

4. Access the Application

5. Create Your First User

  1. Go to http://localhost:5173/signup
  2. Create an account
  3. Navigate to /checkout to test payments

πŸ’³ Razorpay Setup

Get Your API Keys

  1. Sign Up: Visit Razorpay Dashboard
  2. Get Test Keys (no KYC required):
    • Log in to Razorpay Dashboard
    • Go to Settings β†’ API Keys
    • Copy your Key ID (starts with rzp_test_) and Key Secret
  3. Add to .env:
    RAZORPAY_KEY_ID=rzp_test_your_key_id
    RAZORPAY_KEY_SECRET=your_key_secret

Test Payments

Use Razorpay test cards:

  • Success: 4111 1111 1111 1111 (any CVV, any future expiry)
  • Failure: 4000 0000 0000 0002
  • See Razorpay Test Cards for more options

Production Setup

  1. Complete KYC verification in Razorpay Dashboard
  2. Switch to Live Mode
  3. Generate Live API keys
  4. Update .env with live keys
  5. Configure webhooks (see backend/README.md)

πŸ“š Documentation

Core Documentation

Payment Integration

πŸ—οΈ Project Structure

.
β”œβ”€β”€ backend/              # FastAPI backend
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/         # API routes (including payments)
β”‚   β”‚   β”œβ”€β”€ models.py    # Database models (Order, Payment)
β”‚   β”‚   β”œβ”€β”€ crud.py      # Database operations
β”‚   β”‚   β”œβ”€β”€ services/    # Business logic (Razorpay service)
β”‚   β”‚   └── alembic/     # Database migrations
β”‚   └── README.md        # Backend documentation
β”œβ”€β”€ frontend/            # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   └── Payments/  # Payment UI components
β”‚   β”‚   β”œβ”€β”€ routes/       # Application routes
β”‚   β”‚   └── client/       # Auto-generated API client
β”‚   └── README.md        # Frontend documentation
β”œβ”€β”€ img/                 # Screenshots and images
β”œβ”€β”€ docker-compose.yml   # Docker services configuration
β”œβ”€β”€ development.md       # Development guide
└── deployment.md        # Deployment guide

🎯 What's Included

Backend Features

βœ… Payment API Endpoints

  • Create Razorpay orders
  • Verify payment signatures
  • Handle webhooks
  • List user orders
  • Get order details

βœ… Database Models

  • Order - Payment orders with Razorpay integration
  • Payment - Payment records linked to orders
  • Automatic migrations with Alembic

βœ… Services

  • Razorpay service for API interactions
  • Secure signature verification
  • Payment capture handling

Frontend Features

βœ… Payment Components

  • Checkout page with integrated dashboard
  • Payment success/failure pages
  • Payment analytics dashboard
  • Recent orders table

βœ… UI/UX

  • Modern blue theme
  • Responsive design
  • Sidebar navigation
  • Real-time payment updates

πŸ”„ Payment Flow

  1. User initiates payment β†’ Enters amount on /checkout page
  2. Backend creates order β†’ Saves to database, returns Razorpay order ID
  3. Razorpay modal opens β†’ User completes payment
  4. Payment verification β†’ Frontend sends payment details to backend
  5. Signature verification β†’ Backend verifies Razorpay signature
  6. Database update β†’ Order and payment records updated
  7. Success redirect β†’ User sees payment confirmation and analytics
  8. Webhook update β†’ Real-time status updates from Razorpay (optional)

πŸ§ͺ Testing

Run Backend Tests

docker compose exec backend bash scripts/test.sh

Run Frontend E2E Tests

docker compose exec playwright npm run test

πŸ“ Database Migrations

This project uses Alembic for database migrations. Migrations run automatically on startup.

Quick Commands:

# Check migration status
docker compose exec backend bash -c "cd /app && alembic current"

# Create new migration
docker compose exec backend bash -c "cd /app && alembic revision --autogenerate -m 'Description'"

# Apply migrations
docker compose exec backend bash -c "cd /app && alembic upgrade head"

For detailed migration guide, see backend/README.md.

πŸ› οΈ Development

Start Development Environment

docker compose watch

This enables:

  • Hot-reload for backend and frontend
  • Auto-regeneration of API client
  • Live migration application

Backend Development

See backend/README.md for:

  • Local development setup
  • Running tests
  • Creating migrations
  • Payment API details

Frontend Development

See frontend/README.md for:

  • Local development
  • Component structure
  • API client generation

🌐 API Documentation

Once running, access interactive API docs:

All payment endpoints are documented and can be tested directly from the Swagger UI.

πŸ“¦ What You Get

  • βœ… Complete payment integration (Razorpay)
  • βœ… User authentication & authorization
  • βœ… Admin dashboard
  • βœ… Payment analytics
  • βœ… Webhook handling
  • βœ… Database migrations
  • βœ… API documentation
  • βœ… E2E tests
  • βœ… Production deployment config
  • βœ… Docker Compose setup
  • βœ… CI/CD ready

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

This project is licensed under the MIT License.

πŸ™ Acknowledgments


Ready to accept payments? πŸš€ Clone this repo, add your Razorpay keys, and start processing payments in minutes!

About

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 60.8%
  • Python 33.1%
  • HTML 4.8%
  • Shell 0.6%
  • Dockerfile 0.5%
  • Mako 0.2%