doc 仓正典 main@5f02909 冻结 v1.4.0 后的 api 侧收尾:字节级同步快照、守卫
升版、新增/变更操作入契约一致性矩阵。**零生产代码改动**(只改契约快照与测试)。
快照同步(字节级,md5 与正典逐一比对一致 a7081fb84f1207eef579ab94025f5801):
- 四模块 openapi-v1.3.0.yaml → openapi-v1.4.0.yaml,删旧文件(守卫只认一份,
保留旧快照是死重;历史版本由 git 与 doc 仓承载,沿 T3-19 先例)
- 四份守卫期望升版:1.3.0/31/43/72 → 1.4.0/32/45/75
矩阵扩展(173 → 181 格,豁免仍为 1 格):
- patbond-auth +5 格:PATCH /api/v1/me 全响应矩阵(200 设值 / 200 显式 null
清空 / 400 空 patch / 401 / 404 双码 40400+40405 / 422 42203),并让 GET
/api/v1/me 在 nickname 非空分支再走一遍严格校验。注意 /api/v1/me 的守卫与
矩阵都在 auth 模块(实现在 user,契约测试跨服务发请求),扩契约易漏
- patbond-pet +1 格:PATCH /api/v1/pets/{petId} 新增 422/42203;404 单元格
补 40405 第二种业务码(幽灵 asset 与用途不符 asset 合并同答),并补一格
挂 ready 头像的 200
- patbond-community +2 格:GET /api/v1/me/community-stats 200(空数据零值与
有数据 1 赞/2 作品两分支)+ 401(由全操作循环覆盖)
- patbond-user media 域 2 操作 8 格不变(v1.4.0 未触碰其冻结面)
T3.5-04/05/06 遗留的 11 格契约守卫红(auth 2 + pet 9,根因为新增字段未冻结)
全部转绿。测试 379 → 381(+2 个新增矩阵方法),根反应堆 clean test 全绿,
check-secrets.sh --all exit 0。
mutation 自证(三处定向注毒均红、还原即绿):CommunityStats.required 注入
fakeStatsField → GET /me/community-stats 200 报漂移;Me.required 注入
fakeMeField → GET+PATCH /me 200 报漂移;Pet.required 注入 fakePetAvatarField
→ POST /pets 201 等 9 格报漂移。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Patbond API
Patbond API is a Spring Boot multi-module backend.
Modules
patbond-common: stable cross-module contracts (response wrapper, shared DTOs). No web/messaging dependencies.patbond-user: user service for user creation, profile lookup, and password verification.patbond-auth: authentication service for registration and login. Callspatbond-userover HTTP via OpenFeign with a configured static URL (no service discovery in the MVP, see ADR-002).patbond-pet: pet profile and health record service (M2, ADR-009). Shares the database withpatbond-userand only reads/writes thepet_healthschema; the Flyway migration chain stays owned bypatbond-user. First-wave skeleton: liveness endpoint only.
Technology Stack
- Java 17 (build baseline; use JDK 17 for release builds)
- Spring Boot 3.5.16
- Spring Cloud 2025.0.3 (OpenFeign only)
- PostgreSQL 18 + Flyway (patbond-user owns the migration chain:
identity/media/platform/pet_healthschemas) - Maven (use the committed Maven Wrapper
./mvnw)
Build and Test
./mvnw clean test
Integration tests start a disposable postgres:18 via Testcontainers, so a
running Docker daemon is required (no local PostgreSQL installation or
credentials are needed).
If your default JDK is not 17, point JAVA_HOME at a JDK 17 installation first, e.g.:
JAVA_HOME=/usr/lib/jvm/java-17-openjdk ./mvnw clean test
Run
Running patbond-user requires a reachable PostgreSQL 18 database; Flyway
applies the versioned migrations in
patbond-user/src/main/resources/db/migration automatically on startup.
Development seed data (db/dev, regions reference rows) is opt-in via a dev
profile — see application.yml.sample.
Each service ships a committed application.yml.sample; the real application.yml
is git-ignored. First copy the samples (defaults work locally, overrides via
environment variables):
cp patbond-user/src/main/resources/application.yml.sample \
patbond-user/src/main/resources/application.yml
cp patbond-auth/src/main/resources/application.yml.sample \
patbond-auth/src/main/resources/application.yml
cp patbond-pet/src/main/resources/application.yml.sample \
patbond-pet/src/main/resources/application.yml
Install the shared module once, then run each service in its own terminal:
./mvnw -pl patbond-common install
./mvnw -pl patbond-user spring-boot:run
./mvnw -pl patbond-auth spring-boot:run
Running the services also needs an RS256 key pair for access tokens (the
private key signs in patbond-auth, the public key verifies in
patbond-user; neither is committed):
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out jwt-private.pem
openssl pkey -in jwt-private.pem -pubout -out jwt-public.pem
export PATBOND_JWT_PRIVATE_KEY=$PWD/jwt-private.pem # patbond-auth
export PATBOND_JWT_PUBLIC_KEY=$PWD/jwt-public.pem # patbond-user
Tests do not require this copy step — patbond-auth/src/test/resources/application.yml
keeps ./mvnw clean test self-contained on a clean checkout.
Smoke check:
curl -X POST http://127.0.0.1:8081/api/v1/auth/register \
-H 'Content-Type: application/json' \
-d '{"username":"demo_user","password":"secret123"}'
Configuration
| Environment variable | Default | Used by |
|---|---|---|
PATBOND_USER_PORT |
8082 |
patbond-user |
PATBOND_AUTH_PORT |
8081 |
patbond-auth |
PATBOND_USER_SERVICE_URL |
http://127.0.0.1:8082 |
patbond-auth (Feign target for patbond-user) |
PATBOND_DB_URL |
jdbc:postgresql://127.0.0.1:5432/patbond |
patbond-user |
PATBOND_DB_USER |
patbond |
patbond-user |
PATBOND_DB_PASSWORD |
patbond |
patbond-user |
PATBOND_INTERNAL_TOKEN |
dev-only-internal-token |
both (shared secret for /internal/**; inject a strong random value outside local dev) |
PATBOND_JWT_PRIVATE_KEY |
(none, required) | patbond-auth (RS256 private key: PEM path or inline PEM) |
PATBOND_JWT_PUBLIC_KEY |
(none) | patbond-user (RS256 public key: PEM path or inline PEM) |
PATBOND_ACCESS_TTL |
15m |
patbond-auth (access token lifetime, ADR-003) |
PATBOND_REFRESH_TTL |
30d |
patbond-user (refresh token lifetime, ADR-003) |
PATBOND_LOGIN_LOCK_MAX_FAILURES |
5 |
patbond-user (login failures before lockout) |
PATBOND_LOGIN_LOCK_WINDOW |
15m |
patbond-user (failure counting window) |
PATBOND_LOGIN_LOCK_DURATION |
15m |
patbond-user (lock duration) |
Machine-specific values live in the git-ignored application.yml (copied from the
committed .sample); never commit secrets to the samples.
Docker Compose
MVP 编排(ADR-007):postgres:18(数据落 volume)+ 两个无状态应用容器。
配置与本机运行同一套约定 —— 容器内挂载 application.yml.sample 作为配置,
PATBOND_* 环境变量注入实际值。
# 1. 生成 RS256 密钥对与 .env(DB 口令、内部令牌;产物被 .gitignore 忽略)
./deploy/init-secrets.sh
# 2. 构建可执行 jar
JAVA_HOME=/usr/lib/jvm/java-17-openjdk ./mvnw -DskipTests package
# 3. 启动(首次会构建镜像)
docker compose up -d --build
# 冒烟
curl -s -X POST http://127.0.0.1:8081/api/v1/auth/register \
-H 'Content-Type: application/json' \
-d '{"username":"demo_user","password":"secret123"}'
# 停止(-v 同时删除数据库数据)
docker compose down
注意:数据库端口不对宿主机发布;8082(user)在 MVP 阶段直连暴露以提供
/api/v1/me,/internal/** 由服务间令牌保护,规模化阶段应改由网关统一入口。
Services
Auth Service
- Application name:
patbond-auth - Default port:
8081 - Register:
POST /api/v1/auth/register - Login:
POST /api/v1/auth/login - Refresh (rotates the refresh token):
POST /api/v1/auth/refresh - Logout (revokes the current session):
POST /api/v1/auth/logout
User Service
- Application name:
patbond-user - Default port:
8082 - Current user profile:
GET /api/v1/me(Bearer access token, verified locally with the RS256 public key) - Internal (require
X-Internal-Token):- Create user:
POST /internal/users - Verify password:
POST /internal/users/verify-password - Get user by id:
GET /internal/users/{id} - Get user by username:
GET /internal/users/by-username/{username} - Sessions:
POST /internal/sessions,POST /internal/sessions/refresh,POST /internal/sessions/revoke
- Create user:
Note: user data is persisted in PostgreSQL (
identity.users/identity.user_credentials, bcrypt password hashes, UUIDv7 ids generated in the application). Refresh sessions live inidentity.auth_sessions(SHA-256 digests only, rotation on every refresh, token-family revocation on reuse, ADR-003). Errors follow the{code, message, data}envelope with stable business codes and matching HTTP statuses; the public contract is documented inpatbond-doc/docs/api/openapi.yaml.