0. Two-line summary
Fabric IQ is a new multi-tenant garment SaaS (fabriciq.ai / xyz.fabriciq.ai) that rebuilds FactoryTracking’s MES on Postgres and ports FactoriQ’s Buy/Demand/Risk IQ, WhatsApp, and GST patterns — sold at ₹5,000/month (yearly ~₹50,000) with a hard access gate. First paid MVP is achievable in ~8 weeks; full vision ~20–24 weeks.
Can we build it? Yes — shop-floor E2E already runs locally; subscription E2E is standard Razorpay + webhook + tenant provision; WhatsApp/GST need Meta/NIC lead time but are proven patterns in FactoriQ.
1. Product definition
Two-line summary
One product for Indian garment/fabric manufacturers: buy materials intelligently, make on the floor with QR, talk on WhatsApp, invoice buyers with GST, and pay you a subscription for the software.
Positioning table
| Layer | Today’s source | Fabric IQ |
|---|---|---|
| Cut–sew–wash–QC–pack–dispatch | FactoryTracking | Core Make (rebuild) |
| Buy / PO / vendors | FactoriQ BuyIQ | Buy IQ |
| Stock / locations | FT shallow + FQ deeper | Inventory intelligence |
| Demand / reorder AI | FactoriQ DemandIQ | Demand IQ |
| Supplier risk | FactoriQ RiskIQ | Risk IQ |
| WhatsApp ops | FactoriQ Cloud/Baileys | First-class channel |
| GST AR invoices | FactoriQ sell-side | Factory→buyer billing |
| SaaS ₹5k subscription | FT soft Stripe/Paytm | Hard Razorpay gate |
Pricing (initial)
- Monthly: ₹5,000 / factory / month (all Phase-1 features).
- Yearly: ~₹50,000 / year (≈2 months free — finalize commercially).
- Trial: 14 days, then paywall (hard).
- Later: add-ons (extra plants, WhatsApp high volume, GST live NIC support).
2. Architecture (chosen)
Two-line summary
New monorepo — Next.js UI + Express/TypeScript API + PostgreSQL + Redis — FactoriQ-style tenancy; do not ship the Flask monolith.
flowchart LR
subgraph public [Public]
Mkt["fabriciq.ai marketing"]
Rz[Razorpay]
end
subgraph tenant [Tenant]
Sub["xyz.fabriciq.ai"]
Phone["Floor phones"]
WA["WhatsApp Cloud"]
end
subgraph plat [Platform]
FE["Next.js"]
API["Express API"]
PG[(Postgres)]
Redis[(Redis)]
AI["AI service"]
end
Mkt --> Rz
Rz --> API
Sub --> FE
Phone --> FE
FE --> API
API --> PG
API --> Redis
API --> WA
API --> AI
Tenancy
- Resolve host
xyz.fabriciq.ai→tenants.slug = xyz→tenant_idon every query. - Fallback path
/t/xyzif DNS/TLS not ready. - Middleware: auth + subscription_active or trial not expired — else redirect billing.
Data
- Postgres as system of record (Neon/Supabase/RDS).
- Schema starts from Doc 1 tables, renamed
company_id→tenant_idfor consistency with FactoriQ patterns. - Migrations via Prisma or Drizzle (pick one and stick).
Why not evolve Flask?
Untested PG shim, no tests, secrets hygiene failure, Jinja UI bar, and FactoriQ modules are already TS/Python services — rewrite cost of MES domain is lower than forever maintaining the monolith.
3. End-to-end: SaaS subscription (buildable)
Two-line summary
Owner picks plan on marketing site → Razorpay charges → webhook creates tenant + admin → DNS already covers wildcard → owner logs into xyz.fabriciq.ai; every request checks subscription.
Detailed flow
sequenceDiagram
participant Owner as FactoryOwner
participant Web as MarketingSite
participant Pay as Razorpay
participant API as FabricAPI
participant App as TenantApp
Owner->>Web: View pricing Monthly or Yearly
Owner->>Web: Start trial or Pay now
alt Pay now
Web->>Pay: Create subscription
Pay->>Owner: Pay with UPI or card
Pay->>API: Webhook subscription activated
else Trial
API->>API: Create tenant with 14 day trial
end
API->>API: Insert tenant slug and admin user
API->>Owner: Email login link
Owner->>App: Login on subdomain
App->>API: Check subscription active
alt Active or trial valid
API-->>App: Allow MES
else Lapsed
API-->>App: Redirect to billing
end
Implementation checklist
- Razorpay plans:
plan_monthly_5000,plan_yearly_50000. - Webhook signature verify; idempotent tenant create.
- Tables:
tenants,subscriptions,subscription_events. - Hard middleware on all app routes except marketing, signup, webhook, billing.
- Customer portal link to manage payment method.
- Dunning: WhatsApp/email 3 days before trial end (port FT daily-notifications idea).
Trial → paid conversion
Same checkout; on success set subscription_status=active, clear trial lock. No soft access after expiry.
4. End-to-end: factory shop floor (target Fabric IQ)
Two-line summary
Same MES loop as FactoryTracking, plus WhatsApp status pings and (Phase 3) GST invoice after dispatch.
Detailed flow
flowchart TD
O["Customer order entered"] --> C["Create batch at CUTTING"]
C --> Q["Print QR label"]
Q --> S["Operator scans phone"]
S --> MV["Move with sent qty"]
MV --> WA1["WhatsApp stage alert"]
MV --> RV["Receive with received qty"]
RV --> ALERT{"Qty mismatch?"}
ALERT -->|yes| FLAG["ALERT on dashboard"]
ALERT -->|no| OK[OK]
OK --> MORE{"More stages?"}
FLAG --> MORE
MORE -->|continue| MV
MORE -->|QC| DEF["Log defect types"]
DEF --> MORE
MORE -->|PACK| PACK["Packing sheet"]
PACK --> DISP[DISPATCH]
DISP --> WA2["WhatsApp buyer Ready"]
DISP --> GST["GST tax invoice PDF"]
DISP --> REP["TV and reports"]
Stage pipeline (unchanged domain)
flowchart LR CUTTING --> STITCHING --> WASHING --> QC --> PACKING --> DISPATCH
Roles on the floor
| Role | Two-line |
|---|---|
| Administrator | Full access, users, billing, inventory. |
| Supervisor | Move/receive any stage; targets; defects. |
| Operator | Only batches in their department stage. |
| Inspector | QC focus; defects. |
| Buyer (portal) | Read-only own orders/status. |
5. End-to-end: Buy + inventory (Phase 2 target)
Two-line summary
Demand or low stock creates a requisition; Buy IQ drafts a PO to a scored mill; WhatsApp sends it; GRN receives fabric into inventory; cutting consumes BOM.
flowchart TD LS[Low stock or Demand IQ] --> RQ[Requisition] RQ --> BI[Buy IQ vendor score] BI --> PO[Purchase order] PO --> WA[WhatsApp to mill] WA --> GRN[Goods receipt] GRN --> INV[Inventory ledger] INV --> BOM[BOM consume at CUTTING] BOM --> MES[Shop floor MES]
6. Phased delivery & timeline
| Phase | Weeks | Outcome (two-line) |
|---|---|---|
| 0 Foundation | 1–2 | Repos, Postgres schema, auth, subdomain stub, Razorpay sandbox working. |
| 1 Shop-floor MVP | 3–8 | Paid factory can run cut→dispatch + QR + basic stock/BOM + hard billing + WhatsApp alerts v1. |
| 2 Buy + WA ops | 9–14 | Formal POs, fabric item fields, inbound WhatsApp floor/vendor. |
| 3 Demand/Risk/GST | 15–20 | Demand IQ, Risk IQ, GST invoices, buyer portal polish. |
| 4 Polish | 21–24 | Yearly UX, PWA, hardening, optional Tally. |
First revenue: end of Phase 1 (~8 weeks). Full vision as described: ~20–24 weeks with 1–2 senior engineers + you.
Phase 0 detail
- Create
FabricIQmonorepo (apps/web, apps/api, packages/db). - Tables: tenants, users, memberships, subscriptions, factory_stages, production_batches, movement_history, scan_logs, inventory_*, customer_orders (minimum).
- Cloudflare
fabriciq.ai+ wildcard*.fabriciq.ai. - CI: lint, typecheck, tenant-isolation tests.
Phase 1 detail (sellable)
- Onboarding + roles
- MES recreate (create/move/receive/QR/defects/targets/dashboards)
- Inventory + style BOM
- Orders + thin buyer portal
- Razorpay monthly/yearly + hard gate
- WhatsApp Cloud: low_stock + stage_move + daily_brief templates
- Marketing site pricing page
Out of Phase 1: full BuyIQ, Demand/Risk, GST IRN, roll tracking, native app.
Phase 2–4
As in Doc 2 priority table (Buy IQ → WhatsApp inbound → Demand/Risk/GST → polish).
7. Target schema notes (Postgres)
Two-line summary
Port every Doc 1 table; rename company_id → tenant_id; add subscriptions and WhatsApp/integration tables; add fabric attributes on items when Phase 2 starts.
New tables beyond FT
| Table | Two-line purpose |
|---|---|
subscriptions | Razorpay subscription id, status, period end, plan code. |
subscription_events | Webhook audit log. |
whatsapp_templates / whatsapp_messages | Outbound/inbound log (from FQ patterns). |
purchase_orders / purchase_order_lines | Formal POs (Buy IQ). |
customer_invoices | GST AR invoices. |
risk_signals / demand_forecasts | IQ modules. |
Fabric item extensions (Phase 2)
On inventory_items or fabric_rolls: gsm, width_cm, composition, shade, lot_number, roll_barcode, meters.
8. Deployment strategy
Two-line summary
Cloudflare DNS/TLS in front; managed Postgres; app on Railway/Render/Fly or a VPS; staging + prod; never commit secrets.
| Concern | Choice |
|---|---|
| DNS/TLS | Cloudflare proxy + wildcard |
| App host | Railway or Fly (or OCI if you prefer) |
| DB | Neon or RDS Postgres + nightly backup |
| Files/QR | Object storage (S3/R2) not local disk |
| Observability | Sentry + /healthz + uptime |
| Envs | dev / staging.fabriciq.ai / prod |
9. Engineering rules
- Tenant isolation on every query (automated tests).
- No secrets in git; rotate FT-exposed keys before demos.
- MES domain tests first: move/receive qty, stage permissions, subscription middleware.
- UI: one design system (Tailwind; FactoriQ look-and-feel OK).
- India-first: Razorpay, +91 WhatsApp, GST schema hooks early.
- Small PRs; do not paste entire
app.py.
10. Risks & mitigations
| Risk | Two-line | Mitigation |
|---|---|---|
| Meta template approval delay | Blocks WhatsApp alerts. | Apply week 1; ship email fallback in Phase 1. |
| Wildcard TLS pain | Subdomains fail. | Path /t/xyz fallback. |
| Scope creep | Payroll/CAD delay launch. | Enforce non-goals Doc 2. |
| Underestimate MES rewrite | Timeline slips. | Vertical slice week 3: login→batch→move→scan. |
| GST NIC complexity | Phase 3 slips. | Mock IRN first. |
11. Success metrics (first 90 days post-MVP)
| Metric | Target (example) |
|---|---|
| Paying factories | 5+ |
| Batches moved / week / factory | Measurable vs paper |
| WhatsApp alerts delivered | >95% success |
| Trial→paid conversion | Track; improve onboarding |
| Critical bugs in MES qty | Zero silent qty loss |
12. Immediate next steps (after docs approved)
- Confirm domain
fabriciq.ai+ Cloudflare. - Scaffold FabricIQ monorepo.
- Schema ADR + first migrations.
- Razorpay test subscription E2E.
- Vertical slice: subdomain login → create batch → move → QR scan.
- Start Meta Business verification in parallel.
13. FAQ
Is FactoryTracking deployed? No confirmed live URL; use as domain reference only. Is subscription E2E buildable? Yes — Razorpay + webhook + tenant + hard gate. Is shop-floor E2E buildable? Yes — already demoable locally; rebuild for production. Do we need FactoriQ monorepo as dependency? No — port patterns/modules into FabricIQ repos; keep products separate. HTML versions of these docs? Markdown is complete with Mermaid; say if you want matching single-file HTML next.
End of Doc 3.