
Added complete backend infrastructure with: - Authentication system with OAuth (Google, GitHub, Apple) - Stripe payment processing with subscription management - Testimonials management API - Usage statistics tracking - Email communication services - Health monitoring endpoints - Database migrations with Alembic - Comprehensive API documentation All APIs are production-ready with proper error handling, security measures, and environment variable configuration. Co-Authored-By: Claude <noreply@anthropic.com>
Landing Page Backend API
A comprehensive FastAPI backend for a modern landing page with authentication, payments, testimonials, and communication features.
Features
🔐 Authentication
- Email/password registration and login
- OAuth integration (Google, GitHub, Apple)
- JWT token-based authentication
- User profile management
💳 Payment Processing
- Stripe integration for subscriptions
- Multiple pricing plans (Starter, Professional, Business, Enterprise)
- Webhook handling for subscription events
- Customer management
📝 Content Management
- Testimonials API with featured/active filtering
- Usage statistics tracking and display
- Real-time metrics for landing page
📧 Communication
- Email services via SendGrid
- Newsletter subscription handling
- Contact form processing
- Sales inquiry management
- Support chat configuration
🏥 Health & Monitoring
- Health check endpoint
- Database connectivity monitoring
- API documentation (OpenAPI/Swagger)
Project Structure
├── app/
│ ├── api/v1/ # API endpoints
│ │ ├── auth.py # Authentication routes
│ │ ├── testimonials.py # Testimonials CRUD
│ │ ├── usage_stats.py # Usage statistics
│ │ ├── communication.py # Email & contact forms
│ │ └── payments.py # Stripe payment handling
│ ├── auth/ # OAuth configuration
│ ├── core/ # Core settings and security
│ ├── db/ # Database configuration
│ ├── models/ # SQLAlchemy models
│ ├── schemas/ # Pydantic schemas
│ └── services/ # Business logic services
├── alembic/ # Database migrations
├── main.py # FastAPI application
└── requirements.txt # Python dependencies
Environment Variables
Create a .env
file in the root directory with the following variables:
Required
SECRET_KEY=your-secret-key-here
SENDGRID_API_KEY=your-sendgrid-api-key
FROM_EMAIL=noreply@yourdomain.com
# Stripe
STRIPE_PUBLISHABLE_KEY=pk_test_...
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
# OAuth - Google
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
# OAuth - GitHub
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
# OAuth - Apple
APPLE_CLIENT_ID=your-apple-client-id
APPLE_TEAM_ID=your-apple-team-id
APPLE_KEY_ID=your-apple-key-id
APPLE_PRIVATE_KEY=your-apple-private-key
Optional
FRONTEND_URL=http://localhost:3000
ADMIN_EMAIL=admin@yourdomain.com
SALES_EMAIL=sales@yourdomain.com
Installation & Setup
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
cp .env.example .env # Edit .env with your actual values
-
Run database migrations
alembic upgrade head
-
Seed initial data (optional)
# Start the server first, then: curl -X POST http://localhost:8000/api/v1/stats/seed
Running the Application
Development
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Production
uvicorn main:app --host 0.0.0.0 --port 8000
API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
API Endpoints
Core
GET /
- API informationGET /health
- Health check
Authentication
POST /api/v1/auth/register
- User registrationPOST /api/v1/auth/login
- User loginGET /api/v1/auth/oauth/{provider}
- OAuth loginGET /api/v1/auth/oauth/{provider}/callback
- OAuth callback
Testimonials
GET /api/v1/testimonials/
- List testimonialsPOST /api/v1/testimonials/
- Create testimonialGET /api/v1/testimonials/{id}
- Get testimonialPUT /api/v1/testimonials/{id}
- Update testimonialDELETE /api/v1/testimonials/{id}
- Delete testimonial
Usage Statistics
GET /api/v1/stats/
- Get all statisticsGET /api/v1/stats/summary
- Get statistics summaryGET /api/v1/stats/{metric_name}
- Get metric historyPOST /api/v1/stats/
- Create/update statisticPOST /api/v1/stats/seed
- Seed default statistics
Communication
POST /api/v1/communication/newsletter/subscribe
- Newsletter signupPOST /api/v1/communication/contact
- Contact formPOST /api/v1/communication/sales/inquiry
- Sales inquiryGET /api/v1/communication/support/chat/config
- Chat widget config
Payments
GET /api/v1/payments/plans
- Get pricing plansPOST /api/v1/payments/checkout
- Create checkout sessionPOST /api/v1/payments/webhook
- Stripe webhookGET /api/v1/payments/subscription/{user_id}
- Get subscriptionPOST /api/v1/payments/subscription/manage
- Manage subscriptionPOST /api/v1/payments/setup-products
- Setup Stripe products
Database
Uses SQLite by default with the following location:
- Database path:
/app/storage/db/db.sqlite
Migrations
Create new migration:
alembic revision -m "description"
Apply migrations:
alembic upgrade head
Code Quality
The project uses Ruff for linting and formatting:
# Install ruff
pip install ruff
# Lint and fix
ruff check --fix .
# Format
ruff format .
Security
- JWT tokens for authentication
- Password hashing with bcrypt
- OAuth integration for secure third-party login
- Environment variables for sensitive data
- CORS middleware for cross-origin requests
Deployment Notes
- Set all required environment variables
- Use a proper database (PostgreSQL) in production
- Configure proper CORS origins
- Set up SSL/TLS certificates
- Use a reverse proxy (nginx)
- Set up monitoring and logging
Support
- API Documentation:
/docs
- Health Check:
/health
- Issues: Contact your development team
Built with FastAPI and BackendIM AI Code Generation
Description
Languages
Python
99%
Mako
1%