Skip to content

simonescob/showcase-nexus-ai-pay-dashboard-backend

Repository files navigation

ProdDash Backend API

A production-ready FastAPI backend for ProdDash - A productivity dashboard with task management and analytics.

Features

  • 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

Tech Stack

  • 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

Prerequisites

  • Docker and Docker Compose
  • Stripe account (for payment processing)

Setup Instructions

1. Clone the Repository

git clone <repository-url>
cd proddash-backend

2. Environment Configuration

Copy the example environment file:

cp .env.example .env

Update the .env file with your specific configuration:

  • Set SECRET_KEY to a strong, unique value
  • Add your Stripe API keys
  • Adjust other settings as needed

3. Using Docker (Recommended)

Build and start the services:

docker-compose up --build

Run database migrations:

docker-compose exec api alembic upgrade head

The API will be available at: http://localhost:8000

4. Manual Setup (Alternative)

Install dependencies:

pip install -r requirements.txt

Set 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_secret

Run migrations:

alembic upgrade head

Start the server:

uvicorn app.main:app --host 0.0.0.0 --port 8000

API Documentation

After starting the server, you can view the interactive API documentation at:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

API Endpoints

General

  • GET / - Root endpoint
  • GET /health - Health check endpoint
  • GET /error-test - Test error endpoint (for development)

Authentication (/api/v1/auth)

  • POST /register - Register a new user
  • POST /login - Login and get JWT token
  • GET /me - Get current user info

Users (/api/v1/users)

  • GET /me - Get user profile
  • PUT /me - Update user profile

Billing (/api/v1/billing)

  • GET /plans - Get available subscription plans
  • POST /webhook - Handle Stripe webhooks
  • GET /customer-portal - Get billing portal session

Dashboard (/api/v1/dashboard)

  • GET /tasks - Get user tasks (with pagination)
  • POST /tasks - Create a new task
  • PUT /tasks/{id} - Update a task
  • DELETE /tasks/{id} - Delete a task
  • GET /analytics - Get dashboard analytics

Stripe Webhook Configuration

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

Development

Running Tests

pytest

Database Migrations

To create a new migration:

alembic revision --autogenerate -m "Description of changes"

To apply migrations:

alembic upgrade head

Docker Commands

Build images:

docker-compose build

View logs:

docker-compose logs -f api

Execute commands in container:

docker-compose exec api bash

Environment Variables

  • DATABASE_URL: Database connection string
  • SECRET_KEY: Secret key for JWT tokens
  • JWT_ALGORITHM: Algorithm for JWT (default: HS256)
  • ACCESS_TOKEN_EXPIRE_MINUTES: Token expiration time (default: 30)
  • STRIPE_SECRET_KEY: Stripe secret API key
  • STRIPE_WEBHOOK_SECRET: Stripe webhook signing secret
  • STRIPE_PRICE_ID_PRO: Stripe price ID for Pro plan
  • STRIPE_PRICE_ID_ENTERPRISE: Stripe price ID for Enterprise plan
  • ENVIRONMENT: Environment (development/production)
  • FRONTEND_URL: Frontend application URL for CORS

Production Deployment

Heroku

The project includes a Procfile for easy Heroku deployment.

Other Platforms

  • 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

Security Notes

  • 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

Support

For support, please open an issue in the GitHub repository or contact your development team.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published