Skip to content
Mayaskara25Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Prakash Coach Builders ERP — SMK Group

End-to-end manufacturing ERP for a bus body-building company. Replaces paper and Excel tracking of orders, production, inventory, workforce, QC, and finance.


Monorepo Structure

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

Tech Stack

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)

Firebase Setup (first-time)

1. Create a Firebase project

Go to console.firebase.google.com, create a new project.

2. Add a Web app

Project settings → Your apps → click </> → register the app → copy the config snippet.

3. Enable Authentication

Build → Authentication → Get started → Email/Password → Enable → Save.

4. Create Firestore database

Build → Firestore Database → Create database → Start in test mode → region asia-south1 → Done.

5. Create apps/web/.env.local

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

6. Create the first admin user

  1. Firebase Console → Authentication → Add user → admin@pcb.com / pcb@123456 → copy the UID
  2. 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

Getting Started

Prerequisites

  • Node.js via nvm (recommended)
  • Flutter SDK (for mobile)
  • Firebase CLI: npm install -g firebase-tools

Install nvm + Node.js (if not installed)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts

Run the web dashboard

# From repo root
npm install

cd apps/web
npm run dev
# → http://localhost:5173

Demoing without Firebase? Set VITE_DEMO_MODE=true in apps/web/.env.local to run the web dashboard entirely on local sample data — no real login or Firestore required. See apps/web/README.md → "Demo Mode" for details.

Run the mobile app

cd apps/mobile
flutter pub get
flutter run

What Has Been Implemented

Phase 0 — Monorepo Skeleton ✅

  • Root package.json with npm workspaces
  • packages/shared-core — models, validators, constants, formatters
  • apps/web — React + Vite shell with routing, Firebase singleton, TanStack Query config
  • Flutter app moved into apps/mobile/ with git history preserved
  • firestore.rules and firestore.indexes.json promoted to repo root

Phase 1 — Orders & Sales ✅

  • 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

Phase 2 — Production Tracking ✅ (demo-ready)

  • 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

Phase 3 — Inventory & BOM ✅

  • 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)

Phase 4 — Quality Control ✅ (code complete — functions not yet deployed)

  • Per-stage QC checklists (predefined checklist items from QC_ITEMS_BY_STAGE in shared-core)
  • Defect photo logging (base64), rework tracking (failed → rework → re-inspect)
  • Cloud Functions written but not deployed (requires Blaze upgrade):
    • onStageComplete — auto-advances jobCard.currentStage when QC passes
    • onDelayDetected — daily scheduled function to flag delayed job cards, now also logs a delayEvent
  • Manual "Advance Stage" button remains active until functions are deployed
  • Firestore: qcChecklists

Stage List Migration — 12 → 14 stages ✅

  • PRODUCTION_STAGES expanded to the client's actual 14-stage floor process; field renamed no → stageNo everywhere
  • getStageGroup(stageNo) added — buckets stages into the coarser BASE(1–7)/FINISHING(8–11)/PNT(12)/READY(13–14) status the client already uses on paper
  • hasAC? flag added to Order/JobCard (vehicle variant, not yet used for conditional stage logic)

Phase 5 — Finance & Costing + MD Dashboard ✅

  • 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 via computeGstBreakdown()
  • 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

Phase 5.5 — Workforce & Escalation ✅

  • Employee directory with checked-in-today badges (reads the mobile app's attendance collection)
  • Per-worker profile with assignment history (/workforce/:workerId)
  • Assign / unassign workers to a job card's current stage, with an audit-trail assignments subcollection (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

Phase 6 — Delay Events, After-Sales, Status Report ✅

  • Delay events logged (auto or manual) per job card, with category, note, and a responsible contact; shown and resolvable from the escalation panel
  • onDelayDetected extended to also write a delayEvent when 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

What Is Left To Build

Deploy actions (pending, require the Blaze plan)

  • 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

Phase 7 — Mobile Admin Mirror (Next, not yet started)

  • 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 admin role
  • 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).


The 14 Production Stages

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

Firestore Collections

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

Architecture Rules

  • Models in shared-core only — no TypeScript interfaces defined inside component or screen files
  • Module query isolation — each web module has a single *.queries.ts file; no module imports from another module's folder
  • No unfiltered Firestore listeners — all queries must filter by branchId or 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

Key Commands

# 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

Web App Routes

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

Mobile App Routes (GoRouter)

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages