A small-business inventory and order management system: products, customers, orders and stock, with every stock change recorded. Demo data uses a leather workshop, but nothing in the code is specific to leather.
Status: in development, milestone M4 (database + domain). Products and categories run on PostgreSQL end to end. Customers, orders, inventory, auth and deployment are still to come. See docs/progress.md.
Small workshops and shops tend to track stock in a notebook or a spreadsheet, so the numbers drift: nobody can say why a count changed, or which order used up the last of something. Workshop is a full-stack app built to keep those numbers honest.
The design choices that matter:
- Stock is backed by a ledger.
stockQuantitycan't be written through the product API. From the inventory milestone on, every change also records a stock movement in the same transaction, so each count can be explained. - Money is never a float. Prices are
numeric(12,2)in PostgreSQL and strings end to end. - Rules live on the server, with the database as backstop. Zod rejects bad or unknown input, and PostgreSQL constraints (case-insensitive unique SKUs, restricted foreign keys) catch anything that slips through.
- Archive, don't delete. Products keep their history; IDs are UUIDv7.
- Every decision is written down. The reasoning lives in docs/decisions.md.
It's being built one vertical slice at a time, each on its own branch with conventional commits.
| Layer | Tools |
|---|---|
| Frontend | React, TypeScript, Vite, React Router, TanStack Query |
| Backend | Node.js, Express 5, TypeScript, Zod |
| Database | PostgreSQL 18, Drizzle ORM + drizzle-kit migrations |
| Dev | pnpm workspaces, Docker Compose |
Browser → React (apps/web) ──/api──→ Express (apps/api) → service → repository → Drizzle → PostgreSQL
Vite dev server proxies /api to :3000
Inside the API, each layer has one job:
| Layer | File pattern | Responsibility |
|---|---|---|
| Routes | *.routes.ts |
HTTP only: parse the request, call the service, choose the status code |
| Schemas | *.schemas.ts |
Zod rules for untrusted input; unknown fields are rejected |
| Service | *.service.ts |
Business rules; translates DB errors (unique/FK violations) into API errors |
| Repository | *.repository.ts |
The only place with SQL/Drizzle queries |
Rules are enforced on the server, and PostgreSQL constraints back them up. See docs/database.md and docs/decisions.md.
apps/
api/
drizzle/ generated SQL migrations (committed)
src/
app.ts builds the Express app (routes, error handler)
index.ts starts it: app.listen()
config/env.ts validated environment variables
db/ schema, client (pool), seed, pg error helpers
errors/ AppError, error contract, error handler
validation/ parseInput(): Zod → 400 with field details
products/ routes, schemas, service, repository, types
categories/ read-only category list
test/ Vitest + Supertest API tests, setup, factories
web/
src/
app/ App, QueryClient
layouts/ AppLayout
features/ dashboard/, products/
lib/api.ts typed API client + ApiError
docs/ database, decisions, progress
Requires Node 22.9+ (uses --env-file-if-exists; developed on Node 26), pnpm, and Docker.
cp .env.example .env # local config (never committed) docker compose up -d db # PostgreSQL 18 on :5432 pnpm install pnpm --filter @workshop/api db:migrate # apply migrations in apps/api/drizzle/ pnpm --filter @workshop/api db:seed # demo data (safe to re-run) pnpm --filter @workshop/api dev # API on :3000 pnpm --filter @workshop/web dev # web on :5173
Typecheck: pnpm --filter @workshop/api typecheck (includes tests) and pnpm --filter @workshop/web exec tsc -b.
pnpm --filter @workshop/api test # run once pnpm --filter @workshop/api test:watch # re-run on save
API tests use Vitest + Supertest and run against a real PostgreSQL database, workshop_test (TEST_DATABASE_URL in .env), never the dev one:
- Before the run, the database is created if it's missing, and the real migrations are applied to it.
- Every table is truncated before each test. Each test inserts the rows it needs, then calls the API over HTTP.
- Test files run one at a time, because they share the database.
- Tests refuse to start if the database name doesn't end in
_test.
The Postgres container must be running (docker compose up -d db).
The schema lives in apps/api/src/db/schema.ts. After changing it:
pnpm --filter @workshop/api db:generate --name <what_changed> # writes a SQL migration # read the generated SQL before applying it pnpm --filter @workshop/api db:migrate pnpm --filter @workshop/api db:studio # optional: browse the DB
Commit the schema change and its migration together. Never edit a migration that has already been applied anywhere; add a new one instead.
GET /health returns { "status": "ok" } (liveness only, no DB check).
All responses are JSON. Errors share one shape:
{ "error": { "code": "SKU_TAKEN", "message": "Another product already uses this SKU",
"details": [{ "path": "sku", "message": "SKU must be unique (case-insensitive)" }] } }details is only present for field-level problems.
| Method | Path | Description | Success |
|---|---|---|---|
| GET | /api/products |
All products, with their category | 200 { products } |
| GET | /api/products/:id |
One product | 200 { product } |
| POST | /api/products |
Create: sku, name, price, optional description, categoryId |
201 { product } + Location |
| PATCH | /api/products/:id |
Partial update of the fields above, plus status (active/archived) |
200 { product } |
| GET | /api/categories |
All categories | 200 { categories } |
Notes:
-
priceis a string ("1850.00"), both in requests and in responses. Money never passes through a float. -
stockQuantityis read-only. Stock will change only through inventory adjustments, each of which records a movement. -
Error codes:
Code Status When VALIDATION_ERROR400 A field is missing, invalid, or unknown INVALID_JSON400 The request body is not valid JSON CATEGORY_NOT_FOUND400 categoryIddoesn't match a categoryPRODUCT_NOT_FOUND404 No product with that id (a malformed id also gets 404) SKU_TAKEN409 Another product already has that SKU, in any letter case INTERNAL_SERVER_ERROR500 Anything unexpected; the real error is logged on the server
Copyright © 2026 Sarwar Uddin
Workshop is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. If you run a modified version on a server, the AGPL requires you to offer its source code to the users who interact with it.