A production-grade, multi-tenant SaaS inventory management system built with NestJS and TypeScript.
- Overview
- Key Features
- Tech Stack
- Architecture
- Getting Started
- Environment Configuration
- Docker Development
- API Documentation
- Testing
- CI/CD Pipeline
- Project Structure
- Contributing
Invetrixa is a comprehensive, enterprise-level inventory management platform designed as a multi-tenant SaaS application. It provides businesses with tools to manage products, stock, point-of-sale operations, invoicing, customer/supplier relationships, and more β all within a secure, scalable, and modular architecture.
The backend is built with NestJS 11, uses Prisma ORM with PostgreSQL, and leverages Redis for session management and background job processing via BullMQ.
| Module | Description |
|---|---|
| π’ Multi-Tenancy | Isolated tenant workspaces with tenant-specific data, locations, and configurations |
| π Authentication | Session-based auth with Passport.js, OTP verification, and onboarding flow |
| π‘οΈ Access Control (RBAC) | Role-based permissions with module-level granularity and auto-initialized roles |
| π¦ Product Management | Full product catalog with category organization |
| π Stock Management | Comprehensive inventory tracking with stock movements and adjustments |
| π Point of Sale (POS) | Complete POS system with cart management, sales processing, and terminal support |
| π§Ύ Invoice Generation | Automated invoice creation with customizable templates |
| π₯ Customer Management | Customer profiles and transaction history |
| π Supplier Management | Supplier directory and procurement tracking |
| π Location Management | Multi-location support per tenant |
| π¦ Packages & Plans | Subscription packages and feature gating |
- π Enterprise Security β Helmet, CSRF protection, rate limiting, request timeouts, and response sanitization
- π API Versioning β URI-based versioning (
/api/v1/...) for backward-compatible API evolution - π Swagger/OpenAPI β Auto-generated interactive API documentation at
/api-docs(development only) - β‘ Background Jobs β BullMQ + Redis for async task processing (email queues, etc.)
- β Zod Validation β Strict environment variable validation with fail-fast startup behavior
- π Global Interceptors β Logging, timeout, response transformation, and sensitive field sanitization
- π©Ί Health Checks β Built-in
/healthendpoint for container orchestration and monitoring - π§ Email Service β SMTP-based email delivery via Nodemailer
| Category | Technologies |
|---|---|
| Runtime | Node.js 20, TypeScript 5.9 |
| Framework | NestJS 11 |
| ORM | Prisma 7.3 (multi-schema setup with 13 domain schemas) |
| Database | PostgreSQL 17 |
| Cache / Queues | Redis 7, BullMQ |
| Authentication | Passport.js, express-session, connect-redis, Argon2 |
| Validation | class-validator, class-transformer, Zod |
| API Docs | Swagger / OpenAPI (@nestjs/swagger) |
| Security | Helmet, csrf-csrf, @nestjs/throttler |
| Testing | Jest, Supertest |
| Containerization | Docker, Docker Compose (dev / staging / prod) |
| CI/CD | GitHub Actions (CI, CD-staging, CD-production) |
| Code Quality | ESLint, Prettier, Husky, lint-staged, commitlint |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client (Frontend) β
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β HTTPS
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
β NestJS Application β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Middleware Chain β β
β β Helmet β CORS β CSRF β Session β Passport β Logger β β
β βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ β
β β Global Guards & Interceptors β β
β β ThrottlerGuard β OnboardingGuard β β
β β LoggingInterceptor β TimeoutInterceptor β β
β β SanitizeResponseInterceptor β TransformInterceptor β β
β βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ β
β β Feature Modules β β
β β Auth β Tenants β Users β Products β Stock β POS β β
β β Invoice β Customer β Supplier β Category β Location β β
β β Access-Control β Packages β Modules-Definition β β
β βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ β
β βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ β
β β Shared Services β β
β β PrismaService β RedisService β EmailService β Utils β β
β βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ
ββββββββββββββΌβββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββ
βPostgreSQLβ β Redis β β BullMQ β
β 17 β β 7 β β Queues β
ββββββββββββ ββββββββββββ ββββββββββββ
- Node.js β₯ 20
- pnpm β₯ 9
- Docker & Docker Compose (recommended)
- PostgreSQL 17 (if running without Docker)
- Redis 7 (if running without Docker)
# 1. Clone the repository
git clone https://github.com/Asadullah246/invetrixa-server.git
cd invetrixa-server
# 2. Copy the example env file
cp .env.example .env.development
# 3. Start all services (app + Postgres + Redis)
pnpm docker:dev
# 4. (Optional) Start dev tools β pgAdmin, Redis Insight, Portainer
pnpm docker:up:toolsThe API will be available at http://localhost:8080 and Swagger docs at http://localhost:8080/api-docs.
# 1. Install dependencies
pnpm install
# 2. Set up your .env.development file
cp .env.example .env.development
# Edit .env.development with your local PostgreSQL and Redis connection details
# 3. Generate Prisma Client
pnpm prisma:generate
# 4. Push schema to database
pnpm exec prisma db push
# 5. (Optional) Seed the database
pnpm prisma:seed
# 6. Start the dev server
pnpm start:devThis project uses a strict single-file approach per environment β no cascading .env fallbacks.
| File | Environment | Usage |
|---|---|---|
.env.development |
Development | Docker & local development |
.env.test |
Test | Unit, integration & E2E tests |
.env.production |
Production | Production deployment (not committed) |
All environment variables are validated at startup using Zod. Missing or invalid variables will cause the application to fail fast with descriptive error messages.
See
.env.examplefor the full list of supported variables.
The project ships with pre-configured Docker Compose files for multiple environments:
| File | Purpose |
|---|---|
docker-compose.dev.yml |
Development with hot-reload, pgAdmin, Redis Insight |
docker-compose.staging.yml |
Staging environment |
docker-compose.prod.yml |
Production deployment |
# Start / Stop
pnpm docker:up # Start app + Postgres + Redis
pnpm docker:down # Stop all containers
pnpm docker:restart # Restart app container only
# Database
pnpm docker:migrate # Run Prisma migrations
pnpm docker:seed # Seed the database
pnpm docker:reset:db # Reset database (β οΈ destructive)
pnpm docker:studio # Open Prisma Studio (port 5555)
# Monitoring
pnpm docker:logs # Stream app logs
pnpm docker:logs:all # Stream all service logs
pnpm docker:ps # List running containers
pnpm docker:shell # Open shell in app container
# Testing inside Docker
pnpm docker:test # Unit tests
pnpm docker:test:e2e # E2E tests
pnpm docker:test:integration # Integration testsInteractive Swagger documentation is available in development mode:
- URL:
http://localhost:8080/api-docs - Authentication: Session-based (cookie
connect.sid) - Multi-tenant Header:
x-tenant-id(required for tenant-specific endpoints) - Location Header:
x-location-id(for location-specific operations)
Swagger is automatically disabled in production for security.
# Unit Tests
pnpm test # Run all unit tests
pnpm test:watch # Watch mode
pnpm test:cov # With coverage report
# E2E Tests (requires running Postgres + Redis)
pnpm test:e2e
# Integration Tests
pnpm test:integrationThe project uses GitHub Actions with three workflows:
| Workflow | Trigger | Steps |
|---|---|---|
| CI | Pull requests to main / develop |
Lint β Type-check β Unit tests β E2E tests β Docker build |
| CD Staging | Push to develop |
Build β Deploy to staging |
| CD Production | Push to main |
Build β Deploy to production |
CI runs lint, type-check, and unit tests in parallel with E2E tests (using service containers for Postgres 17 + Redis 7).
invetrixa-server/
βββ .github/ # GitHub Actions workflows & templates
β βββ workflows/
β βββ ci.yml # CI pipeline
β βββ cd-staging.yml # Staging deployment
β βββ cd-production.yml # Production deployment
βββ prisma/
β βββ schemas/ # Multi-file Prisma schema (13 domain models)
β βββ migrations/ # Database migration history
β βββ seed/ # Database seeders
βββ src/
β βββ bootstrap/ # App initialization (security, CORS, Swagger)
β βββ config/ # Typed config namespaces & Zod validation
β βββ common/ # Shared utilities, DTOs, guards, interceptors
β β βββ constants/ # Application constants
β β βββ decorator/ # Custom decorators
β β βββ dto/ # Shared DTOs & API response types
β β βββ filter/ # Global exception filter
β β βββ interceptors/ # Global interceptors
β β βββ middleware/ # Custom middleware (security, logging)
β β βββ prisma/ # Prisma service
β β βββ services/ # Shared services (email, etc.)
β β βββ utils/ # Utility functions
β β βββ validator/ # Custom validators
β βββ modules/
β β βββ auth/ # Authentication & authorization
β β βββ tenants/ # Multi-tenant management
β β βββ users/ # User management
β β βββ product/ # Product catalog
β β βββ category/ # Product categories
β β βββ stock/ # Inventory & stock management
β β βββ pos/ # Point of Sale system
β β βββ invoice/ # Invoice generation
β β βββ customer/ # Customer management
β β βββ supplier/ # Supplier management
β β βββ location/ # Location management
β β βββ access-control/ # RBAC system
β β βββ packages/ # Subscription packages
β β βββ modules-definition/ # Module feature definitions
β β βββ health/ # Health check endpoint
β βββ redis/ # Redis service & module
βββ test/ # E2E & integration test suites
βββ docker-compose.dev.yml # Development Docker Compose
βββ docker-compose.staging.yml
βββ docker-compose.prod.yml
βββ Dockerfile # Multi-stage production build
βββ Dockerfile.dev # Development Dockerfile
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
- Setting up your development environment
- Commit message conventions (Conventional Commits)
- Pull request process
- Code style & testing requirements
- Branch strategy (
mainβdevelopβfeat/*)
Built with β€οΈ using NestJS