NexusERP is an enterprise-grade ERP system built with a modern Monorepo architecture. It separates concerns into distinct workspaces for Frontend, Backend API, and Core Domain Logic.
This project uses npm workspaces:
apps/web: React + Vite Admin Dashboard.- Features: Users, Roles, Inventory, Orders, Audit Logs.
- Visuals: Data-dense tables, Sidebar navigation, Action Toolbars.
apps/api: Serverless Backend (Cloudflare Worker Pages).- Features: Authentication, Transactional operations (Order -> Stock), Role-based access.
- Database: PostgreSQL.
- Runtime: Cloudflare Workers with TypeScript support.
packages/core: Shared Domain Logic & Types.- Contains: Type definitions (
User,Order,Product), Pure business rules (Validation, Calculation). - Used by both Web and API apps.
- Contains: Type definitions (
- Node.js v18+
- PostgreSQL Database
- Cloudflare CLI (
npm install -g wrangler) - Cloudflare Account with Workers enabled
-
Install Dependencies:
npm install
This installs dependencies for all workspaces and links them.
-
Environment Variables: Create
.envin root:DATABASE_URL=postgres://user:pass@host:5432/dbname JWT_SECRET=your_super_secret_key
For Cloudflare Workers, set environment variables via
wrangler.tomlor Cloudflare Dashboard:wrangler secret put DATABASE_URL wrangler secret put JWT_SECRET
-
Configure Cloudflare Worker: Update
wrangler.tomlwith your Cloudflare settings:- Update
namefield to your worker name - Set
routeswith your domain/zone information - Configure
env.production.routesfor production deployment
- Update
-
Run Locally (Recommended Workflow):
-
Terminal 1 (Core Watch):
npm run dev:core # Watches @nexus/core for changes. -
Terminal 2 (API Server):
npm run dev:api # Starts Cloudflare Worker (API on 8787) -
Terminal 3 (Frontend):
npm run dev:web # Starts Vite dev server (Frontend on 5173) # Configure frontend API endpoint to http://localhost:8787/api
-
Build for Production:
npm run build
Deploy to Cloudflare Workers:
# From apps/api directory
cd apps/api
npm run deploy
# Or from root
wrangler publish
Preview Deployment:
wrangler preview
Run SQL migrations from database/schema.sql:
psql $DATABASE_URL < database/schema.sql
Seed roles:
psql $DATABASE_URL < database/seed_roles.sql
Create admin user:
node scripts/create-admin-user.ts
All API routes are prefixed with /api:
- Authentication:
/api/auth/*(login, register, change-password) - Products:
/api/products/* - Stock:
/api/stock/* - Orders:
/api/orders/*(routes to sales-orders) - Customers:
/api/customers/* - Suppliers:
/api/suppliers/* - Users:
/api/users/*(admin only) - Roles:
/api/roles/*(admin only) - Warehouses:
/api/warehouses/* - Purchase Orders:
/api/purchase-orders/* - Audit Logs:
/api/audit-logs/*(admin only) - Dashboard:
/api/dashboard/*(admin only)
- RBAC: Roles are managed in
apps/api/functions/roles.ts. - Audit Logs: Critical actions (Stock adjustments, User modifications) are logged via
audit_logstable. - Validation: Business rules (e.g., negative stock prevention) are enforced in
@nexus/core. - Secrets: Sensitive environment variables are managed via Cloudflare Secrets Manager.
- Ensure
wrangleris installed:npm install -g wrangler - Check
wrangler.tomlconfiguration - Verify Node.js version is 18+
- Verify
DATABASE_URLenvironment variable is set correctly - Ensure PostgreSQL server is accessible
- Check database credentials and connection string format
- Authenticate with Cloudflare:
wrangler login - Verify account permissions for Workers
- Check
wrangler.tomlroutes configuration - Review deployment logs:
wrangler tail