End-to-end manufacturing ERP for a bus body-building company. Replaces paper and Excel tracking of orders, production, inventory, workforce, QC, and finance.
- Firebase project:
pcb-operations-hub - Firestore region:
asia-south1(Mumbai) - Branding: Navy
#111D44· Gold#FCAD19 - Logo: https://www.smkpl.in/images/smk-logo-1.png
pcb-operations/
├── CLAUDE.md ← Agent instructions (auto-loaded every session)
├── AGENTS.md ← Hard rules for all AI agents
├── PLAN.md ← Phased build order (read before coding)
├── package.json ← Workspaces: ["apps/*", "packages/*"]
├── firebase.json ← Hosting → apps/web/dist
├── firestore.rules ← Role-based security rules
├── firestore.indexes.json ← Composite indexes
│
├── packages/
│ └── shared-core/ ← TypeScript library shared by web + mobile
│ └── src/
│ ├── models/ ← TypeScript interfaces for every Firestore doc
│ ├── validators/ ← Zod schemas (order, jobCard, invoice, assignment, delayEvent, warranty, serviceRequest)
│ ├── constants/ ← PRODUCTION_STAGES (14), BUS_VARIANTS, QC_ITEMS_BY_STAGE, finance (GST_RATE, REVENUE_TARGET_MONTHLY)
│ └── formatters/ ← formatDate, formatCurrency, formatStageLabel, getStageGroup, computeGstBreakdown
│
├── apps/
│ ├── web/ ← React + Vite dashboard (managers / MD)
│ │ └── src/
│ │ ├── lib/ ← firebase.ts, auth-context.tsx, query-client.ts
│ │ ├── components/ ← Shared UI: PageShell, StatCard, KanbanCard, StageTag
│ │ ├── hooks/ ← TanStack Query wrappers + cross-module seams
│ │ │ (useOrders, useJobCards, useEscalationContacts, useCostRollup, …)
│ │ ├── demo/ ← VITE_DEMO_MODE offline sample data + in-memory store
│ │ └── modules/ ← One folder per feature: orders, production, inventory,
│ │ workforce, quality, finance, aftersales, reports, dashboard
│ │
│ ├── mobile/ ← Flutter app (floor workers)
│ │ └── lib/
│ │ ├── core/ ← Router (GoRouter), theme, shared widgets
│ │ ├── data/models/ ← json_serializable Dart models
│ │ └── features/
│ │ ├── attendance/ ← LIVE in production — do not modify
│ │ ├── auth/
│ │ ├── dashboard/
│ │ ├── production/ ← Phase 2: stage sign-off
│ │ ├── inventory/ ← Phase 3: material issue
│ │ ├── employees/
│ │ └── reporting/
│ │
│ └── functions/ ← Cloud Functions (Phase 4+, requires Blaze)
│ └── src/
│ ├── onStageComplete.ts ← Auto-advances job card when QC passes
│ └── onDelayDetected.ts ← Daily scheduled delay flagging
│
└── scripts/
└── seed-demo-data.ts ← Seeds Firestore with demo customers, orders, job cards
| Layer | Technology |
|---|---|
| Web dashboard | React 19 + Vite + TypeScript 6 + Tailwind CSS 4 |
| Web state | TanStack Query 5 |
| Web routing | React Router v7 |
| Mobile | Flutter + Riverpod + GoRouter + json_serializable |
| Shared logic | TypeScript (@pcb/shared-core) |
| Database | Firebase Firestore |
| Auth | Firebase Auth — email/password only |
| Hosting | Firebase Hosting |
| Cloud Functions | Firebase Functions (Phase 4+, Blaze required) |
| Validation | Zod (in shared-core) |
| Image storage | Base64 strings in Firestore (no Cloud Storage — cost decision) |
Go to console.firebase.google.com, create a new project.
Project settings → Your apps → click </> → register the app → copy the config snippet.
Build → Authentication → Get started → Email/Password → Enable → Save.
Build → Firestore Database → Create database → Start in test mode → region asia-south1 → Done.
VITE_FIREBASE_API_KEY=your_api_key
VITE_FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your_project_id
VITE_FIREBASE_STORAGE_BUCKET=your_project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id
VITE_FIREBASE_APP_ID=your_app_id
- Firebase Console → Authentication → Add user →
admin@pcb.com/pcb@123456→ copy the UID - Firestore → create collection
employees→ document ID = that UID → fields:
| Field | Type | Value |
|---|---|---|
role |
string | admin |
name |
string | Admin User |
email |
string | admin@pcb.com |
branchId |
string | branch-001 |
- Node.js via nvm (recommended)
- Flutter SDK (for mobile)
- Firebase CLI:
npm install -g firebase-tools
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts# From repo root
npm install
cd apps/web
npm run dev
# → http://localhost:5173Demoing without Firebase? Set
VITE_DEMO_MODE=trueinapps/web/.env.localto run the web dashboard entirely on local sample data — no real login or Firestore required. Seeapps/web/README.md→ "Demo Mode" for details.
cd apps/mobile
flutter pub get
flutter run- Root
package.jsonwith npm workspaces packages/shared-core— models, validators, constants, formattersapps/web— React + Vite shell with routing, Firebase singleton, TanStack Query config- Flutter app moved into
apps/mobile/with git history preserved firestore.rulesandfirestore.indexes.jsonpromoted to repo root
- Login page (Firebase Auth, email/password)
- Customer management (create, list)
- Bus order creation, list view with status filter, order detail with status updates
- Firestore:
customers,orders - Seed script: 4 customers + 10 orders with realistic PCB data
- Horizontal-scroll Kanban board (one column per production stage) — every active bus is a card
- Job card creation linked to an order
- Stage detail view: QC pass/fail, defect notes, advance stage
- Visual stage-by-stage progress timeline
- Atomic batch write: all stage documents initialised when a job card is created
- Stage count was originally 12; migrated to the client's real 14-stage process (see below)
- Flutter (worker mobile): My Jobs screen, Stage Sign-Off (details → photo → confirm)
- Firestore:
jobCards,jobCards/{id}/stages
- Stock register with search, category filter, low-stock highlight
- Material issue form linked to job card + stage (Firestore transaction: read → check qty → decrement → create issue record)
- Low-stock alert banner on stock register
- Material cost breakdown on job card detail
- Flutter: material issue screen with job card and stage pickers
- Firestore:
inventory,materialIssues,vendors - Seed script: 4 vendors + 10 inventory items (3 below reorder level for demo)
- Per-stage QC checklists (predefined checklist items from
QC_ITEMS_BY_STAGEin shared-core) - Defect photo logging (base64), rework tracking (failed → rework → re-inspect)
- Cloud Functions written but not deployed (requires Blaze upgrade):
onStageComplete— auto-advancesjobCard.currentStagewhen QC passesonDelayDetected— daily scheduled function to flag delayed job cards, now also logs adelayEvent
- Manual "Advance Stage" button remains active until functions are deployed
- Firestore:
qcChecklists
PRODUCTION_STAGESexpanded to the client's actual 14-stage floor process; field renamedno→stageNoeverywheregetStageGroup(stageNo)added — buckets stages into the coarser BASE(1–7)/FINISHING(8–11)/PNT(12)/READY(13–14) status the client already uses on paperhasAC?flag added toOrder/JobCard(vehicle variant, not yet used for conditional stage logic)
- Cost & variance table per job card: materials issued + labour (
stage.actualHours × supervisor.wageRate) vs quoted amount - GST invoices — client-side printable (
@media print), not a Cloud Function — generated from an order, GST breakdown viacomputeGstBreakdown() - MD Command Center dashboard: buses by stage-group, on-time %, revenue vs a configured monthly target, low-stock alerts — one-time reads only, no listeners
- Firestore:
invoices
- Employee directory with checked-in-today badges (reads the mobile app's
attendancecollection) - Per-worker profile with assignment history (
/workforce/:workerId) - Assign / unassign workers to a job card's current stage, with an audit-trail
assignmentssubcollection (jobCards.assignedWorkers[]stays a cache, kept in sync in the same batch write) - "Who do I call" escalation panel on Job Card Detail — resolves the stage supervisor (falling back to the last signed-off stage), currently assigned workers, last material issuer, and last QC inspector, each down to a phone number
- Firestore:
jobCards/{id}/assignments
- Delay events logged (auto or manual) per job card, with category, note, and a responsible contact; shown and resolvable from the escalation panel
onDelayDetectedextended to also write adelayEventwhen it flags a job card delayed- After-Sales module: warranty registration against a delivered vehicle, service request logging with technician assignment and status tracking
- Status Report: client-side-printable production sheet reproducing the client's paper format (SL NO / WO.NO / CUSTOMER / VEH TYPE / 14-stage tick grid / STAGE / REMARKS)
- Firestore:
jobCards/{id}/delayEvents,warranties,serviceRequests
- Upgrade Firebase project to Blaze plan (Firebase Console → Billing)
-
firebase deploy --only functions -
firebase deploy --only firestore(rules + indexes for every collection added since the last deploy) - Once functions are live, remove the manual "Advance Stage" button in
JobCardDetail.tsx
- Full read+write parity: every web admin module (orders, production, inventory, workforce, quality, finance, after-sales, status report) rebuilt as Flutter screens, gated behind the existing
adminrole - One app, one codebase — admin screens added to existing feature folders + a new
features/admin_dashboard/, never a separate app target - Dart model mirrors for everything added since Phase 2 (
hasAC,wageRate,doneAt,Invoice,Assignment,Attendance,DelayEvent,Warranty,ServiceRequest) - Not started yet — deliberately deferred to be built last, against finished/stable shared-core models
Full phase-by-phase implementation plan and design decisions: ~/.claude/plans/ancient-frolicking-shamir.md (local, not checked into the repo).
Defined in packages/shared-core/src/constants/stages.ts. Never hardcode these elsewhere. This is an
approximation of the client's real floor process (not their full formal SOP) — expect revision once
they share it.
| # | Stage | Group |
|---|---|---|
| 1 | Chassis preparation & jig mounting | BASE |
| 2 | Underframe fabrication | BASE |
| 3 | Side frame & pillar welding | BASE |
| 4 | Roof frame fabrication | BASE |
| 5 | Body panelling | BASE |
| 6 | Flooring & insulation | BASE |
| 7 | Electrical wiring harness | BASE |
| 8 | Roof fabric / ACP (mount & fix) | FINISHING |
| 9 | Hat rack fitting | FINISHING |
| 10 | PNC & window fitting | FINISHING |
| 11 | Seat / bed fitting | FINISHING |
| 12 | Painting & finishing | PNT |
| 13 | QC inspection | READY |
| 14 | PDI & delivery | READY |
| Collection | Purpose | Added in |
|---|---|---|
employees |
User profiles + roles (admin/supervisor/worker) | Existing (mobile) |
attendance |
Daily check-in/out with selfie (base64) | Existing (mobile) |
branches |
Branch locations | Existing (mobile) |
leaves |
Leave requests | Existing (mobile) |
customers |
Bus buyer records | Phase 1 |
orders |
Bus orders (qty, variant, delivery date, status) | Phase 1 |
jobCards |
Production job per bus (stages, workers, status) | Phase 2 |
jobCards/{id}/stages |
Per-stage progress, photos, QC result | Phase 2 |
inventory |
Raw material stock levels | Phase 3 |
materialIssues |
Material consumed per job card + stage | Phase 3 |
vendors |
Supplier records | Phase 3 |
qcChecklists |
Stage QC results and defect log | Phase 4 |
invoices |
GST invoices per order | Phase 5 |
jobCards/{id}/assignments |
Audit trail of worker → stage assignments | Phase 5.5 |
jobCards/{id}/delayEvents |
Auto- and manually-logged delay events | Phase 6 |
warranties |
Warranty registration per delivered vehicle | Phase 6 |
serviceRequests |
After-sales service logging + technician assignment | Phase 6 |
- Models in shared-core only — no TypeScript interfaces defined inside component or screen files
- Module query isolation — each web module has a single
*.queries.tsfile; no module imports from another module's folder - No unfiltered Firestore listeners — all queries must filter by
branchIdor another field first (billing risk) - Web state via TanStack Query — no Redux, Zustand, or Context for server state
- Mobile state via Riverpod — no BLoC, Provider, or GetX
- Base64 images only — selfies, QC photos, stage photos stored as base64 strings in Firestore; no Firebase Storage
- Email/password auth only — no Phone Auth (cost decision)
- Cloud Functions in Phase 4+ only — requires Blaze plan; do not add Functions code before then
# Web (from apps/web/)
npm run dev # local dev server → localhost:5173
npm run typecheck # tsc --noEmit (must show 0 errors before commit)
npm run build # production build → dist/
# Shared core (from packages/shared-core/)
npm run build # compile TypeScript
npm run typecheck
# Mobile (from apps/mobile/)
flutter analyze # must show 0 errors before commit
dart run build_runner build # run after any model change
flutter build apk --debug
# Firebase (from repo root)
firebase deploy --only firestore # deploy rules + indexes
firebase deploy --only hosting # deploy web app
firebase deploy # deploy everything| Route | Module | Status |
|---|---|---|
/login |
auth | Live |
/dashboard |
dashboard | Live |
/orders |
orders | Live |
/production |
production | Live |
/inventory |
inventory | Live |
/quality |
quality | Live |
/workforce |
workforce | Live |
/finance |
finance | Live |
/aftersales |
aftersales | Live |
/reports |
reports (Status Report) | Live |
| Route | Screen | Status |
|---|---|---|
/home |
Company Dashboard | Live |
/attendance |
Attendance hub + check-in | Live |
/production |
Active buses list | Live |
/my-jobs |
Worker's assigned job cards | Phase 2 |
/my-jobs/:jobId/signoff/:stageNo |
Stage sign-off flow | Phase 2 |
/inventory/issue |
Material issue screen | Phase 3 |
/employees |
Employee directory | Live |
/reports |
Daily reports | Live |