Getting Started
Quick start guide for the FastAPI template with authentication, payments, and modern tooling
Overview
This FastAPI template eliminates months of boilerplate setup by providing a production-ready backend architecture. Built with modern Python practices, it includes everything you need to launch a robust web application: secure authentication, payment processing, background task management, and a clean, maintainable codebase.
Perfect for startups, MVPs, and enterprise applications that need to move fast without sacrificing code quality or security.
What's Included
🔐 Complete Authentication
JWT tokens, password hashing, email verification, password reset, and role-based access control
💳 Payment Processing
Stripe integration with webhooks, subscriptions, one-time payments, and customer management
📧 Email System
SMTP configuration, HTML templates, async sending, and transactional email support
🗄️ Database Layer
SQLAlchemy ORM, Alembic migrations, connection pooling, and async database operations
⚡ Background Tasks
Celery integration with Redis broker, task scheduling, monitoring, and error handling
🚀 Production Ready
Docker support, environment management, logging, monitoring, and deployment configs
Architecture Overview
The template follows a clean, modular architecture designed for scalability and maintainability:
Key Architecture Principles:
- Modular Design: Each feature (auth, payments, email) is self-contained with its own routes, models, and schemas
- Async-First: Built for high concurrency with async/await throughout the codebase
- Background Processing: Celery integration for heavy tasks like email sending and data processing
- Database Abstraction: SQLAlchemy ORM with proper connection pooling and transaction management
- Configuration Management: Environment-based settings with validation and type safety
- Testing Ready: Comprehensive test setup with fixtures and database isolation
Quick Setup
Prerequisites
Before you begin, ensure you have the following installed:
- Python 3.9+ - The template requires Python 3.9 or higher
- PostgreSQL - Database for production use
- Redis - For caching and Celery task queue
- Git - Version control
You can also use Docker to run the entire stack without installing dependencies individually.
Clone the Repository
Clone the template repository to your local machine:
git clone https://github.com/yourusername/fastlaunchapi_template.git
cd fastlaunchapi_template/backend
Configure Environment
Copy the sample environment file:
cp .env.sample .env
Update the .env
file with basic settings:
SECRET_KEY=TEST
DATABASE_URL=postgresql://postgres:postgres@192.168.178.50:5432/template-db # change to your database url
FRONTEND_URL=http://localhost:3000 # change to your frontend url
BACKEND_URL=http://localhost:8000
GOOGLE_CLIENT_ID=<YOUR_KEY>
GOOGLE_CLIENT_SECRET=<YOUR_KEY>
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/callback/google
STRIPE_PUBLIC_KEY=<YOUR_KEY>
STRIPE_SECRET_KEY=<YOUR_KEY>
WEBHOOK_SECRET=<YOUR_KEY>
OPENAI_API_KEY=<YOUR_KEY>
SENDGRID_API_KEY=<YOUR_KEY>
SUPPORT_EMAIL=support@yourcompany.com
FROM_EMAIL=noreply@yourcompany.com
COMPANY_NAME="Your Company Name"
Replace SECRET_KEY
with a secure random string.
Environment Setup
In the next step we will start all our docker containers. (postgresql, redis, celery, beat, pgadmin, redis, flower) Make sure the docker daemon is running on your machine.
# Build and start all services
docker-compose up
Install all python dependencies.
# Install dependencies
pip install -r requirements.txt
Setup Database
# Create migrations
alembic revision --autogenerate -m "Migration"
# Run migrations
alembic upgrade head
Start the Application
# Start the development server
fastapi dev
Verify Installation
Your FastAPI application should now be running! Visit these URLs to verify:
- API Documentation: http://localhost:8000/docs
- Alternative Docs: http://localhost:8000/redoc
- Health Check: http://localhost:8000/health
Core Components
Authentication System
Complete JWT-based authentication with enterprise-grade security features and user management capabilities.
Core Features:
- JWT token-based authentication with refresh tokens
- Secure password hashing using bcrypt
- Email verification and account activation
- Password reset with secure token generation
- Rate limiting can be easily installed
- OAuth2 compliance with FastAPI security
Payment Processing
Full-featured Stripe integration with webhook handling, subscription management, and secure payment processing.
Supported Features:
- One-time payments and payment intents
- Subscription management (create, update, cancel)
- Webhook endpoint handling and verification
- Customer management and billing profiles
- Payment method storage and management
- Invoice generation and management
- Proration and billing cycle handling
- Refund processing and dispute management
Email System
Comprehensive email infrastructure with template support, async processing, and transactional capabilities.
Email Features:
- HTML email templates with Jinja2 templating
- SENDGRID integration for transactional emails
- Async email sending with Celery background tasks
- Email verification and welcome sequences
- Password reset and security notifications
- Template management and customization
Database Layer
Production-ready database setup with SQLAlchemy ORM, migrations, and connection management.
Database Features:
- SQLAlchemy ORM with async support
- Alembic migrations for schema management
- Connection pooling and optimization
- Database session management
- Model relationships and constraints
- Query optimization and indexing
- Transaction handling and rollback support
Background Task Management
Celery integration with Redis broker for scalable background processing and task management.
Task Management:
- Celery worker configuration with Redis broker
- Task queue management and prioritization
- Error handling and retry mechanisms
- Task monitoring and logging
- Result backend for task status tracking
- Task routing and worker specialization
- Memory management and worker scaling
- Dead letter queue handling
Task Scheduling System
Celery Beat scheduler for automated tasks, maintenance jobs, and recurring operations.
Scheduling Features:
- Cron-style task scheduling
- Recurring task management
- Dynamic schedule updates
- Timezone-aware scheduling
- Task dependency management
- Schedule persistence and recovery
- Maintenance window scheduling
Security Framework
Multi-layered security approach with CORS, rate limiting, input validation, and protection against common attacks.
Security Features:
- CORS configuration for cross-origin requests
- Rate limiting and request throttling with additional packages
- Input validation with Pydantic models
- SQL injection protection via ORM
- XSS and CSRF protection
- Security headers (HSTS, CSP, etc.)
Development & Production Tools
Complete development environment with testing, linting, formatting, and deployment configurations.
Developer Tools:
- Pre-configured testing with pytest and fixtures
- Code formatting with Black and isort
- Hot reload and debugging support
- Docker containerization and docker-compose
- Environment management and configuration
- Logging and monitoring setup
- CI/CD pipeline templates
Development Workflow
Testing
Run the test suite to ensure everything is working:
# Run all tests
pytest
# Run with coverage
pytest --cov=app
# Run specific test file
pytest tests/test_auth.py
Code Quality
The template includes pre-configured tools for code quality:
# Format code with black
black .
# Sort imports with isort
isort .
# Lint with flake8
flake8 .
# Type checking with mypy
mypy .
Background Task Management
The template includes a complete Celery setup for handling background tasks:
# Start Celery worker for processing tasks
celery -A celery_setup worker --loglevel=info
# Start Celery Beat for scheduled tasks
celery -A celery_setup beat --loglevel=info
# Monitor tasks with Flower (optional)
celery -A celery_setup flower
Common Use Cases:
- Email sending (registration, password reset, notifications)
- Payment processing and webhook handling
- Data exports and report generation
- Image processing and file uploads
- Database cleanup and maintenance tasks
- API integrations and third-party syncing
Task Scheduling with Celery Beat
Configure recurring tasks in your celery_setup.py
:
from celery.schedules import crontab
beat_schedule = {
'cleanup-expired-tokens': {
'task': 'app.tasks.cleanup_expired_tokens',
'schedule': crontab(hour=2, minute=0), # Daily at 2 AM
},
'send-weekly-reports': {
'task': 'app.tasks.send_weekly_reports',
'schedule': crontab(hour=9, minute=0, day_of_week=1), # Monday 9 AM
},
'health-check': {
'task': 'app.tasks.system_health_check',
'schedule': 300.0, # Every 5 minutes
},
}
Next Steps
📚 API Documentation
Learn about the available endpoints and how to use them
🔐 Authentication Guide
Deep dive into the authentication system
💳 Payment Setup
Configure payment processing for your application
🚀 Deployment
Deploy your application to production
Common Issues
Database Connection Issues: Ensure PostgreSQL is running and the DATABASE_URL is correct in your .env file.
Migration Errors: If you encounter migration issues, try dropping all tables and running migrations again in development.
Port Conflicts: If port 8000 is already in use, specify a different port
with --port 8001
.
Support
Need help? Here are some resources:
- Documentation: Check the
/docs
folder for detailed guides - GitHub Issues: Report bugs and request features
- Community: Join our Discord server for support