Skip to content

Automatajm/sunset-erp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

183 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Sunset ERP

A modern, production-ready, multi-tenant SaaS ERP platform built with NestJS, TypeScript, and PostgreSQL.

License: MIT TypeScript NestJS PostgreSQL

πŸ“‹ Overview

Sunset ERP is a complete enterprise resource planning system designed for multi-tenant SaaS deployment. It provides comprehensive business management capabilities including procurement, sales, inventory management, and full manufacturing execution.

🎯 Production Ready - This is commercial-grade software, not a demo or proof of concept.

✨ Features

πŸ” Security & Authentication

  • JWT-based authentication with 15-minute expiry
  • Role-based access control (RBAC) with 23 permissions
  • Multi-tenant data isolation with RLS-ready architecture
  • Password hashing with bcrypt (cost factor 12)
  • Complete audit trails on all operations
  • Soft delete preserving data integrity

πŸ“¦ Procurement Management

  • Suppliers: Complete vendor master data management
  • Purchase Orders: Multi-line POs with automatic calculations
    • Auto-generated PO numbers (PO-YYYY-####)
    • Line-level pricing with discounts
    • Approval workflows
    • Status tracking (draft β†’ approved β†’ closed)

πŸ’Ό Sales Management

  • Customers: Customer master data with credit management
    • Credit limit tracking
    • Credit status (good/watch/hold)
    • Payment terms
  • Sales Orders: Multi-line orders with calculations
    • Auto-generated SO numbers (SO-YYYY-####)
    • Customer PO tracking
    • Delivery date management
    • Status workflow (draft β†’ confirmed β†’ shipped β†’ delivered)

πŸ“Š Inventory Management

  • Items: Support for multiple item types
    • Raw materials, finished goods, work-in-progress, services
    • Lot/serial tracking configuration
    • Valuation methods (Average, FIFO, Standard Cost)
    • Planning parameters (lead time, safety stock, reorder point)
  • Warehouses: Multi-location inventory management
    • Multiple warehouse types (regular, consignment, transit)
    • Location tracking
    • Stock count integration
  • Stock Transactions: Real-time inventory tracking
    • Stock receipts (inbound)
    • Stock issues (outbound)
    • Stock transfers between warehouses
    • Stock adjustments
    • Auto-generated movement numbers (SM-YYYY-####)
    • Lot/serial number tracking
    • Real-time balance calculation

🏭 Manufacturing

  • Bill of Materials (BOM): Product structure definition
    • Parent-component relationships
    • Quantity per unit with scrap percentage
    • BOM versioning
    • Auto-generated BOM numbers (BOM-YYYY-####)
    • Material requirements calculation (MRP)
    • Multi-level BOM support
    • Circular reference prevention
  • Work Centers: Production resource management
    • Machine and labor stations
    • Capacity tracking (units/hour)
    • Efficiency percentage
    • Cost per hour
  • Production Orders: Manufacturing execution
    • BOM-based production planning
    • Auto-generated MO numbers (MO-YYYY-####)
    • Material requirements integration
    • Status workflow (draft β†’ released β†’ in_progress β†’ completed)
    • Planned vs actual date tracking
    • Production quantity tracking

🏒 Multi-Tenancy

  • Complete data isolation per tenant
  • Tenant-specific numbering sequences
  • Shared infrastructure with isolated data
  • Automatic tenant scoping on all queries

πŸ“š API Documentation

  • Complete Swagger/OpenAPI documentation
  • Interactive API testing at /api/docs
  • Request/response examples
  • Permission requirements documented

πŸ“Š Statistics

  • API Endpoints: 65+
  • Business Modules: 10
  • Database Tables: 50
  • Lines of Code: ~13,000+
  • Permissions: 23
  • Test Coverage: Manual testing complete

πŸ› οΈ Technology Stack

  • Backend Framework: NestJS 10
  • Language: TypeScript (strict mode)
  • Database: PostgreSQL 15+
  • ORM: Prisma 5
  • Authentication: Passport.js + JWT
  • Validation: class-validator
  • Documentation: Swagger/OpenAPI 3.0
  • Development: Nodemon (auto-restart)

πŸš€ Getting Started

Prerequisites

  • Node.js 24+ (LTS recommended)
  • PostgreSQL 15+
  • npm or yarn

Installation

  1. Clone the repository
   git clone https://github.com/Automatajm/sunset-erp.git
   cd sunset-erp/backend
  1. Install dependencies
   npm install
  1. Configure environment
   cp .env.example .env

Edit .env with your database credentials:

   DATABASE_URL="postgresql://user:password@localhost:5432/sunset_erp_dev?schema=public"
   JWT_SECRET=your_jwt_secret_change_in_production
  1. Run database migrations
   npx prisma migrate dev
  1. Seed the database
   npm run seed
  1. Start development server
   npm run start:dev

The API will be available at http://localhost:3000/api
Swagger documentation at http://localhost:3000/api/docs

Default Credentials

After seeding the database:

  • Email: admin@demo.com
  • Password: Admin123!
  • Tenant: DEMO

πŸ“– Documentation

πŸ”‘ API Overview

Authentication

POST /api/auth/login
POST /api/auth/register
GET /api/auth/profile

Procurement

# Suppliers
POST   /api/suppliers
GET    /api/suppliers
GET    /api/suppliers/:id
PATCH  /api/suppliers/:id
DELETE /api/suppliers/:id

# Purchase Orders
POST   /api/purchase-orders
GET    /api/purchase-orders
PATCH  /api/purchase-orders/:id/status/:status

Sales

# Customers
POST   /api/customers
GET    /api/customers

# Sales Orders
POST   /api/sales-orders
GET    /api/sales-orders
PATCH  /api/sales-orders/:id/status/:status

Inventory

# Items
POST   /api/items
GET    /api/items
GET    /api/items/statistics

# Warehouses
POST   /api/warehouses
GET    /api/warehouses

# Stock Transactions
POST   /api/stock-transactions
GET    /api/stock-transactions/balance

Manufacturing

# BOM
POST   /api/bom
GET    /api/bom/:id/calculate/:quantity

# Work Centers
POST   /api/work-centers
GET    /api/work-centers

# Production Orders
POST   /api/production-orders
PATCH  /api/production-orders/:id/status/:status

πŸ§ͺ Example Workflows

Complete Manufacturing Workflow

// 1. Create a finished good item
POST /api/items
{
  "code": "CHAIR-001",
  "name": "Office Chair",
  "itemType": "finished_good",
  "isManufacturable": true
}

// 2. Create BOM with components
POST /api/bom
{
  "itemId": "chair-uuid",
  "components": [
    { "componentItemId": "bolt-uuid", "quantity": 4, "scrapPercent": 5 },
    { "componentItemId": "steel-uuid", "quantity": 2, "scrapPercent": 10 }
  ]
}

// 3. Calculate material requirements
GET /api/bom/{bom-id}/calculate/200
// Returns: 840 bolts (800 + 40 scrap), 440kg steel (400 + 40 scrap)

// 4. Create production order
POST /api/production-orders
{
  "bomId": "bom-uuid",
  "quantityOrdered": 200
}
// Returns: MO-2026-0001

// 5. Release and start production
PATCH /api/production-orders/{id}/status/released
PATCH /api/production-orders/{id}/status/in_progress

πŸ—οΈ Architecture

Clean Architecture

  • Controllers: HTTP layer, request/response handling
  • Services: Business logic and orchestration
  • DTOs: Data validation and transformation
  • Guards: Authorization and permission checks
  • Decorators: Metadata and cross-cutting concerns

Database Schema

  • 50 tables covering all ERP modules
  • Complete audit trail on all tables
  • Soft delete implementation
  • Foreign key constraints for data integrity
  • Optimized indexes for performance

Multi-Tenant Design

  • Tenant ID on all business tables
  • Automatic tenant scoping via middleware
  • Isolated numbering sequences per tenant
  • Shared infrastructure, separated data

πŸ”’ Security Features

  • Authentication: JWT tokens with short expiry
  • Authorization: Permission-based access control
  • Password Security: bcrypt with cost factor 12
  • Data Isolation: Automatic tenant filtering
  • Audit Trail: Complete change tracking
  • Input Validation: class-validator on all DTOs
  • SQL Injection: Protected by Prisma ORM
  • XSS Protection: Input sanitization

πŸ“ˆ Performance

  • Database Indexing: Optimized queries with proper indexes
  • Prisma ORM: Efficient query generation
  • Eager Loading: Reduces N+1 queries
  • Pagination Ready: Can be added to list endpoints
  • Caching Ready: Redis integration prepared

πŸ§ͺ Testing

Manual Testing

All modules have been manually tested with complete workflows:

  • βœ… Authentication flows
  • βœ… CRUD operations on all modules
  • βœ… Business logic validation
  • βœ… Permission enforcement
  • βœ… Multi-tenant isolation
  • βœ… Stock balance calculations
  • βœ… BOM material requirements
  • βœ… Production order workflows

Test Data

Use the seed command to populate test data:

npm run seed        # Seed database
npm run seed:reset  # Reset and reseed

πŸš€ Deployment

Docker (Recommended)

# Coming in Sprint 6
docker-compose up -d

Manual Deployment

  1. Set production environment variables
  2. Run migrations: npx prisma migrate deploy
  3. Build: npm run build
  4. Start: npm run start:prod

Environment Variables

NODE_ENV=production
DATABASE_URL=postgresql://...
JWT_SECRET=strong_secret_here
JWT_EXPIRES_IN=15m
PORT=3000

πŸ—ΊοΈ Roadmap

  • Sprint 1: Foundation (Auth, Multi-tenant, RBAC)
  • Sprint 2: Business Modules (Procurement, Sales)
  • Sprint 3: Manufacturing (Inventory, BOM, Production)
  • Sprint 4: Financial Management (GL, Reports)
  • Sprint 5: Frontend (React + Vite)
  • Sprint 6: DevOps (Docker, CI/CD, AWS)

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Juan Osvaldo Mendoza Santana

πŸ™ Acknowledgments

  • Built with passion for creating production-ready software
  • Inspired by real-world ERP requirements
  • Designed for scalability and maintainability

Status: Production Ready βœ…
Version: 1.0.0
Last Updated: March 15, 2026

⭐ If you find this project useful, please consider giving it a star!

About

Enterprise resources planning

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors