docs: archive add-repo-foundation-local-stack

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-11-26 19:10:56 +08:00
1 parent 1c77d9b63f
commit 6b2fcf5780
6 files changed
+80

No files matched your search

@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-26
@@ -0,0 +1,76 @@
# Design
## Context
See proposal.md for the motivation. The phase 1 design is in `docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md`.
What Tastefully looks like today (commit `8bd93d15`):
- There is no root pom. Each module is a standalone Spring Boot 3.2.8 app with its own parent and pulls `com.solvway.core:solvway-core-libs:${core-project.version}` (`tastefully-v1`) from `~/.m2`. Babyboo uses `babyboo-v1` at the same coordinates.
- Every service listens on port 80. The gateway resolves services by hostname from `app.services.name.*`: `service-auth`, `service-system`, `service-counter` and so on. These are the k8s service names.
- MySQL holds one schema per service (`service-system`, `service-counter`, `service-member`, `service-log`, `service-email`). Tables are managed by hand-written DDL; there is no `ddl-auto` and no Flyway. No full DDL exists in the repo.
- Config comes from environment variables: `MYSQLHOST`, `MYSQLPORT`, `MYSQLUSER`, `MYSQLPWD`, `REDISHOST`, `GCP_PROJECT`, `GCP_CREDENTIAL_FILE`, `APIGATEWAYURL` and `AES_SECRET_KEY`. mobile-api also requires `JWT_SECRET`, `APIKEY` and `AUTH_API_KEYS`.
- Added by this change when literal secrets were removed: `JWT_TOKEN` (required, must equal `JWT_SECRET`), `USER_AUTH_API_SECRET` (required), and optional `SMTP_PASSWORD`, `MAILGUN_API_KEY`, `SENDGRID_API_KEY`, `MAILJET_API_KEY`, `MAILJET_SECRET_KEY`, `JUMIO_TOKEN`, `JUMIO_SECRET`, `XXL_JOB_TOKEN`, `IPGEOLOCATION_API_KEY` and `USERSTACK_API_KEY`. The gateway reads its API keys from a mounted `/deployments/appkeys/appkeys.json`. Change 5 (k8s) must supply all of these.
- The dumped schema loads only with MySQL `log_bin_trust_function_creators=1` and `innodb_strict_mode=OFF`; change 5 must check the production server matches.
- Pub/Sub inbound adapters are declared in each service's `PubSubConfig` (system 7, counter 12, member 12, log 3, email 3). Some serve flows Co-Lite drops (stockist, Jumio, Camunda). They stay, so each subscription must exist in the emulator.
- The Dockerfiles use the base image `gitea.containerverse.dev/solvway/docker-java-21`, `ADD target/*.jar` and `-Dspring.profiles.active=$BUILD_PROFILE`.
## Goals / Non-Goals
**Goals:**
- Bring the stack up from a clean clone with two commands: build, then up.
- Use the same hostnames and ports as k8s, so change 5 reuses the images and env contract unchanged.
**Non-Goals:**
- Any admin API, lead table or portal trimming. Those belong to changes 2–4.
- Removing dead code inside kept modules beyond what stops compilation or startup.
- Running the Next.js apps inside compose. They run with `npm run dev`.
## Decisions
1. **Copy with `git archive` at pinned commits.** Tastefully `8bd93d15` and babyboo `f64d096ea`. Only tracked files come across: no `node_modules`, `target` or stray files.
- Alternative: `cp -r`. Rejected because it drags in untracked junk and possibly local secrets.
2. **Root aggregator pom.** Add a `pom.xml` with `<packaging>pom</packaging>` that lists the kept modules, with `solvway-core-libs` and `solvway-core-session` first. Module poms keep their own Spring Boot parent. The aggregator only orders the reactor, so `mvn -T 1C verify` at the root builds everything.
- Alternative: a shared parent. Rejected because it would rewrite every module pom for no phase-1 gain.
3. **core-libs version `colite-v1`.** Set it in `solvway-core-libs/pom.xml`, and set `core-project.version` in every kept module. The same applies to `solvway-core-session` if it is versioned the same way.
4. **Compose mirrors k8s.** Compose service names equal the k8s names (`service-auth`, `service-system`, `service-counter`, `service-member`, `service-log`, `service-email`, `api-gateway`, `mobile-api`). Each service listens on port 80 inside its container. Only `mobile-api` and `api-gateway` are published to the host, on 8080 and 8081.
- Images are built from the existing Dockerfiles with `BUILD_PROFILE=local`.
5. **`local` Spring profile per module.** Add an `application-local.yml` that sets `spring.cloud.gcp.pubsub.emulator-host: pubsub:8085` and `spring.cloud.gcp.project-id: co-lite-local`. It also disables the credentials-file requirement where the emulator needs that. All other values still come from the env file `local/.env.example`, with dev-only values; a copied `.env` is git-ignored.
6. **Pub/Sub emulator plus an init job.** A one-shot container creates every topic and subscription from `local/pubsub/topics.txt`, one `topic subscription` pair per line, before the services start (`depends_on: condition: service_completed_successfully`). The list is extracted from the kept modules' `PubSubConfig` classes and resolved property values.
7. **Seed from the user's Tastefully dump.** MySQL runs its official image's `/docker-entrypoint-initdb.d`. It runs only on an empty volume, which gives first-start seeding for free.
- Files, in run order:
1. `01-schema.sql`: schema-only dump of the five schemas.
2. `02-reference.sql`: reference-table rows (roles, modules/menus, system_property, location_hierarchy and other lookup tables, chosen per table).
3. `03-colite.sql`: one company and one admin user, with a bcrypt hash of a dev-only password documented in `local/README.md`.
- Reset is `docker compose down -v`.
- **Location:** `local/seed/`. Decided by the user: runnable dev seed files are a documented exception to the SQL-placement rule (see `CLAUDE.md`), because the change folder moves when the change is archived and would break the compose mount.
- **Source:** the user supplies a schema-only dump and a reference-table data dump, not a full dump. Customer data from Tastefully never enters this repo or the local database.
8. **Smoke check is `local/smoke.sh`.** It makes three calls and exits non-zero, naming the failing call, if any of them fails:
1. Admin login: `POST /auth/authenticate` on the gateway (auth → system → MySQL).
2. `GET /counter/event/findCurrentEvent` on the gateway, with the admin token (counter → MySQL).
3. `GET /api/public/messages/en_US` on mobile-api (mobile-api → gateway → system → MySQL).
- The originally planned `GET /api/event/upcomingEvent` returns a hardcoded URL and never reaches a service. mobile-api has no public endpoint backed by counter; its counter calls need a member token. That is why the counter call goes through the gateway directly.
9. **Dropped-service references.** HTTP calls to dropped services are strings; they compile and only fail if called, so they stay. Remove only these:
- gateway routes whose `uri` points at a dropped service (bonus, payment, inventory, stockist, wallet and similar);
- any bean or config that fails at startup without a dropped service.
- Each removal is listed in the task's commit message.
## Risks / Trade-offs
- [The base image `gitea.containerverse.dev/solvway/docker-java-21` needs registry access] → The README documents `docker login gitea.containerverse.dev`. If access is a blocker, use `eclipse-temurin:21-jre` locally only.
- [The dump may contain customer data in tables thought to be reference data] → Reference rows are dumped per table from an allow-list, and the diff is reviewed before commit (spec scenario "Seed contains no customer data").
- [The schema dump drifts from the entity mappings] → The smoke check and service startup catch it, and change 2–4 tests run against the seeded schema.
- [Subscriptions are missed in the emulator] → The services fail at startup. The "stack starts healthy" scenario checks the logs.
- [Six JVMs plus MySQL use about 6 GB of RAM] → Set `JAVA_OPTS=-Xmx384m` per service in compose.
## Migration Plan
None. This is a new repo with nothing deployed. Rollback is reverting the commits.
@@ -0,0 +1,33 @@
# Proposal
## Why
Co-Lite has no code yet. Before any lead-tracking work can start, the repository needs the Tastefully modules Co-Lite keeps, plus the two web apps. It also needs a way to run the whole system on a developer machine, because nothing is deployed yet. This is change 1 of 5 in phase 1 (see `docs/superpowers/specs/2026-11-26-co-lite-foundation-and-leads-design.md`). Go-live is 15 January 2027.
## What Changes
- Copy the kept Tastefully modules into this repo from Tastefully commit `8bd93d15`: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log and services-email.
- Copy `solvway-admin-portal` from babyboo commit `f64d096ea` and `solvway-customer-portal` from Tastefully. Both are unchanged in this change; they are trimmed in later changes.
- Add a root Maven aggregator `pom.xml` so one parallel build covers every kept module.
- Change the core-libs version from `tastefully-v1` to `colite-v1`, so Co-Lite's library cannot overwrite Tastefully's or babyboo's in the shared local Maven repository.
- Remove gateway routes for dropped services, plus any code in kept modules that stops compilation or startup without a dropped module.
- Add `local/`: a docker-compose stack with MySQL, Redis, the Pub/Sub emulator and every kept backend service, plus one documented start command.
- Seed the local MySQL with Tastefully's schemas and reference data, taken from a schema dump the user supplies, plus one company and one admin user.
- Add a smoke check: one existing public mobile-api endpoint that reads from services-counter and MySQL through the gateway.
## Capabilities
### New Capabilities
- `local-dev-stack`: running the full Co-Lite backend on a developer machine: build, start, seed and smoke-check.
### Modified Capabilities
None.
## Impact
- New top-level modules and `local/` directory; no existing code in this repo is touched.
- Shared local Maven repository: adds `com.solvway.core:solvway-core-libs:colite-v1` alongside the existing versions.
- Requires a Tastefully schema dump from the user before the seed task (task group 4) can finish.
- No production systems or databases are touched. The local MySQL is disposable and dev-only.
@@ -0,0 +1,80 @@
# Spec Delta
## Purpose
Lets a developer build, start, seed and check the whole Co-Lite backend on their own machine, with no shared environment.
## ADDED Requirements
### Requirement: Single build for all backend modules
The repository SHALL build and test every kept backend module with one Maven command run from the repository root.
#### Scenario: Root build succeeds
- **GIVEN** a fresh clone with JDK 21 and Maven installed
- **WHEN** the developer runs `mvn -T 1C verify` at the repository root
- **THEN** every kept module compiles and its tests pass
### Requirement: Isolated core library version
The Co-Lite core library MUST be published under a version distinct from every other Solvway project on the same machine.
#### Scenario: Local install does not overwrite other projects
- **GIVEN** Tastefully's `tastefully-v1` core library is in the local Maven repository
- **WHEN** the developer installs Co-Lite's core library
- **THEN** it is stored as version `colite-v1`
- **AND** the `tastefully-v1` artifact is unchanged
### Requirement: One command starts the local stack
The repository SHALL start MySQL, Redis, the Pub/Sub emulator and every kept backend service locally with one documented command.
#### Scenario: Stack starts healthy
- **WHEN** the developer runs the documented start command
- **THEN** every service container reaches a running, healthy state
- **AND** no service logs a startup failure about a missing topic, subscription, schema or dropped service
### Requirement: Local database is seeded on first start
The local stack SHALL create the kept service schemas, their reference data, one company and one admin user on first start of an empty database.
#### Scenario: Empty database is seeded
- **GIVEN** the local MySQL volume is empty
- **WHEN** the stack starts
- **THEN** the schemas `service-system`, `service-counter`, `service-member`, `service-log` and `service-email` exist with their tables
- **AND** one company and one admin user exist
#### Scenario: Seed contains no customer data
- **WHEN** the seed files are committed
- **THEN** they contain table definitions and reference rows only, with no Tastefully member, attendance, order or user rows
### Requirement: Local stack can be reset
The repository SHALL provide a documented command that deletes local data and reseeds from scratch.
#### Scenario: Reset restores the seeded state
- **GIVEN** the developer has changed data in the local database
- **WHEN** they run the documented reset command and start the stack again
- **THEN** the database holds only the seeded data
### Requirement: End-to-end smoke check
The repository SHALL include a smoke check that logs in as the seeded admin through the gateway, reads from services-counter through the gateway, and calls a public mobile-api endpoint, confirming each succeeds against MySQL.
#### Scenario: Smoke check passes on a healthy stack
- **GIVEN** the stack is running and seeded
- **WHEN** the developer runs the smoke check
- **THEN** it exits with status 0 and prints HTTP status 200 for each call
#### Scenario: Smoke check fails loudly
- **GIVEN** services-counter is stopped
- **WHEN** the developer runs the smoke check
- **THEN** it exits with a non-zero status and names the failing call
@@ -0,0 +1,37 @@
# Tasks
Run serially: every group touches build files or shared config.
## 1. Copy modules into the repo
- [x] 1.1 Copy the ten kept backend modules (core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email) from Tastefully `8bd93d15`, using `git -C ~/Projects/tastefully archive 8bd93d15 <dirs> | tar -x`. Verify: `ls` shows exactly those ten `solvway-*` dirs, and `find . -name node_modules -o -name target` is empty.
- [x] 1.2 Copy `solvway-admin-portal` from babyboo `f64d096ea` and `solvway-customer-portal` from Tastefully `8bd93d15` the same way. Verify that `npm ci && npm test && npm run build` passes in each app, or record the pre-existing failures with their output.
- [x] 1.3 Scan the copied tree for secrets: `grep -rnEi "(password|secret|apikey|api_key|token|BEGIN .*PRIVATE KEY)\s*[:=]" --include=*.yml --include=*.yaml --include=*.properties --include=*.env* --include=*.json .`. Replace every literal secret with an env placeholder. Verify: re-running the scan shows only placeholders or dev-only values. Commit with the list of replaced keys, never the values.
## 2. Single build
- [x] 2.1 Set the core-libs version to `colite-v1` in `solvway-core-libs/pom.xml` (and core-session if it shares the scheme), and set `core-project.version` to `colite-v1` in every kept module pom. Verify: `grep -rn "tastefully-v1\|babyboo-v1" --include=pom.xml .` is empty.
- [x] 2.2 Add a root `pom.xml` aggregator (groupId `com.solvway`, artifactId `co-lite`, packaging `pom`) listing the ten modules, core-libs and core-session first. Verify: `mvn -T 1C verify` at the root passes, and `ls ~/.m2/repository/com/solvway/core/solvway-core-libs/` still contains `tastefully-v1` with an unchanged timestamp. Do not run `mvn install` against the Tastefully or babyboo repos.
- [x] 2.3 Remove gateway routes to dropped services in `solvway-api-gateway/src/main/resources/application.yml`, and any `app.services.name.*` entries only they use. Verify: the existing gateway tests pass, and `grep -nE "bonus|payment|inventory|stockist|wallet" solvway-api-gateway/src/main/resources/application.yml` is empty.
## 3. Local stack (without seed)
- [x] 3.1 Extract every Pub/Sub topic and subscription name used by the kept modules: read each `PubSubConfig`, `PubSubListener` and publisher call, and resolve property values. Write them to `local/pubsub/topics.txt` as `topic subscription` lines, plus publish-only topics as `topic` lines. Verify: every `@Value("${pubsub...}")` key in the kept modules resolves to a name (none unresolved). Result: 32 unique subscriptions plus 9 publish-only topics. There are fewer than the 37 adapter constructions because Tastefully shares some subscription names across services (e.g. `new-member-add-user-subscription` in system, counter and member). This is kept as-is.
- [x] 3.2 Add `application-local.yml` to each kept Spring module with the emulator host and `co-lite-local` project id. Verify: `mvn -T 1C verify` still passes.
- [x] 3.3 Add `local/docker-compose.yml`: mysql:8, redis:7, the Pub/Sub emulator, a pubsub-init one-shot that reads `topics.txt`, and the eight Java services named as in design decision 4, each with `JAVA_OPTS=-Xmx384m`. Add `local/.env.example` with dev-only values for every env var listed in design Context, and git-ignore `local/.env`. Add `local/up.sh`, which runs `mvn -T 1C -DskipTests package` then `docker compose up -d --build`. Verify: with an empty MySQL (schemas created empty by an init script), `local/up.sh` brings pubsub-init to exit 0, and no service log shows a missing topic or subscription error. Result (2026-11-26): pubsub-init exit 0, 7 of 8 services start on empty schemas, and service-counter stops only on `Table 'service-counter.event' doesn't exist`, which is expected until group 4 seeds the schema. Gateway API keys are mounted from `local/appkeys.json` at `/deployments/appkeys/appkeys.json`, as in k8s.
## 4. Seed (needs the user's Tastefully dump)
- [x] 4.1 Ask the user for the dump, giving them this exact command: `mysqldump --no-data --routines --triggers --skip-add-drop-table --databases service-system service-counter service-member service-log service-email > 01-schema.sql`, plus a data dump of an allow-list of reference tables. Build the allow-list from the services-system entities: role, module, system_property, location_hierarchy and the other lookup tables, each checked for personal data before it is listed. Put the files in `local/seed/`. Verify: grep the files for `INSERT INTO \`(member|user|event_attendance|orders)` and it is empty.
- [x] 4.2 Write `03-colite.sql`: one company row and one admin user with the Administrator role, a bcrypt hash of the documented dev password, and the column set matching the dumped `user` table. Verify: after `docker compose down -v && local/up.sh`, `SELECT count(*) FROM \`service-system\`.user` returns 1. The admin can log in through `POST /auth/...` via the gateway (endpoint confirmed from services-auth) and gets a token. Result: `POST /auth/authenticate` through the gateway (`api-key` header) returns a JWT for `admin` / `colite-dev-admin`. A wrong password returns 200 with an empty body, which is existing Tastefully behaviour. MySQL runs with `--log-bin-trust-function-creators=1 --innodb-strict-mode=OFF` to load the dumped schema, and its healthcheck uses TCP so services wait for seeding to finish.
- [x] 4.3 Write `local/README.md`: prerequisites (JDK 21, Maven, Docker, registry login), build/up, reset (`docker compose -f local/docker-compose.yml down -v`), the dev login, and how to rebuild one service and attach a debugger inside the stack. (This replaces the planned "run one service from an IDE": services address each other by container name, so a service outside Docker cannot join the stack.) Verify: a second developer follows it on a clean clone without help. If no second developer is available, re-run the documented commands verbatim on a fresh clone in a scratch dir.
## 5. Smoke check
- [x] 5.1 Add `local/smoke.sh` (design decision 8). Verify on a healthy stack: exit 0 and prints `200`. Then `docker compose stop service-counter`: exit non-zero, with the failing URL printed.
- [x] 5.2 Integration: from a fresh clone in a scratch directory, run `mvn -T 1C verify`, `local/up.sh` and `local/smoke.sh`. Verify: all three succeed and `docker compose ps` shows every service running. Paste the outputs into the PR description.
## Workflow follow-up
- Code review, then push the branch and confirm the PR target with the user.
- Archive the change after merge.