Spring Boot 3 / Java 21 support assistant built with Spring AI. Every model call goes through a single governance layer (sensitive-data policy, input size check, per-account daily token budget, usage recording). Keycloak JWT secures the API; customers only see their own orders. Grounded answers use pgvector retrieval with visibility filters, citation validation, and score-based abstention.
| Layer | Choice |
|---|---|
| Runtime | Java 21, Spring Boot 3.5, Spring AI 1.1 |
| Auth | Keycloak OIDC JWT (customer, support_agent) |
| Data | PostgreSQL 17 + pgvector, Flyway, JPA |
| Models | Ollama (default) or OpenAI-compatible profile |
| UI | Angular 20, Keycloak login, SSE streaming |
| Ops | Docker Compose, Micrometer/Prometheus, Resilience4j, GitHub Actions |
HTTP → JWT / roles → controller validation
→ GovernedCalls
admit → sensitive data → size → daily budget reserve
call → ChatClient / RAG / advisors → model
settle → usage row + budget correction (or release on failure)
→ problem+json errors with request id
| Endpoint | Description |
|---|---|
POST /api/v1/support/ask |
Grounded support answer (JSON) |
POST /api/v1/support/ask/stream |
Same, SSE (token then done) |
GET /api/v1/orders, /api/v1/orders/{orderRef} |
Customer-scoped orders (agents see all) |
GET /api/v1/usage/today |
Daily token usage |
GET /api/v1/me |
Subject, roles, display name |
GET /actuator/health |
Public health |
All other endpoints require a bearer token. Model-calling routes are governed.
Legacy demo routes (/api/chat/*, /api/order-support, /api/trips/*, /multi-model/*) remain for prompt/template samples and are also governed.
| Check | Result |
|---|---|
| Credential/secret with a value | 422 SENSITIVE_DATA |
| Card number (Luhn) | Redacted to last four digits |
| Input over token budget (+ margin) | 422 INPUT_TOO_LONG |
| Daily budget exhausted | 429 DAILY_BUDGET_EXHAUSTED |
| Model circuit open | 503 MODEL_UNAVAILABLE |
Usage is stored without prompt/answer text. Cost status is NOT_CONFIGURED, LOCAL_MODEL, or ESTIMATED when prices are configured.
- Java 21, Maven wrapper (
./mvnw) - Docker (Postgres/pgvector, Keycloak; Testcontainers for tests)
- Optional: Ollama with
llama3.2:3bandnomic-embed-text
cp .env.example .env # set SUPPORT_DB_PASSWORD and KEYCLOAK_ADMIN_PASSWORD
docker compose up -d db keycloak
export SUPPORT_DB_PASSWORD=<same value>
SPRING_PROFILES_ACTIVE=demo ./mvnw spring-boot:runDemo users (dev only): alice / bob (customer), agent (support_agent), password Demo-pass-1.
TOKEN=$(curl -s -X POST http://localhost:8180/realms/support/protocol/openid-connect/token \
-d client_id=support-dev -d grant_type=password -d username=alice -d password=Demo-pass-1 \
| sed -n 's/.*"access_token":"\([^"]*\)".*/\1/p')
curl -H "Authorization: Bearer $TOKEN" http://localhost:8080/api/v1/orders
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"question":"Why is my order late?","orderRef":"ORD-1001"}' \
http://localhost:8080/api/v1/support/askOpenAI-compatible endpoint:
SPRING_PROFILES_ACTIVE=openai,demo OPENAI_API_KEY=<key> ./mvnw spring-boot:runcd frontend && npm ci && npm start # http://localhost:4200Or full stack: docker compose up --build (UI on http://localhost:8081). See frontend/README.md.
./mvnw verify
cd frontend && npm ci && npm test -- --watch=false --browsers=ChromeHeadlessNoSandboxBackend: 185 tests (Testcontainers + mocked models). Frontend: 112 tests (incl. axe). Evaluation gate: evaluation/ (66 questions, baseline in CI).
src/main/java/com/springai/
advisor/ governance/ budget/ knowledge/ order/ security/ support/ ...
frontend/ Angular UI
knowledge/ Sample support corpus
evaluation/ Regression questions + baseline
.github/workflows/ CI (Maven verify, Docker, frontend)
Apache License 2.0. See LICENSE and SECURITY.md.