A robust production-ready backend API built with NestJS, designed for enterprise-grade Software-as-a-Service applications.
Quick guide to set up and run the platform.
graph TD
A[Client Request] --> B[Global Guards: JWT & RBAC]
B --> C[Global Interceptors: Logging/Transform]
C --> D[Feature Module: Controller]
D --> E[Service Layer: Business Logic]
E --> F[Repository Layer: Prisma ORM]
F --> G[(PostgreSQL: Row Level Isolation)]
subgraph Async Operations
E --> H[BullMQ / Redis]
H --> I[Worker: Email/Billing]
end
| Component | Implementation | Industry Value | | :— | :— | :— | | Data Isolation | Row-Level Multi-tenancy | Essential for GDPR/CCPA compliance in SaaS | | Security Architecture | JWT + RBAC + Passport.js | Protects enterprise data against unauthorized access | | Scalability | Redis Queue + BullMQ Workers | Handles high-volume traffic without system degradation | | Maintainability | Clean Architecture & NestJS DI | Reduces long-term technical debt and operational costs |
All modules include:
Create a .env file in the root directory:
# Database
DATABASE_URL="postgresql://username:password@localhost:5432/portfolio_saas?schema=public"
# JWT
JWT_SECRET="your-secret-key"
JWT_EXPIRES_IN="1h"
# Redis
REDIS_URL="redis://localhost:6379"
# Email (simulation)
EMAIL_HOST="smtp.gmail.com"
EMAIL_PORT=587
EMAIL_USER="your-email@gmail.com"
EMAIL_PASS="your-password"
# Payment (Stripe sandbox)
STRIPE_SECRET_KEY="sk_test_..."
STRIPE_WEBHOOK_SECRET="whsec_..."
git clone <repository-url>
cd portfolio-saas-backend
npm install
# Start PostgreSQL and Redis locally or via Docker
docker run --name postgres -e POSTGRES_USER=username -e POSTGRES_PASSWORD=password -e POSTGRES_DB=portfolio_saas -p 5432:5432 -d postgres:15
docker run --name redis -p 6379:6379 -d redis:7-alpine
cp .env.example .env
# Edit .env with your values
npm run prisma:migrate
npm run prisma:generate
npm run start:dev
The API will be available at http://localhost:3000.
docker-compose up --build
This will start the app, PostgreSQL, and Redis.
POST /auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123",
"firstName": "John",
"lastName": "Doe",
"organizationId": "org-id"
}
POST /auth/login
Content-Type: application/json
{
"username": "user@example.com",
"password": "password123"
}
Response:
{
"access_token": "jwt-token-here"
}
POST /organizations
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "My Company"
}
GET /organizations?page=1&limit=10&name=search
Authorization: Bearer <token>
POST /projects
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "Website Redesign",
"description": "Redesign company website"
}
GET /projects?page=1&limit=10&name=search
Authorization: Bearer <token>
POST /tasks
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Design homepage",
"description": "Create new homepage design",
"projectId": "project-id"
}
GET /tasks?page=1&limit=10&status=pending
Authorization: Bearer <token>
POST /payments/create-intent
Content-Type: application/json
{
"amount": 1000,
"currency": "usd"
}
POST /payments/webhook
Content-Type: application/json
Stripe-Signature: <signature>
{
"type": "payment_intent.succeeded",
"data": { ... }
}
organizationId for data isolationThe platform implements a Shared Database, Shared Schema strategy. Data isolation is enforced at the service level through mandatory organizationId filters in every query. This approach balances cost-efficiency with the scalability required for high-growth startups.
# Unit tests
npm run test
# E2E tests
npm run test:e2e
# Coverage
npm run test:cov
This application is containerized with Docker and can be deployed to any cloud platform supporting Docker containers (AWS ECS, Google Cloud Run, Azure Container Instances, etc.).
For production:
Patrick - Computer Engineer To view other projects and portfolio details, visit: https://pklavc.github.io/projects.html
This project demonstrates advanced backend development capabilities for enterprise SaaS applications.
14bbba43 (Clean up project structure and update documentation) 87cf431c
======= «««< HEAD
=======
14bbba43 (Clean up project structure and update documentation) 87cf431c