A production-ready FastAPI backend for ProdDash - A productivity dashboard with task management and analytics.
- User authentication with JWT tokens
- Subscription management via Stripe
- Task management with CRUD operations
- Analytics dashboard with mock data
- Rate limiting for security
- Docker containerization
- Database migrations with Alembic
- Comprehensive API documentation
- Framework: FastAPI
- Database: PostgreSQL (with SQLite fallback)
- ORM: SQLAlchemy
- Authentication: JWT with bcrypt hashing
- Payment Processing: Stripe
- Rate Limiting: SlowAPI
- Logging: Loguru
- Containerization: Docker & Docker Compose
- Docker and Docker Compose
- Stripe account (for payment processing)
git clone <repository-url>
cd proddash-backendCopy the example environment file:
cp .env.example .envUpdate the .env file with your specific configuration:
- Set
SECRET_KEYto a strong, unique value - Add your Stripe API keys
- Adjust other settings as needed
Build and start the services:
docker-compose up --buildRun database migrations:
docker-compose exec api alembic upgrade headThe API will be available at: http://localhost:8000
Install dependencies:
pip install -r requirements.txtSet environment variables:
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/proddash
export SECRET_KEY=your-super-secret-key-change-in-production
export STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
export STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secretRun migrations:
alembic upgrade headStart the server:
uvicorn app.main:app --host 0.0.0.0 --port 8000After starting the server, you can view the interactive API documentation at:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
GET /- Root endpointGET /health- Health check endpointGET /error-test- Test error endpoint (for development)
POST /register- Register a new userPOST /login- Login and get JWT tokenGET /me- Get current user info
GET /me- Get user profilePUT /me- Update user profile
GET /plans- Get available subscription plansPOST /webhook- Handle Stripe webhooksGET /customer-portal- Get billing portal session
GET /tasks- Get user tasks (with pagination)POST /tasks- Create a new taskPUT /tasks/{id}- Update a taskDELETE /tasks/{id}- Delete a taskGET /analytics- Get dashboard analytics
To receive payment notifications, configure a webhook in your Stripe dashboard:
- Endpoint URL:
https://your-domain.com/api/v1/billing/webhook - Events to listen for:
invoice.payment_succeeded,customer.subscription.deleted
pytestTo create a new migration:
alembic revision --autogenerate -m "Description of changes"To apply migrations:
alembic upgrade headBuild images:
docker-compose buildView logs:
docker-compose logs -f apiExecute commands in container:
docker-compose exec api bashDATABASE_URL: Database connection stringSECRET_KEY: Secret key for JWT tokensJWT_ALGORITHM: Algorithm for JWT (default: HS256)ACCESS_TOKEN_EXPIRE_MINUTES: Token expiration time (default: 30)STRIPE_SECRET_KEY: Stripe secret API keySTRIPE_WEBHOOK_SECRET: Stripe webhook signing secretSTRIPE_PRICE_ID_PRO: Stripe price ID for Pro planSTRIPE_PRICE_ID_ENTERPRISE: Stripe price ID for Enterprise planENVIRONMENT: Environment (development/production)FRONTEND_URL: Frontend application URL for CORS
The project includes a Procfile for easy Heroku deployment.
- Ensure environment variables are properly set
- Configure a production-grade database
- Set up a reverse proxy (nginx) in production
- Use Gunicorn with multiple workers for production:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app
- Never commit real API keys or secrets to version control
- Use HTTPS in production
- Implement proper firewall rules
- Regularly update dependencies
- Monitor logs for suspicious activity
For support, please open an issue in the GitHub repository or contact your development team.