A comprehensive web application for generating Supply Chain Navigator Excel templates with multi-user authentication, environment management, and dynamic data visualization. Built for supply chain professionals to create and manage demo data efficiently.
- User Registration & Login: Secure JWT-based authentication
- Environment Management: Multi-tenant architecture with isolated data environments
- Role-Based Access Control: Admin and standard user roles
- User Profile Management: Personal settings and environment switching
- Session Management: Persistent sessions with automatic renewal
- Multi-step Wizard: Guided template creation process
- Region & City Selection: Choose specific locations for analysis with country filtering
- Product Selection: Raw materials and finished goods with category filtering
- Custom Routes: Define custom supply chain routes and configurations
- Period Configuration: Multiple reporting timeframes
- Professional Excel Export: Generate formatted Excel templates with ExcelJS
- Interactive Visualization: Visual product relationship mapping (under development)
- Category Filtering: Filter by product categories and types
- Product Dependencies: Map raw materials to finished goods
- Dynamic Layout: Relationship network visualization
- Master Data CRUD: Manage regions, cities, products, and periods
- Environment Isolation: Each environment has its own data + shared system data
- Pagination & Filtering: Efficient data browsing (25 items/page)
- Bulk Operations: Import multiple records via CSV
- Data Cleanup: Detect and resolve duplicates/inconsistencies
- Analytics Dashboard: Visual insights into data distribution
- Data Distribution Charts: Visualize products by category and type
- Environment Statistics: Track data across environments
- Real-time Metrics: Active users and system health
- Framework: React 18 with TypeScript
- Build Tool: Vite for fast development and HMR
- UI Library: Shadcn/ui components with Radix UI primitives
- Styling: Tailwind CSS with custom theme
- State Management: React Context (Auth, Data Visibility, WebSocket)
- Routing: React Router v6 for SPA navigation
- Forms: React Hook Form with Zod validation
- Charts: Recharts for analytics visualization
- Runtime: Node.js with ES modules
- Framework: Express.js RESTful API
- Database: SQLite with better-sqlite3 (synchronous)
- Authentication: JWT tokens + bcrypt password hashing
- Excel Generation: ExcelJS for template creation
- Session Storage: File-based admin sessions with expiration
- Clone the repository
git clone <repository-url>
cd SCNavigatorDemoDataGenerator- Install frontend dependencies
npm install- Setup backend
cd backend
npm install
npm run init-db-safe- Start development servers
Backend (Terminal 1):
cd backend
npm run devFrontend (Terminal 2):
npm run dev- Access the application
- Frontend: http://localhost:5173 (Vite default) or http://localhost:8080
- Backend API: http://localhost:3001
- Health Check: http://localhost:3001/api/health
- Initial User Setup
- Users must be created by administrators through the User Management interface
- Use the admin authentication for initial access to create the first users
- Default admin password can be set during database initialization
The application is configured for Ubuntu with Nginx reverse proxy:
- Build the application
npm run build- Deploy using Ubuntu script
chmod +x deploy-ubuntu.sh
sudo ./deploy-ubuntu.sh- Configure Nginx
- The
nginx-sc-nav-template-generator.conffile is provided - Update domain name and SSL certificates as needed
- Copy to
/etc/nginx/sites-available/ - Create symlink in
/etc/nginx/sites-enabled/ - Enable required modules (proxy_pass, headers)
sudo ln -s /etc/nginx/sites-available/nginx-sc-nav-template-generator.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx- Start backend in production
cd backend
npm start
# Or use PM2 for process management:
pm2 start backend/start-production.js --name sc-navigator-apiSCNavigatorDemoDataGenerator/
βββ src/ # Frontend source code
β βββ components/ # React components
β β βββ admin/ # Admin console data tables
β β β βββ CitiesTable.tsx
β β β βββ RegionsTable.tsx
β β β βββ ProductsTable.tsx
β β β βββ PeriodsTable.tsx
β β β βββ EnvironmentManagement.tsx
β β β βββ UserManagement.tsx
β β βββ auth/ # Authentication components
β β β βββ LoginForm.tsx
β β βββ ui/ # Shadcn UI components
β β βββ ReportGenerator.tsx # Main Excel generator
β β βββ DataRelationships.tsx # Product relationships
β β βββ AdminConsole.tsx # Data management console
β β βββ AnalyticsDashboard.tsx # Analytics & charts
β β βββ DataCleanup.tsx # Data quality tools
β β βββ UserProfile.tsx # User profile management
β β βββ ExcelPreview.tsx # Excel preview component
β βββ contexts/ # React contexts
β β βββ AuthContext.tsx # Authentication state
β β βββ DataVisibilityContext.tsx # Data visibility
β β βββ WebSocketContext.tsx # WebSocket connections
β βββ lib/ # Utilities and API client
β β βββ api.ts # API client
β β βββ bulk-utils.ts # Bulk operations
β β βββ utils.ts # Utility functions
β βββ hooks/ # Custom React hooks
β βββ pages/ # Page components
β βββ main.tsx # Application entry point
βββ backend/ # Backend API server
β βββ lib/ # Core libraries
β β βββ database.js # Main database queries
β β βββ user-database.js # User & environment queries
β β βββ schema-checker.js # Safe DB initialization
β β βββ excel-generator.js # Excel template generation
β βββ routes/ # API routes
β β βββ auth.js # Authentication endpoints
β β βββ auth-simple.js # Simple auth (legacy)
β β βββ users.js # User management
β β βββ environments.js # Environment management
β βββ middleware/ # Express middleware
β β βββ auth.js # JWT authentication middleware
β βββ scripts/ # Database scripts
β β βββ init-db.js # Initialize database
β β βββ init-db-safe.js # Safe init (recommended)
β β βββ add-cities.js # Add city data
β βββ server.js # Main Express server
β βββ start-production.js # Production startup
β βββ database.sqlite # SQLite database file
βββ public/ # Static assets
β βββ Template SC Navigator.xlsx # Excel template
βββ dist/ # Built frontend (generated)
βββ deploy-ubuntu.sh # Ubuntu deployment script
βββ nginx-sc-nav-template-generator.conf # Nginx config
βββ database.sqlite # SQLite database (root - optional)
- Login:
POST /api/auth/login- User login (returns session token) - Current User:
GET /api/auth/me- Get current user info (requires auth) - Logout:
POST /api/auth/logout- User logout (requires auth) - Update Profile:
PUT /api/auth/profile- Update user profile (requires auth) - Change Password:
POST /api/auth/change-password- Change password (requires auth) - Cleanup Sessions:
POST /api/auth/cleanup-sessions- Remove expired sessions
- Admin Login:
POST /api/admin/auth- Admin password authentication - Admin Session:
GET /api/admin/me- Validate admin session - Admin Logout:
POST /api/admin/logout- Clear admin session
- List Users:
GET /api/users- Get all users - Get User:
GET /api/users/:id- Get user by ID - Create User:
POST /api/users- Create new user - Update User:
PUT /api/users/:id- Update user - Delete User:
DELETE /api/users/:id- Delete user - Toggle User:
PUT /api/users/:id/toggle- Activate/deactivate user
- List All:
GET /api/environments- Get all environments (admin) - My Environments:
GET /api/environments/my- Get user's environments - Get Environment:
GET /api/environments/:id- Get environment details - Create:
POST /api/environments- Create new environment (admin) - Update:
PUT /api/environments/:id- Update environment (admin) - Delete:
DELETE /api/environments/:id- Soft delete (admin) - Hard Delete:
DELETE /api/environments/:id/permanent- Permanent delete (admin) - Assign User:
POST /api/environments/:id/users/:userId- Assign user to environment - Remove User:
DELETE /api/environments/:id/users/:userId- Remove user from environment
- Regions:
GET /POST /PUT /DELETE /api/regions[/:id] - Cities:
GET /POST /PUT /DELETE /api/cities[/:id]- Get by region:
GET /api/cities/region/:regionId - Random cities:
GET /api/cities/region/:regionId/random/:count?country=X
- Get by region:
- Products:
GET /POST /PUT /DELETE /api/products[/:id]- By category:
GET /api/products/category/:category - By product category:
GET /api/products/product-category/:productCategory - By type:
GET /api/products/product-type/:productType
- By category:
- Periods:
GET /POST /PUT /DELETE /api/periods[/:id] - Product Categories:
GET /api/product-categories
- Generate Template:
POST /api/generate-excel- Body:
{ regionId, cityIds, productIds, rawMaterialIds, finishedGoodIds, periodIds, cityCount, cdcCount, ldcCount, fgCount, rmCount, prodCount, includeBaseCase, customRoutes } - Returns: Excel file (.xlsx)
- Body:
- Merge Duplicates:
POST /api/admin/merge-duplicates - Dismiss Duplicates:
POST /api/admin/dismiss-duplicates - Get Dismissed:
GET /api/admin/dismissed-duplicates
- Health Check:
GET /api/health- Server status
- React 18 + TypeScript
- Vite - Lightning-fast build tool with HMR
- Tailwind CSS - Utility-first CSS framework
- Shadcn/ui - High-quality accessible components
- Radix UI - Unstyled accessible primitives
- Lucide React - Beautiful icon library
- React Router v6 - Client-side routing
- React Hook Form - Performant form validation
- Zod - TypeScript-first schema validation
- Recharts - Composable charting library
- TanStack Query - Data fetching and caching
- Node.js (ES Modules)
- Express.js - Web framework
- SQLite + better-sqlite3 - Embedded database
- ExcelJS - Excel file generation
- bcrypt - Password hashing
- jsonwebtoken - JWT authentication
- CORS - Cross-origin resource sharing
- ESLint - Code linting
- TypeScript - Type safety
- Nodemon - Auto-restart dev server
- PostCSS - CSS processing
- Autoprefixer - CSS vendor prefixing
- Session Authentication: Secure token-based authentication with 24-hour expiration
- Password Hashing: bcrypt with salt rounds for password security
- Admin Sessions: File-based sessions with 8-hour expiration
- User Sessions: Database-stored sessions with automatic cleanup
- Role-Based Access Control: Admin and user roles with granular permissions
- Environment Isolation: Multi-tenant data separation for secure data segregation
- Input Validation: Server-side validation for all inputs
- SQL Injection Protection: Prepared statements with better-sqlite3
- CORS Configuration: Configurable origin restrictions
- Secure Middleware: Authentication middleware for protected routes
The application uses SQLite with the following tables:
- users - User accounts (id, username, email, password_hash, role, is_active)
- environments - Data environments (id, name, description, is_deleted)
- user_environments - User-environment relationships with roles
- regions - Geographic regions (id, name, code, environment_id, is_system_data)
- cities - Cities (id, name, region_id, latitude, longitude, country, environment_id, is_system_data)
- products - Product catalog (id, name, product_category, product_type, environment_id, is_system_data)
- periods - Reporting periods (id, label, start_date, end_date, environment_id, is_system_data)
- product_categories - Product categorization metadata
- product_relationships - Product dependencies and connections
- dismissed_duplicates - Data cleanup decisions (entity_type, entity_ids)
- admin_auth - Admin password authentication (for simple auth mode)
- Secure user registration and login
- JWT-based authentication with automatic token refresh
- Role-based permissions (Admin, User)
- User profile management
- Active/inactive user toggling
- Session persistence across browser restarts
- Multi-tenant architecture for data isolation
- Users can be assigned to multiple environments
- Each environment has its own data + shared system data
- Environment-scoped CRUD operations
- Admin can create, manage, and delete environments
- Seamless environment switching from user profile
- Multi-step wizard with validation
- Region selection with country filtering
- Dynamic city selection (manual or auto-count)
- Raw materials and finished goods selection
- Multiple period support
- Custom route definition
- Base case inclusion option
- Professional Excel output with formatted sheets
- Full CRUD operations for all entities
- Pagination (25 items/page) with search
- Environment-scoped data visibility
- Bulk CSV import (under development)
- Real-time data analytics
- Product relationship visualization
- Data cleanup tools for duplicates
- Product distribution by category and type
- Environment statistics
- Visual charts and graphs
- Data quality insights
- System health metrics
- Automatic duplicate detection
- Bulk selection and merging
- Master record selection
- Dismiss false positives
- Persistent cleanup decisions
- Cross-entity duplicate detection
- Frontend: Code splitting, lazy loading, Vite optimized bundles
- Backend: Synchronous SQLite (better-sqlite3), efficient queries
- Database: Proper indexing on foreign keys and search fields
- Caching: JWT token caching, API response optimization
- Build: Production mode with minification and tree-shaking
The backend includes comprehensive endpoints for all features. Test using:
- Postman/Insomnia for API testing
- Browser DevTools for debugging
- Check backend console for detailed logs
# Initialize database safely (recommended)
npm run init-db-safe
# Full initialization (drops existing data)
npm run init-db
# Add city data
node backend/scripts/add-cities.js-
Port already in use
# Windows netstat -ano | findstr :3001 taskkill /PID <PID> /F # Linux/Mac lsof -ti:3001 | xargs kill -9
-
Database locked errors
- Close any database browsers (DB Browser for SQLite)
- Restart the backend server
-
Session token expired
- User sessions expire after 24 hours
- Admin sessions expire after 8 hours
- Simply log in again to get a new session token
-
Environment data not showing
- Ensure user is assigned to the environment
- Check environment_id in user context
- System data (environment_id = 1) is shared across all environments
-
Excel generation fails
- Verify region, cities, and products are selected
- Check backend console for detailed error messages
- Ensure at least one product is selected
PORT=3001 # Server port (default: 3001)
NODE_ENV=production # Environment modeAPI endpoint is configured in src/lib/api.ts:
const API_URL = 'http://localhost:3001/api';- Backend README: See
backend/README.mdfor detailed API documentation - API Endpoints: Comprehensive list above
- Database Schema: Defined in initialization scripts
- Component Library: Shadcn/ui documentation at ui.shadcn.com
The schema is managed through initialization scripts:
backend/scripts/init-db-safe.js- Safe schema updates (recommended)backend/scripts/create-user-system-schema.sql- User system SQL schema
Built with Shadcn/ui - a collection of re-usable components:
- Fully accessible (Radix UI primitives)
- Customizable with Tailwind CSS
- Consistent design system
- Located in
src/components/ui/
npm run build # Production build
npm run build:dev # Development build
npm run preview # Preview production buildcd backend
npm start # Start server
# Or use PM2:
pm2 start start-production.js --name sc-navigator
pm2 save
pm2 startupThis project is provided "as is" without ongoing support or warranties. See LICENSE.md for full terms and conditions.
For issues, questions, or feature requests, please contact the development team.
SC Navigator Demo Data Generator - Empowering supply chain professionals with multi-tenant data management and professional Excel template generation. π§β¨