From 83cee9640d2427362929c78d3f2a03ad0f3366e3 Mon Sep 17 00:00:00 2001 From: ngqile Date: Thu, 26 Nov 2026 15:30:33 +0800 Subject: [PATCH] docs: phase 1 foundation and lead tracking design Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- ...-26-co-lite-foundation-and-leads-design.md | 183 ++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md diff --git a/docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md b/docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md new file mode 100644 index 0000000..8623ab1 --- /dev/null +++ b/docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md @@ -0,0 +1,183 @@ +# Co-Lite Phase 1 — Foundation and Lead Tracking + +Date: 2026-11-26 +Status: Draft for approval + +## Intent + +Co-Lite is an event CRM for one company, cloned from Tastefully (Solvway platform). Go-live is 15 January 2027, seven weeks from this design, with two developers. + +Success on go-live day is one thing: **staff can track leads at an event.** A salesperson keys a lead into the admin portal during an event. The system tells them whether the person is new or already known. Sales can then work through their leads after the event. Everything else on the feature list waits for later phases. + +Nothing is deployed yet. Phase 1 is built to run end to end on a developer machine first, then deployed to the team's own Kubernetes cluster before go-live. + +## Goals + +- One repository that holds the Co-Lite backend modules, the admin portal and the customer portal, and runs locally with one command. +- Admin portal (Next.js, modelled on babyboo's `solvway-admin-portal`) with staff login, users and roles, events, leads and event leads. +- Lead capture with New/Existing detection, a salesperson assigned per lead per event, and follow-up tracking. +- New tables carry a company id. +- Key-in form and Event Leads Listing usable on a phone or iPad at the event. +- Deployed to the team's Kubernetes cluster by go-live. + +## Non-goals (phase 1) + +- WhatsApp inbox. It becomes its own service in a later phase. Start Meta business verification now; it needs no code. +- Vouchers, partners and partner vouchers, pop-up and featured ads, product flyers, Spin & Win, Blindbox, achievement board, notifications. +- Member-app changes. The customer portal is copied in but not stripped or re-skinned in phase 1. +- Visitor self-registration as a lead, and linking leads to members. +- Merging duplicate leads. +- Per-salesperson visibility. All staff see all leads. +- Importing existing leads. The user confirmed none exist; every lead on 15 January starts as NEW. +- Audit log of lead changes (my call: rows keep updated_by / updated_at; babyboo's audit pipeline is ported later). + +## Anti-goals + +- A lead captured twice as two records because staff typed the same phone in another format. +- A New/Existing flag that changes after capture. It records what was true at that event. +- Porting Tastefully screens that do not serve lead tracking "while we're at it". +- Deploying or extending the Tastefully Thymeleaf backoffice. + +## Constraints + +- Java 21, Spring Boot 3.2, Maven multi-module, MySQL (one schema per service), Redis, Google Pub/Sub. These are inherited from Tastefully. +- Schemas are managed by hand-written DDL (no `ddl-auto`, no Flyway). DDL lives in the OpenSpec change folder. +- `mobile-api` has no tables. It calls services through `solvway-api-gateway`. Every admin screen needs an `/api/admin/**` endpoint in `mobile-api` plus the service endpoints behind it. +- Admin portal stack follows babyboo: Next.js 16, React 19, TanStack Table, Vitest. +- Treat any reachable database as production: read-only. +- Production runs on the team's own Kubernetes cluster. Google Pub/Sub stays (reached from the cluster with a service-account key; emulator locally). My call: replacing Pub/Sub touches about 12 modules and does not fit phase 1. +- Staff key leads in on phones and iPads, so the screens they use at the event must work at those sizes. + +## Approaches considered + +| | Approach | Trade-off | +|---|---|---| +| **A (chosen)** | One repo with a trimmed copy of Tastefully. Leads live in `services-counter`, next to `Event` and `EventAttendance`. | Cheapest. No new service. Event and lead data share one schema, so listings are plain joins, and the Event Leads Listing can follow the attendance listing pattern. Cost: `services-counter` stays a broad service of about 50 tables. | +| B | Same repo, leads in a new `services-lead`. | Cleaner boundary, but about 2 extra days of setup (Dockerfile, gateway route, local profile, schema), plus a batched cross-service call for event names. Too costly against seven weeks. | +| C | Collapse services into one application. | A rewrite. Does not fit the timeline. | + +The user picked A. + +## Decisions + +### Repository layout + +One git repository (`co-lite`), matching Tastefully and babyboo: + +``` +co-lite/ + solvway-core-libs/ + solvway-core-session/ + solvway-api-gateway/ + solvway-mobile-api/ + solvway-services-auth/ + solvway-services-system/ admin users, roles, modules/menus + solvway-services-counter/ events, attendance, leads, event leads + solvway-services-member/ + solvway-services-log/ + solvway-services-email/ password reset and notices + solvway-admin-portal/ from babyboo, cut down + solvway-customer-portal/ from Tastefully, untouched in phase 1 + local/ docker-compose and seed data + docs/ openspec/ +``` + +**Dropped:** bonus, stockist, inventory, payment, payment-gateway, job-bonus, job-flush-pending-sales, job-parse-tree, member-portal, stockist-portal, services-css, services-drive, services-report, services-staff, api-mobile-gateway, backoffice. + +The backoffice is read in place at `~/Projects/tastefully` for business rules. It is not copied. + +**Porting rule:** remove whole modules only. Inside a kept module, remove code only where it will not compile or start without a dropped module. That includes gateway routes and Pub/Sub subscriptions that point at dropped services. No other trimming in phase 1. + +### Local environment + +- `local/docker-compose.yml` runs MySQL, Redis and the Pub/Sub emulator. +- Each kept Java module gets a `local` Spring profile pointing at them. +- The Next.js apps run with `npm run dev` against the local gateway. +- Every kept module and both Next.js apps get a Dockerfile (most exist already) so the same images run locally and on Kubernetes. +- One documented command brings the stack up. A seed script creates the schemas and the minimum reference data: one company, an admin user, roles and menus. + +### Deployment + +The last phase 1 change deploys to the team's Kubernetes cluster: images, manifests, secrets (DB, Redis, Pub/Sub key, SMTP), ingress with TLS and a domain, and real SMTP for password reset. Only after the local stack works end to end. Cluster specifics (registry, ingress controller, MySQL hosting) are gathered when that change is written. + +### Who is a salesperson + +A salesperson is an admin-portal user (`services-system` User) with a Sales role. They key leads in themselves, so they need a login anyway. This is why `services-staff` is dropped. + +### Admin portal + +Start from babyboo's `solvway-admin-portal`: shell, auth, role-based menus and table components. Remove every babyboo screen not listed here. + +The event-floor screens (Event Leads Listing, key-in form, event lead edit, lead detail) are responsive down to phone width: the listing collapses to cards, the key-in form is a single column with large touch targets and the right keyboard for phone and email fields. Back-office screens (users, roles, events, interests) stay desktop-first. + +Phase 1 screens: +1. Login, first-login password change, forgot/reset password. +2. Users: list, create, edit, deactivate, assign roles. +3. Roles: list, create, edit permissions. +4. Events: list, create, edit. Keep only the fields Co-Lite needs from Tastefully's event model. +5. Lead Listing. +6. Event Leads Listing, with the key-in form. +7. Lead detail: the lead's fields plus their event history. +8. Interests: manage the product/service list used to tag leads. + +`mobile-api` gains the matching `/api/admin/**` controllers. Adapt them from babyboo's AdminAuth, AdminUser and AdminRole controllers onto Tastefully's `services-system`. AdminEvent is built new against Tastefully's event model, because babyboo's version does not match it. + +### Lead data model (in `services-counter`) + +**lead** (one row per person) +- id, uuid, company_id +- name, mobile_e164 (nullable), email_normalised (nullable), company_name, job_title, notes +- created_by, created_at, updated_by, updated_at +- At least one of mobile or email is required. +- Indexed, not unique: (company_id, mobile_e164) and (company_id, email_normalised). My call: a shared office or family phone must not block capturing a real person. + +**event_lead** (one row per lead per event) +- id, uuid, company_id, event_uuid, lead_uuid +- salesperson_user_id (nullable) +- lead_type: NEW or EXISTING, set at capture and never recalculated +- temperature: HOT, WARM or COLD +- status: OPEN, CONTACTED, QUALIFIED, WON or LOST +- next_follow_up_date, notes +- captured_by, captured_at, updated_by, updated_at +- Unique (event_uuid, lead_uuid). + +**interest** (admin-managed list): id, company_id, name, active, sort_order. + +**event_lead_interest**: event_lead_id, interest_id. + +### Capture and matching rules + +1. Staff enter mobile and/or email. The mobile is normalised to E.164, defaulting to the Malaysian country code (+60) when no country code is given. The email is trimmed and lowercased. +2. The system looks for leads matching either value within the company. + - **No match:** a new lead is created, and the event lead is marked NEW. + - **One or more matches:** staff pick the matching person, or choose "different person", which creates a new lead (NEW) carrying the same value. + - **Picked a match:** The event lead is marked EXISTING. If staff entered details the lead did not have, they fill the blanks; existing values are not overwritten. + - Mobile and email matching different leads is the same case: all candidates are shown and staff pick one. No automatic merge. +3. A lead already captured at this event cannot be captured again. The form opens the existing event lead instead. +4. A lead is EXISTING if it existed before this capture, at any event or entered any other way. + +### Listings + +- **Lead Listing:** all leads. Search by name, mobile or email. Each row shows the number of events, the last event and the latest salesperson. Paginated server-side. CSV export. +- **Event Leads Listing:** one event's leads. Columns: name, mobile, email, NEW/EXISTING, salesperson, temperature, status, interests, next follow-up. Filters: salesperson, temperature, status, interest, NEW/EXISTING. Paginated server-side. CSV export. +- Event lead edits: salesperson, temperature, status, interests, next follow-up and notes. +- Lead edits (lead detail page, edit permission): name, mobile, email, company, job title, notes. Same normalisation as capture. If the new mobile or email belongs to another lead, the other lead is shown as a warning; the save is allowed and nothing is merged (my call). + +### Access + +- All staff with lead access see all leads. +- Permissions follow babyboo's per-screen module access (`@AdminModule` plus module-to-role mapping), since the portal comes from babyboo. Separate modules for view leads, edit leads, export leads, manage interests, manage events, manage users/roles (my call). +- Export is a separate permission because it moves customer data out of the system. + +### Company id + +New tables (lead, event_lead, interest, event_lead_interest) carry `company_id NOT NULL`. Tastefully's admin `user` has no company field, so phase 1 adds a `company_id` column to it (my call; the only change to an existing table) and a small `company` table in `services-system`. The seed creates one company and assigns every user to it. Lead APIs take the company id from the logged-in user, never from the request. + +## Left to the builder + +- Which Tastefully event fields to keep in the Co-Lite event form, read from `solvway-backoffice` event templates. +- Exact permission names, following existing ROLE_* naming. +- Table component reuse and page layout, following babyboo. +- The phone normalisation library. Check whether one is already present before adding one. +- Whether to keep babyboo's login-lockout and session-policy screens; they depend on endpoints Tastefully's `services-system` lacks. Default: drop. +- The OpenSpec change split. Suggested: (1) repo setup and local stack, (2) admin auth, users and roles, (3) events, (4) leads and event leads, (5) Kubernetes deployment.