A full-stack order management API with JWT authentication, role-based access control, PostgreSQL (Prisma), and optional Ethereum blockchain hash verification.
| Layer | Technology |
|---|---|
| Runtime | Node.js + Express 5 |
| Database | PostgreSQL (Neon) + Prisma ORM |
| Auth | JWT + bcrypt |
| Validation | Zod |
| Blockchain | ethers.js (demo mode when not configured) |
| API Docs | Swagger UI at /api-docs |
| Desktop UI | Electron + vanilla JS frontend |
backend/
app.js # Express app factory (used by server + tests)
server.js # HTTP server entry point
config/ # Prisma client
controllers/ # Route handlers
middleware/ # Auth, validation, errors, RBAC
routes/ # API route definitions
validators/ # Zod schemas
swagger/ # OpenAPI component schemas
services/
blockchainService.js # Order hash storage (Ethereum or in-memory demo)
prisma/ # Schema and migrations
tests/ # Integration tests (Jest + Supertest)
frontend/ # Electron desktop client
- Node.js 18+
- PostgreSQL database (e.g. Neon)
npm install
cp .env.example .env # then edit DATABASE_URL and JWT_SECRET
npm run db:generate
npm run db:migrate
npm run devServer: http://localhost:5000
Swagger: http://localhost:5000/api-docs
DATABASE_URL="postgresql://..."
JWT_SECRET=your_secret_here
PORT=5000
# Optional blockchain (omit for demo/in-memory mode)
RPC_URL=
PRIVATE_KEY=
CONTRACT_ADDRESS=GET /health— server + database statusGET /api/ping— simple ping
POST /api/auth/register— register ascustomerorsupplieronlyPOST /api/auth/login— receive JWTGET /api/auth/me— current user profilePUT /api/auth/me— update own profile
GET /api/products— list all (public)GET /api/products/:id— get by ID (public)GET /api/products/search?q=— search by name/descriptionGET /api/products/low-stock?threshold=10— low stock alertPOST /api/products— create (admin, supplier)PUT /api/products/:id— update (owner or admin)DELETE /api/products/:id— delete (owner or admin)
GET /api/orders— list (scoped by role; customers see own only)GET /api/orders/my— current user's ordersGET /api/orders/:id— get by IDPOST /api/orders— create (admin, customer)PUT /api/orders/:id— update (admin, customer, supplier for status)POST /api/orders/:id/cancel— cancel order and restore stockDELETE /api/orders/:id— delete (admin)GET /api/orders/:id/verify— verify blockchain hash integrity
GET /api/categories— list categories (public)GET /api/categories/:id— get category (public)GET /api/categories/:id/products— products in category (public)POST /api/categories— create (admin)PUT /api/categories/:id— update (admin)DELETE /api/categories/:id— delete (admin)
GET /api/notifications— list notificationsGET /api/notifications/unread-count— unread countPATCH /api/notifications/:id/read— mark one as readPATCH /api/notifications/read-all— mark all as readDELETE /api/notifications/:id— delete notification
GET /api/inventory/summary— stock overview (admin, supplier)GET /api/inventory/movements— stock movement historyPOST /api/inventory/adjust— manual stock adjustment
GET /api/addresses— list shipping addresses (customer, admin)POST /api/addresses— add addressGET /api/addresses/:id— get addressPUT /api/addresses/:id— update addressPATCH /api/addresses/:id/default— set default addressDELETE /api/addresses/:id— delete address
GET /api/reviews/product/:productId— product reviews and rating stats (public)POST /api/reviews— create review (customer, delivered orders only)DELETE /api/reviews/:id— delete own review (or admin)
GET /api/supplier/dashboard— supplier metrics and recent ordersGET /api/supplier/products— supplier's productsGET /api/supplier/orders— orders for supplier's productsGET /api/supplier/products/:id/sales— sales stats per product
GET /api/users— list all (admin)POST /api/users— create user with any role (admin)GET /api/users/:id— get user (admin or self)PUT /api/users/:id— update (admin or self)DELETE /api/users/:id— delete (admin)
GET /api/stats/dashboard— counts, revenue estimate, recent orders
GET /api/audit-logs— order change audit trailGET /api/audit-logs/:id— single audit entry
| Role | Capabilities |
|---|---|
| customer | Own orders, addresses, reviews; cancel pending orders |
| supplier | Manage own products, update order status |
| admin | Full access including user management and stats |
npm run dev # Start API server
npm run test # Run integration tests
npm run db:migrate # Apply migrations
npm run db:studio # Prisma Studio GUI
npm run electron # Start desktop appTests use the database configured in DATABASE_URL and reset all tables before each test. Use a dedicated test database or Neon branch.
npm testMIT