Skip to content

About

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NestJS TypeScript Prisma PostgreSQL Redis Docker

Invetrixa Server

A production-grade, multi-tenant SaaS inventory management system built with NestJS and TypeScript.

Node.js pnpm License


πŸ“‹ Table of Contents


πŸ” Overview

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.


✨ Key Features

Core Business Modules

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

Technical Highlights

  • πŸ”’ 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 /health endpoint for container orchestration and monitoring
  • πŸ“§ Email Service β€” SMTP-based email delivery via Nodemailer

πŸ›  Tech Stack

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

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       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  β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 20
  • pnpm β‰₯ 9
  • Docker & Docker Compose (recommended)
  • PostgreSQL 17 (if running without Docker)
  • Redis 7 (if running without Docker)

Quick Start (Docker β€” Recommended)

# 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:tools

The API will be available at http://localhost:8080 and Swagger docs at http://localhost:8080/api-docs.

Local Development (Without Docker)

# 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:dev

βš™οΈ Environment Configuration

This 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.example for the full list of supported variables.


🐳 Docker Development

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

Useful Commands

# 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 tests

πŸ“– API Documentation

Interactive 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.


πŸ§ͺ Testing

# 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:integration

πŸ”„ CI/CD Pipeline

The 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).


πŸ“ Project Structure

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

🀝 Contributing

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

About

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages