diff --git a/openspec/changes/add-repo-foundation-local-stack/.openspec.yaml b/openspec/changes/add-repo-foundation-local-stack/.openspec.yaml new file mode 100644 index 0000000..7ed429c --- /dev/null +++ b/openspec/changes/add-repo-foundation-local-stack/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-26 diff --git a/openspec/changes/add-repo-foundation-local-stack/design.md b/openspec/changes/add-repo-foundation-local-stack/design.md new file mode 100644 index 0000000..4e81f2a --- /dev/null +++ b/openspec/changes/add-repo-foundation-local-stack/design.md @@ -0,0 +1,73 @@ +# 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`. +- 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 `pom` 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:** under the user's SQL-placement rule these live in this change's `sql/` folder. That folder moves when the change is archived, so a permanent compose mount needs `local/seed/` instead. This is pending the user's decision (see Open Questions). + +8. **Smoke check is `local/smoke.sh`.** It runs `curl -fsS` against `http://localhost:8080/api/event/upcomingEvent` (mobile-api → gateway → service-counter → MySQL), prints the status code, and exits non-zero on failure. The task confirms the endpoint is public; if it is not, the task picks another public counter-backed endpoint and records the choice here. + +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. + +## Open Questions + +- Where do the seed SQL files live permanently? Option A: this change's `sql/` folder, with the compose mount moved to the archive path at archive time. Option B, recommended: `local/seed/`, as a documented exception to the SQL-placement rule for executable dev fixtures. This changes only the file path in tasks 4.x. diff --git a/openspec/changes/add-repo-foundation-local-stack/proposal.md b/openspec/changes/add-repo-foundation-local-stack/proposal.md new file mode 100644 index 0000000..3ddb767 --- /dev/null +++ b/openspec/changes/add-repo-foundation-local-stack/proposal.md @@ -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. diff --git a/openspec/changes/add-repo-foundation-local-stack/specs/local-dev-stack/spec.md b/openspec/changes/add-repo-foundation-local-stack/specs/local-dev-stack/spec.md new file mode 100644 index 0000000..605bb52 --- /dev/null +++ b/openspec/changes/add-repo-foundation-local-stack/specs/local-dev-stack/spec.md @@ -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 calls a public mobile-api endpoint through the local stack and confirms a successful response backed by services-counter and 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 the endpoint's HTTP status 200 + +#### 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 diff --git a/openspec/changes/add-repo-foundation-local-stack/tasks.md b/openspec/changes/add-repo-foundation-local-stack/tasks.md new file mode 100644 index 0000000..2c94f21 --- /dev/null +++ b/openspec/changes/add-repo-foundation-local-stack/tasks.md @@ -0,0 +1,37 @@ +# Tasks + +Run serially: every group touches build files or shared config. + +## 1. Copy modules into the repo + +- [ ] 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 | tar -x`. Verify: `ls` shows exactly those ten `solvway-*` dirs, and `find . -name node_modules -o -name target` is empty. +- [ ] 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. +- [ ] 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 + +- [ ] 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. +- [ ] 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. +- [ ] 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) + +- [ ] 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: the line count of subscriptions equals the number of `PubSubInboundChannelAdapter` constructions in the kept modules (37). +- [ ] 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. +- [ ] 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. + +## 4. Seed (needs the user's Tastefully dump) + +- [ ] 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 at the location the user chose in design Open Questions. Verify: grep the files for `INSERT INTO \`(member|user|event_attendance|orders)` and it is empty. +- [ ] 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. +- [ ] 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 run one service from an IDE (stop its container, run with profile `local` and `.env` exported). 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 + +- [ ] 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. +- [ ] 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.