|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Benefit Decision Toolkit (BDT) is a platform for creating benefit eligibility screeners using Decision Model and Notation (DMN) and Form-JS. The project consists of four main applications: |
| 8 | + |
| 9 | +- **library-api**: Standalone Quarkus API that generates REST endpoints from DMN files (Kogito-based) |
| 10 | +- **builder-api + builder-frontend**: Web application for creating and managing screeners (admin tool) |
| 11 | +- **screener-api + screener-frontend**: Public-facing screener evaluation interface (end-user tool) |
| 12 | + |
| 13 | +The core concept: Subject matter experts can define eligibility rules using visual DMN decision tables, which automatically become REST APIs and interactive screeners without traditional software development. |
| 14 | + |
| 15 | +## Common Commands |
| 16 | + |
| 17 | +### Development Setup |
| 18 | + |
| 19 | +```bash |
| 20 | +# One-time setup with Devbox (recommended) |
| 21 | +bin/install-devbox && devbox run setup |
| 22 | + |
| 23 | +# Or without Devbox (requires manual dependency installation) |
| 24 | +bin/setup |
| 25 | +``` |
| 26 | + |
| 27 | +### Running Services |
| 28 | + |
| 29 | +```bash |
| 30 | +# Start all services in development mode (uses process-compose) |
| 31 | +devbox services up |
| 32 | + |
| 33 | +# Or manually with process-compose (if not using devbox) |
| 34 | +process-compose |
| 35 | + |
| 36 | +# Run library-api standalone |
| 37 | +cd library-api && quarkus dev |
| 38 | +# Serves at http://localhost:8083, Swagger UI at /q/swagger-ui |
| 39 | + |
| 40 | +# Run builder services (requires Firebase emulators) |
| 41 | +# Terminal 1: Start Firebase emulators |
| 42 | +firebase emulators:start --project demo-bdt-dev --only auth,firestore,storage |
| 43 | + |
| 44 | +# Terminal 2: Start builder-api |
| 45 | +cd builder-api && quarkus dev |
| 46 | +# Debug port: 5005 |
| 47 | + |
| 48 | +# Terminal 3: Start builder-frontend |
| 49 | +cd builder-frontend && npm run dev |
| 50 | +``` |
| 51 | + |
| 52 | +### Building |
| 53 | + |
| 54 | +```bash |
| 55 | +# Build specific API |
| 56 | +cd builder-api && mvn clean package |
| 57 | +cd screener-api && mvn clean package |
| 58 | +cd library-api && mvn clean package |
| 59 | + |
| 60 | +# Build frontend |
| 61 | +cd builder-frontend && npm run build |
| 62 | +cd screener-frontend && npm run build |
| 63 | + |
| 64 | +# Clean rebuild (useful when DMN files change) |
| 65 | +mvn clean compile |
| 66 | +``` |
| 67 | + |
| 68 | +### Testing |
| 69 | + |
| 70 | +```bash |
| 71 | +# Run Java tests for an API |
| 72 | +cd builder-api && mvn test |
| 73 | +cd screener-api && mvn test |
| 74 | + |
| 75 | +# Run library-api tests with Bruno (API testing tool) |
| 76 | +cd library-api/test/bdt && bru run |
| 77 | + |
| 78 | +# Frontend doesn't have test suites currently |
| 79 | +``` |
| 80 | + |
| 81 | +## High-Level Architecture |
| 82 | + |
| 83 | +### Multi-Application Structure |
| 84 | + |
| 85 | +This is a monorepo containing four distinct applications that work together: |
| 86 | + |
| 87 | +1. **library-api** (Kogito-based DMN → REST API generator) |
| 88 | + - Standalone Quarkus app using Kogito for automatic API generation |
| 89 | + - DMN files in `src/main/resources/` become REST endpoints |
| 90 | + - See `library-api/CLAUDE.md` for detailed documentation |
| 91 | + |
| 92 | +2. **builder-api** (Quarkus REST API, ~3,300 LOC) |
| 93 | + - Admin backend for screener creation and management |
| 94 | + - Integrates Firebase (Auth, Firestore, Cloud Storage) |
| 95 | + - Uses KIE DMN (not Kogito) for manual DMN compilation and evaluation |
| 96 | + - Main packages: `controller`, `service`, `persistence`, `model` |
| 97 | + |
| 98 | +3. **builder-frontend** (Solid.js, Form-JS Editor, DMN-JS) |
| 99 | + - Visual editor for creating benefit screeners |
| 100 | + - Features: Form editor, DMN decision editor, benefit configuration, preview, publish |
| 101 | + - Routes: `/` (home), `/project/:id` (editor), `/check/:id` (DMN editor) |
| 102 | + |
| 103 | +4. **screener-api** (Lightweight Quarkus REST API, ~750 LOC) |
| 104 | + - Read-only runtime for serving published screeners |
| 105 | + - Executes pre-compiled DMN decisions against user input |
| 106 | + - Two endpoints: GET screener schema, POST evaluate decisions |
| 107 | + |
| 108 | +5. **screener-frontend** (Solid.js, Form-JS Viewer) |
| 109 | + - Public-facing screener with real-time eligibility evaluation |
| 110 | + - Debounced auto-submission as user fills form |
| 111 | + - Displays nested results (benefits → eligibility checks) |
| 112 | + |
| 113 | +### Data Flow Architecture |
| 114 | + |
| 115 | +``` |
| 116 | +Builder Flow: |
| 117 | +Admin → builder-frontend → builder-api → Firebase (Firestore + Storage) |
| 118 | + ↓ |
| 119 | + Compile DMN → Store compiled JAR |
| 120 | + ↓ |
| 121 | + Publish screener |
| 122 | +
|
| 123 | +Screener Flow: |
| 124 | +User → screener-frontend → screener-api → Firestore (read metadata) |
| 125 | + → Cloud Storage (read form schema + DMN JAR) |
| 126 | + → KIE Runtime (evaluate DMN) |
| 127 | + → Return results |
| 128 | +``` |
| 129 | + |
| 130 | +### Key Architectural Patterns |
| 131 | + |
| 132 | +**Separation of Concerns**: |
| 133 | +- **Eligibility Checks**: Reusable DMN models (independent decision logic) |
| 134 | +- **Benefits**: Configurations that reference one or more eligibility checks |
| 135 | +- **Forms**: Separate schemas defining user input fields |
| 136 | +- **Screeners**: Containers that combine forms + benefits + checks |
| 137 | + |
| 138 | +**DMN Processing Differences**: |
| 139 | +- **library-api**: Uses Kogito (automatic code generation at build time) |
| 140 | +- **builder-api**: Uses KIE DMN directly (runtime compilation from XML) |
| 141 | +- **screener-api**: Uses KIE DMN (loads pre-compiled JAR artifacts) |
| 142 | + |
| 143 | +**Storage Strategy**: |
| 144 | +- **Metadata** (relationships, configs): Firestore NoSQL collections |
| 145 | +- **Large artifacts** (DMN files, form schemas, compiled JARs): Google Cloud Storage |
| 146 | +- **Reference data** (location lookups): Embedded SQLite databases |
| 147 | + |
| 148 | +**Authentication**: |
| 149 | +- **builder-api/builder-frontend**: Firebase Auth required (user ownership model) |
| 150 | +- **screener-api/screener-frontend**: Public/anonymous access |
| 151 | +- **library-api**: No authentication (standalone utility) |
| 152 | + |
| 153 | +### Technology Stack |
| 154 | + |
| 155 | +**Backend (All APIs)**: |
| 156 | +- **builder-api**: Quarkus 3.23.0, Java 21, KIE DMN 10.0.0 |
| 157 | +- **screener-api**: Quarkus 3.23.0, Java 21, KIE DMN 10.0.0 |
| 158 | +- **library-api**: Quarkus 2.16.10, Java 17, Kogito 1.44.1 |
| 159 | + |
| 160 | +**Frontend**: |
| 161 | +- **Framework**: Solid.js (reactive JavaScript framework) |
| 162 | +- **Form Builder/Renderer**: Form-JS (BPMN.io) |
| 163 | +- **DMN Editor**: DMN-JS + Kogito Tooling |
| 164 | +- **Styling**: Tailwind CSS |
| 165 | + |
| 166 | +**Infrastructure**: |
| 167 | +- **Dev Environment**: Devbox (Nix-based) or Devcontainer |
| 168 | +- **Process Management**: process-compose |
| 169 | +- **Cloud Services**: Firebase (Auth, Firestore, Cloud Storage) |
| 170 | +- **Database**: SQLite (embedded for reference data) |
| 171 | + |
| 172 | +## Development Workflow |
| 173 | + |
| 174 | +### Working with DMN Files |
| 175 | + |
| 176 | +**In library-api** (Kogito): |
| 177 | +1. Add/edit DMN file in `library-api/src/main/resources/` |
| 178 | +2. Run `quarkus dev` - Kogito auto-generates REST endpoints |
| 179 | +3. Check `/q/swagger-ui` for new endpoints |
| 180 | +4. Test with Bruno: `cd library-api/test/bdt && bru run` |
| 181 | + |
| 182 | +**In builder-api** (Manual): |
| 183 | +1. Create eligibility check via builder-frontend UI |
| 184 | +2. Upload DMN file through UI (stores in Cloud Storage) |
| 185 | +3. builder-api compiles DMN on-demand during evaluation |
| 186 | +4. Publish screener to create pre-compiled artifact |
| 187 | + |
| 188 | +**DMN Editing**: |
| 189 | +- Use VS Code extension: [DMN Editor](https://marketplace.visualstudio.com/items?itemName=kie-group.dmn-vscode-extension) |
| 190 | +- Learn DMN basics: https://learn-dmn-in-15-minutes.com/ |
| 191 | +- Access raw XML: Right-click → "Reopen with Text Editor" |
| 192 | + |
| 193 | +### Firebase Emulators |
| 194 | + |
| 195 | +The project uses Firebase emulators for local development: |
| 196 | + |
| 197 | +```bash |
| 198 | +# Start emulators (automatically imports data from ./emulator-data) |
| 199 | +firebase emulators:start --project demo-bdt-dev --only auth,firestore,storage |
| 200 | + |
| 201 | +# Export current state |
| 202 | +firebase emulators:export ./emulator-data |
| 203 | + |
| 204 | +# Access UIs: |
| 205 | +# - Auth UI: http://localhost:4000/auth |
| 206 | +# - Firestore UI: http://localhost:4000/firestore |
| 207 | +# - Storage UI: http://localhost:4000/storage |
| 208 | +``` |
| 209 | + |
| 210 | +### Environment Configuration |
| 211 | + |
| 212 | +The project uses `.env` files for configuration: |
| 213 | + |
| 214 | +```bash |
| 215 | +# Root .env (loaded by devbox) |
| 216 | +# See .env.example for template |
| 217 | + |
| 218 | +# Service-specific .env files |
| 219 | +builder-api/.env |
| 220 | +builder-frontend/.env |
| 221 | +screener-api/.env |
| 222 | +screener-frontend/.env |
| 223 | + |
| 224 | +# Setup script copies .env.example → .env |
| 225 | +bin/setup |
| 226 | +``` |
| 227 | + |
| 228 | +### Working with Individual Services |
| 229 | + |
| 230 | +**builder-api**: |
| 231 | +- Port: Configured via `QUARKUS_HTTP_PORT` env var |
| 232 | +- Debug port: 5005 |
| 233 | +- Main classes: `ScreenerResource`, `DecisionResource`, `KieDmnService` |
| 234 | +- Tests: `mvn test` (some tests may be skipped in CI) |
| 235 | + |
| 236 | +**builder-frontend**: |
| 237 | +- Dev server: `npm run dev` |
| 238 | +- Key components: `ProjectEditor`, `KogitoDmnEditorView`, `FormEditor` |
| 239 | +- API client: `src/api/` (uses `authFetch` wrapper) |
| 240 | + |
| 241 | +**screener-api**: |
| 242 | +- Port: Configured via `QUARKUS_HTTP_PORT` env var |
| 243 | +- Debug: Disabled by default in process-compose |
| 244 | +- Main classes: `ScreenerResource`, `DecisionResource` |
| 245 | +- Lightweight (minimal business logic) |
| 246 | + |
| 247 | +**screener-frontend**: |
| 248 | +- Dev server: `npm run dev` |
| 249 | +- Main component: `Screener.tsx` (form + results) |
| 250 | +- No authentication required |
| 251 | + |
| 252 | +### Common Development Scenarios |
| 253 | + |
| 254 | +**Add a new benefit to library-api**: |
| 255 | +1. Create DMN file in `library-api/src/main/resources/benefits/` |
| 256 | +2. Import BDT.dmn for shared types and utilities |
| 257 | +3. Define Decision Service in DMN |
| 258 | +4. Run `quarkus dev` - endpoint auto-generated |
| 259 | +5. Test with Bruno or Swagger UI |
| 260 | + |
| 261 | +**Create a custom screener**: |
| 262 | +1. Start all services: `devbox services up` |
| 263 | +2. Open builder-frontend (typically http://localhost:5173) |
| 264 | +3. Create project → Edit form → Add/configure benefits → Preview → Publish |
| 265 | +4. Access published screener via screener-frontend |
| 266 | + |
| 267 | +**Debug DMN evaluation issues**: |
| 268 | +1. Check DMN syntax in VS Code with DMN extension |
| 269 | +2. Review Swagger UI for expected input/output schemas |
| 270 | +3. Use Quarkus dev mode logs (shows DMN evaluation details) |
| 271 | +4. Test individual decisions via Swagger UI before integrating |
| 272 | + |
| 273 | +**Modify an existing DMN in library-api**: |
| 274 | +1. Edit DMN file (XML or via VS Code extension) |
| 275 | +2. Save file - Quarkus dev mode auto-reloads |
| 276 | +3. Re-run Bruno tests to verify changes |
| 277 | +4. No manual compilation needed (Kogito handles it) |
| 278 | + |
| 279 | +## Deployment |
| 280 | + |
| 281 | +### library-api Deployment to Google Cloud Run |
| 282 | + |
| 283 | +library-api uses a semantic versioning workflow that keeps git tags, pom.xml version, Docker image tags, and Cloud Run revision names synchronized. |
| 284 | + |
| 285 | +**Deployment Workflow**: |
| 286 | +```bash |
| 287 | +# 1. Create a release (updates pom.xml + creates git tag atomically) |
| 288 | +cd library-api |
| 289 | +./bin/tag-release 0.2.0 |
| 290 | + |
| 291 | +# 2. Review the changes |
| 292 | +git show |
| 293 | + |
| 294 | +# 3. Push the commit and tag |
| 295 | +git push origin <branch-name> |
| 296 | +git push origin library-api-v0.2.0 |
| 297 | +``` |
| 298 | + |
| 299 | +When you push a tag matching `library-api-v*`, GitHub Actions automatically: |
| 300 | +1. Extracts version from pom.xml using Maven |
| 301 | +2. Validates the git tag matches the pom.xml version |
| 302 | +3. Builds the Quarkus application |
| 303 | +4. Builds and pushes Docker images with both `:v0.2.0` and `:latest` tags |
| 304 | +5. Deploys to Cloud Run with revision name `library-api-v0-2-0` |
| 305 | + |
| 306 | +**Version Management**: |
| 307 | +- **Source of truth**: `pom.xml` version field |
| 308 | +- **Git tags**: `library-api-v{version}` (e.g., `library-api-v0.2.0`) |
| 309 | +- **Docker tags**: `:v{version}` and `:latest` (e.g., `:v0.2.0`, `:latest`) |
| 310 | +- **Cloud Run revisions**: `library-api-v{version-with-dashes}` (e.g., `library-api-v0-2-0`) |
| 311 | + |
| 312 | +**Helper Scripts**: |
| 313 | +- `library-api/bin/tag-release <version>`: Creates release atomically (updates pom.xml, commits, and tags) |
| 314 | +- `bin/validate-library-api-version`: Validates that git tag exists for current pom.xml version |
| 315 | + |
| 316 | +**Validation**: |
| 317 | +The deployment has three layers of validation to ensure version sync: |
| 318 | +1. **Primary**: `tag-release` script updates pom.xml and creates matching git tag atomically |
| 319 | +2. **Secondary**: Git pre-push hook validates version before allowing tag push (optional, see setup below) |
| 320 | +3. **Tertiary**: GitHub Actions workflow validates and fails if versions don't match |
| 321 | + |
| 322 | +### Setting Up Git Pre-Push Hook (Optional) |
| 323 | + |
| 324 | +To prevent accidental version mismatches locally, you can install a pre-push hook: |
| 325 | + |
| 326 | +```bash |
| 327 | +# Create the pre-push hook |
| 328 | +cat > .git/hooks/pre-push << 'EOF' |
| 329 | +#!/usr/bin/env bash |
| 330 | +
|
| 331 | +# Validate library-api version before pushing tags |
| 332 | +bin/validate-library-api-version --pre-push-hook |
| 333 | +
|
| 334 | +exit $? |
| 335 | +EOF |
| 336 | + |
| 337 | +# Make it executable |
| 338 | +chmod +x .git/hooks/pre-push |
| 339 | +``` |
| 340 | + |
| 341 | +This hook will: |
| 342 | +- Intercept pushes of `library-api-v*` tags |
| 343 | +- Validate that the tag version matches pom.xml version |
| 344 | +- Block the push if versions don't match |
| 345 | +- Provide helpful error messages with fix instructions |
| 346 | + |
| 347 | +**Note**: Pre-push hooks are not committed to the repository. Each developer must set up their own hook. |
| 348 | + |
| 349 | +### Deployment Infrastructure |
| 350 | + |
| 351 | +**Google Cloud Project**: `benefit-decision-toolkit-play` |
| 352 | +- **Region**: `us-central1` |
| 353 | +- **Service Account**: `library-api-service-account@benefit-decision-toolkit-play.iam.gserviceaccount.com` |
| 354 | +- **Container Registry**: `us-central1-docker.pkg.dev/benefit-decision-toolkit-play/benefit-decision-toolkit-play/library-api` |
| 355 | +- **Max Instances**: 2 |
| 356 | +- **Authentication**: Unauthenticated (public API) |
| 357 | + |
| 358 | +**Dockerfile**: `library-api/src/main/docker/Dockerfile.jvm` |
| 359 | +- Uses Kogito builder and runtime images (version 1.44.1) |
| 360 | +- Multi-stage build with optimized layers |
| 361 | +- Java 17 runtime |
| 362 | + |
| 363 | +## Important Constraints |
| 364 | + |
| 365 | +**DMN Import Rules**: |
| 366 | +- Imported decision services cannot have the same name, even if in different models |
| 367 | +- Always namespace-qualify decision references when importing |
| 368 | +- Check `library-api/CLAUDE.md` for detailed DMN import hierarchy |
| 369 | + |
| 370 | +**Firebase Dependency**: |
| 371 | +- builder-api and screener-api require Firebase configuration |
| 372 | +- Use emulators for local dev (no real Firebase project needed) |
| 373 | +- Production requires actual Firebase project setup |
| 374 | + |
| 375 | +**Process Compose Dependencies**: |
| 376 | +- Services start in order: firebase → APIs → frontends |
| 377 | +- Check `process-compose.yml` for dependency chain |
| 378 | +- APIs wait for "All emulators ready!" log message |
| 379 | + |
| 380 | +**Devbox vs. Native**: |
| 381 | +- Devbox ensures consistent dependency versions |
| 382 | +- Native setup requires manual installation (see `devbox.json` for versions) |
| 383 | +- direnv integration recommended for automatic environment loading |
0 commit comments