A scalable and production-ready backend template for SaaS applications, built with NestJS, PostgreSQL (Prisma ORM), Stripe for subscriptions, and Winston + Loki + Grafana for logging.
✅ Authentication & Authorization (JWT + Role-Based Access Control)
✅ Subscription Management (Stripe Checkout, Webhooks, Cancellations)
✅ PostgreSQL Database with Prisma ORM
✅ Logging & Monitoring with Loki + Grafana
✅ Docker Support for easy deployment
✅ Structured Codebase (Modular NestJS Architecture)
git clone https://github.com/tsvetanml/saas-backend-template.git
cd saas-backend-template
Copy .env.example
and create a .env
file:
cp .env.example .env
Then update the following variables:
DATABASE_URL=postgresql://user:password@localhost:5432/saas_backend_db?schema=public
JWT_SECRET=your_jwt_secret
STRIPE_PUBLIC_KEY=your_stripe_public_key
STRIPE_SECRET_KEY=your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=your_stripe_webhook_secret
docker-compose up -d
npx prisma migrate dev --name init
npm run start:dev
The server will run at: http://localhost:4000
POST /auth/register -> Register a new user
POST /auth/login -> Login and get JWT token
POST /stripe/checkout -> Start a subscription checkout
DELETE /subscriptions/cancel -> Cancel active subscription
GET /profile -> Get user profile (Auth Required)
GET /subscriptions/active -> Get active subscriptions (Admin Only)
🔹 Full API documentation coming soon!
1️⃣ Start Loki & Grafana (If not running)
docker-compose up -d
2️⃣ Open Grafana: http://localhost:3000
3️⃣ Login: (Default: admin
/ admin
)
4️⃣ Go to "Explore" → Select "Loki" → Query Logs
{app="saas-backend"}
- WebSocket Notifications for Subscription Events
- Multi-Tier Subscription Plans
- Admin Dashboard for Subscription Management
Made with ❤️ by Tsvetan. Feel free to contribute!
MIT License - Free for personal & commercial use.