A comprehensive inventory management system with integrated supplier portfolio management, built with Next.js, TypeScript, and PostgreSQL.
The inventory management system has been fully integrated with the NXT-SPP (Supplier Inventory Portfolio) platform. All supplier pricelist uploads, product selection, and stock tracking are now managed through a unified workflow.
Quick Start:
- Access the system at:
http://localhost:3000/nxt-spp - See Integration Documentation for details
- See NXT-SPP README for API reference
- β Unified supplier inventory management (NXT-SPP)
- β End-to-end workflow: Upload β Select β Stock
- β Single-active-selection business rule enforcement
- β Real-time stock on hand reporting
- β Automated pricelist validation and merging
- β Comprehensive dashboard and analytics
- β Multi-supplier support with price history tracking
- β Inventory selection interface (ISI)
- β Performance-optimized database queries
- β RESTful API with comprehensive error handling
- Supplier Pricelist Management: Upload and validate supplier pricelists β NXT-SPP Dashboard
- Inventory Selection: Choose which products to stock β Selection Interface
- Stock Reporting: View stock on hand for selected items β Stock Reports
- Node.js 18+ and npm
- PostgreSQL database
- Environment variables configured
-
Clone the repository
git clone https://gitlab.com/gambew/MantisNXT.git cd MantisNXT -
Install dependencies
bun install
-
Set up environment variables
cp env.example .env.local # Edit .env.local with your database credentials -
Run full integration
npm run integration:full
-
Verify integration
npm run integration:verify
-
Start the development server
npm run dev
-
Access the application
- NXT-SPP Dashboard:
http://localhost:3000/nxt-spp - Inventory Management:
http://localhost:3000/inventory
- NXT-SPP Dashboard:
If you were using the previous inventory system:
- All functionality has moved to
/nxt-spp - The
/inventoryroute now redirects to the unified system - Your data can be migrated using the integration scripts
- See Integration Documentation for details
The system includes comprehensive integration scripts organized by function:
# Database operations (scripts/database/)
npm run db:purge # Purge all inventory data
npm run db:verify-schema # Verify database schema
npm run db:create-schemas # Create missing schemas
# Migrations (scripts/migrations/)
npm run db:migrate # Run database migrations
npm run db:migrate:verify # Verify migrations
# Data imports (scripts/imports/)
npm run import:master # Import master dataset
npm run import:create-selection # Create default selection
npm run import:seed-stock # Seed stock on hand
# Deployment (scripts/deployment/)
npm run deploy:checklist # Pre-deployment checklist
npm run deploy:rollback # Emergency rollback
# Full integration
npm run integration:full # Run complete integration
npm run integration:verify # Verify integration successMantisNXT/
βββ data/ # Data files and templates
β βββ templates/ # CSV templates for imports
β βββ temp/ # Temporary data files
βββ database/ # Database schemas and migrations
β βββ migrations/ # All database migration files
β βββ scripts/ # Database utility scripts
β βββ schema/ # Schema definitions
β βββ indexes/ # Index definitions
β βββ ... # Other database subdirectories
βββ docs/ # Documentation
β βββ imports/ # Import documentation
β βββ ... # Other documentation
βββ scripts/ # Utility scripts
β βββ database/ # Database operation scripts
β βββ migrations/ # Migration execution scripts
β βββ imports/ # Data import scripts
β βββ deployment/ # Deployment scripts
β βββ utils/ # Utility scripts
β βββ tests/ # Test scripts
βββ src/ # Application source code
βββ tests/ # All test files (consolidated)
β βββ auth/ # Authentication tests
β βββ e2e/ # End-to-end tests
β βββ fixtures/ # Test fixtures
β βββ helpers/ # Test helpers
β βββ integration/ # Integration tests
β βββ services/ # Service tests
βββ ... # Other directories
The system follows a 3-layer architecture:
- SPP Layer (Staging): Pricelist uploads and validation
- CORE Layer (Canonical): Normalized master data
- SERVE Layer (Reporting): Read-optimized views
GET /api/core/selections/active- Get active selectionPOST /api/core/selections/[id]/activate- Activate selectionGET /api/core/selections/[id]/items- Get selection items
GET /api/serve/nxt-soh- NXT Stock on Hand (selected items only)
POST /api/spp/upload- Upload pricelistPOST /api/spp/validate- Validate pricelistPOST /api/spp/merge- Merge pricelist to core
- Single Active Selection: Only one selection can be active at a time
- Selected Items Only: Stock reports show ONLY items in active selection
- Price History: SCD Type 2 tracking with valid_from/valid_to
- Supplier Product Mapping: Each supplier SKU maps to internal product
- Integration Documentation - Complete integration guide
- NXT-SPP README - API reference and technical details
- Database Schema - Schema documentation
- Type Definitions - TypeScript interfaces
npm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run lint # Run ESLint
npm run type-check # Run TypeScript type checking
npm run test # Run tests
npm run test:e2e # Run end-to-end tests# Run all tests
npm run test:all
# Run specific test suites
npm run test:component # Component tests
npm run test:api # API tests
npm run test:integration # Integration tests
npm run test:e2e # End-to-end testsYou can run the platform inside containers for both production-style testing and local development.
- Build the multi-stage image (runs
npm run buildduring the build step):docker compose build
- Provide any required environment variables (e.g.
DATABASE_URL) via your shell or a.envfile, then start the container:The application is exposed ondocker compose up
http://localhost:3000.
For a live-reloading dev server inside Docker, use the development compose file:
docker compose -f docker-compose.dev.yml up --buildThis mounts the repository into the container, installs dependencies, and runs the dev server.
Important: create a .env.local (see env.example) with a valid Neon connection string before starting, or the app will fail fast on env validation.
A .devcontainer/devcontainer.json is included. In Cursor (or VS Code) choose Dev Containers: Open Folder in Container... and select the project; the editor will attach to the docker-compose.dev.yml service and run bun install automatically.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Check the documentation
- Review the integration guide
For detailed information on query optimization, index usage, and troubleshooting slow queries, see:
Query performance metrics are available at:
- Endpoint:
GET /api/health/query-metrics - Requires authentication (admin token)
- Slow query threshold: 1000ms (configurable via
SLOW_QUERY_THRESHOLD_MS) - Query logging: Enabled by default in development
- Circuit breaker threshold: 3 consecutive failures
-
Check slow queries:
# View query metrics curl http://localhost:3000/api/health/query-metrics -
Analyze database performance:
# Connect to database psql $DATABASE_URL # Run analysis script \i scripts/analyze-slow-queries.sql
-
Enable detailed query logging:
# In .env.local QUERY_LOG_ENABLED=true LOG_QUERY_TEXT=true LOG_PARAMETERS=true SLOW_QUERY_THRESHOLD_MS=500
Run these commands periodically:
-- Update statistics
ANALYZE inventory_items;
ANALYZE suppliers;
-- Vacuum to reclaim space
VACUUM ANALYZE inventory_items;
VACUUM ANALYZE suppliers;