Automated Action 246b4e058e Implement comprehensive FastAPI backend for landing page
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>
2025-07-01 23:39:39 +00:00

233 lines
6.0 KiB
Markdown

# 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
```bash
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
```bash
FRONTEND_URL=http://localhost:3000
ADMIN_EMAIL=admin@yourdomain.com
SALES_EMAIL=sales@yourdomain.com
```
## Installation & Setup
1. **Install dependencies**
```bash
pip install -r requirements.txt
```
2. **Set up environment variables**
```bash
cp .env.example .env
# Edit .env with your actual values
```
3. **Run database migrations**
```bash
alembic upgrade head
```
4. **Seed initial data** (optional)
```bash
# Start the server first, then:
curl -X POST http://localhost:8000/api/v1/stats/seed
```
## Running the Application
### Development
```bash
uvicorn main:app --reload --host 0.0.0.0 --port 8000
```
### Production
```bash
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 information
- `GET /health` - Health check
### Authentication
- `POST /api/v1/auth/register` - User registration
- `POST /api/v1/auth/login` - User login
- `GET /api/v1/auth/oauth/{provider}` - OAuth login
- `GET /api/v1/auth/oauth/{provider}/callback` - OAuth callback
### Testimonials
- `GET /api/v1/testimonials/` - List testimonials
- `POST /api/v1/testimonials/` - Create testimonial
- `GET /api/v1/testimonials/{id}` - Get testimonial
- `PUT /api/v1/testimonials/{id}` - Update testimonial
- `DELETE /api/v1/testimonials/{id}` - Delete testimonial
### Usage Statistics
- `GET /api/v1/stats/` - Get all statistics
- `GET /api/v1/stats/summary` - Get statistics summary
- `GET /api/v1/stats/{metric_name}` - Get metric history
- `POST /api/v1/stats/` - Create/update statistic
- `POST /api/v1/stats/seed` - Seed default statistics
### Communication
- `POST /api/v1/communication/newsletter/subscribe` - Newsletter signup
- `POST /api/v1/communication/contact` - Contact form
- `POST /api/v1/communication/sales/inquiry` - Sales inquiry
- `GET /api/v1/communication/support/chat/config` - Chat widget config
### Payments
- `GET /api/v1/payments/plans` - Get pricing plans
- `POST /api/v1/payments/checkout` - Create checkout session
- `POST /api/v1/payments/webhook` - Stripe webhook
- `GET /api/v1/payments/subscription/{user_id}` - Get subscription
- `POST /api/v1/payments/subscription/manage` - Manage subscription
- `POST /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:
```bash
alembic revision -m "description"
```
Apply migrations:
```bash
alembic upgrade head
```
## Code Quality
The project uses Ruff for linting and formatting:
```bash
# 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
1. Set all required environment variables
2. Use a proper database (PostgreSQL) in production
3. Configure proper CORS origins
4. Set up SSL/TLS certificates
5. Use a reverse proxy (nginx)
6. 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