Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Maker-Checker-Flowable

A standalone, polyglot-friendly maker-checker approval REST API, built on the Flowable OSS BPMN engine — in the spirit of Camunda 7's REST-API-first approach, but purpose-built for one workflow shape instead of exposing the whole engine.

Any system that speaks HTTP — Java, Node.js, Python, .NET, anything — can plug into this as a reusable approval-workflow sidecar: submit something for approval, list what's pending for a checker, approve or reject it, get notified by webhook when it's decided, and query status and a full audit trail at any point. The service owns none of your business logic and no user directory of its own; it only tracks who made a request, who can act on it, and what they decided.

Why Flowable, and what's actually happening underneath

Every request maps to one instance of a single, generic BPMN process (makerCheckerProcess, defined in src/main/resources/processes/maker-checker.bpmn20.xml):

Start Event -> User Task "Review Request" -> Exclusive Gateway -> End (Approved) / End (Rejected)

The user task's candidate group is set dynamically per request (via a checkerGroup variable), so the same process definition serves every entityType without redeploying anything. Everything else about a request — its entityType, payload, maker, decision, timestamps, audit trail — lives in a local table, not as Flowable process variables, keeping the process itself generic and Flowable's own tables lean.

This is a single-level maker-checker: one maker submits, one checker approves or rejects. There is no multi-level approval chain or quorum in this version.

Quickstart

Zero external dependencies — an embedded, file-based H2 database is used by default.

mvn spring-boot:run

The service starts on :8080. Try the worked example for a full curl-driven walkthrough, or see below for the API by hand.

Security model

Every /api/** call is checked in two independent steps:

  1. X-API-Key — a shared secret that answers "is this caller allowed to talk to me at all?" Configure it via the MC_API_KEY environment variable. The default in application.yml (dev-local-insecure-api-key) is for local development only — always override it outside a throwaway dev instance.
  2. X-User-Id / X-User-Groups — the acting user's identity and group memberships, as asserted by the calling ecosystem. This service does not authenticate end users or own a user directory; it trusts that the caller already authenticated its own user through its own means, and is telling the truth about who that user is. X-User-Id drives audit fields (maker, claimedBy, decidedBy); X-User-Groups (comma-separated) drives Flowable candidate-group visibility, claiming, and approve/reject authorization.

/actuator/health, /v3/api-docs/**, and /swagger-ui/** are intentionally left open — health for orchestrator probes, docs for discoverability by integrators who don't have credentials yet.

API reference

Base path /api/v1. Full interactive docs at http://localhost:8080/swagger-ui.html once the app is running (use the "Authorize" button to set your headers for try-it-out).

Method Path Purpose
POST /requests Create a request and start its review process
GET /requests/{id} Get a request by id
GET /requests?status=&entityType=&maker=&page=&size= Paginated/filtered list
GET /requests/{id}/audit Full audit trail for a request
GET /tasks Pending checker tasks visible to the caller's X-User-Groups
GET /tasks/{taskId} Task detail
POST /tasks/{taskId}/claim Claim a task (idempotent for the same caller)
POST /tasks/{taskId}/approve Approve; auto-claims if unclaimed and authorized
POST /tasks/{taskId}/reject Reject; auto-claims if unclaimed and authorized

Full lifecycle, by hand

API_KEY=dev-local-insecure-api-key

# 1. Maker submits a request. entityType and payload are entirely caller-defined.
curl -s -X POST http://localhost:8080/api/v1/requests \
  -H "X-API-Key: $API_KEY" -H "X-User-Id: alice" -H "Content-Type: application/json" \
  -d '{
        "entityType": "expense-approval",
        "payload": {"amount": 420, "currency": "USD"},
        "checkerGroup": "finance-checkers",
        "callbackUrl": "https://your-app.example.com/webhooks/maker-checker"
      }'
# -> 201, { "id": "...", "taskId": "...", "status": "PENDING", ... }

# 2. Checker (in the finance-checkers group) lists what's pending for them.
curl -s http://localhost:8080/api/v1/tasks \
  -H "X-API-Key: $API_KEY" -H "X-User-Id: bob" -H "X-User-Groups: finance-checkers"

# 3. Checker approves (or POST .../reject) with an optional comment. Auto-claims if unclaimed.
curl -s -X POST http://localhost:8080/api/v1/tasks/{taskId}/approve \
  -H "X-API-Key: $API_KEY" -H "X-User-Id: bob" -H "X-User-Groups: finance-checkers" \
  -H "Content-Type: application/json" -d '{"comment": "looks good"}'
# -> 200, status APPROVED, decidedBy/decidedAt set; if callbackUrl was set, a webhook fires now.

# 4. Anyone can check status and the full audit trail at any time.
curl -s http://localhost:8080/api/v1/requests/{id} -H "X-API-Key: $API_KEY" -H "X-User-Id: alice"
curl -s http://localhost:8080/api/v1/requests/{id}/audit -H "X-API-Key: $API_KEY" -H "X-User-Id: alice"

Error responses are a consistent JSON shape (timestamp, status, error, message, path) for every failure: 401 bad/missing API key, 400 missing X-User-Id or failed validation, 403 caller's groups don't match the task, 404 unknown request/task, 409 already claimed by someone else or already decided.

Webhooks

If callbackUrl is set on a request, this service POSTs a small JSON payload to it the moment the request is decided:

{
  "requestId": "...", "entityType": "...", "status": "APPROVED",
  "maker": "...", "checkerGroup": "...", "decidedBy": "...", "decidedAt": "...", "comment": "..."
}

It's sent with Transfer-Encoding: chunked rather than a Content-Length header — any real web framework (Express, Flask, FastAPI, ASP.NET) handles that transparently; only a hand-rolled raw socket/http.server-style receiver needs to decode it itself (see the worked example for exactly that case).

Delivery is synchronous, best-effort, with a short timeout, and is not retried automatically on failure — webhookStatus (SENT/FAILED) and the audit trail always show what happened, so a caller that needs guaranteed delivery should poll GET /requests/{id} as a fallback. A webhook failure never affects the decision itself, which is already durably committed before the webhook fires.

Calling from Node.js / Python / .NET / anything else

There's no SDK, on purpose — it's plain HTTP and JSON. From any language:

POST /api/v1/requests
X-API-Key: <shared key>
X-User-Id: <your authenticated user's id>
X-User-Groups: <comma-separated groups, for checker calls>
Content-Type: application/json

{ "entityType": "...", "payload": { ... }, "checkerGroup": "...", "callbackUrl": "..." }

Whatever your stack already uses for auth, keep doing that for your own users — just forward who they are via X-User-Id/X-User-Groups once they're calling this service.

Running with Docker

docker build -t maker-checker-flowable .
docker run -p 8080:8080 -e MC_API_KEY=change-me -v maker-checker-data:/app/data maker-checker-flowable

Testing

mvn test

Covers the full happy path (create → list → claim → approve → webhook → audit), the rejection path, and the authorization edge cases (missing/bad API key, wrong group, already claimed, already decided).

Versions and known constraints

Built on Spring Boot 4.1.x, Flowable 8.0.0, Java 21. Spring Boot 4's default web stack uses Jackson 3 (tools.jackson.*), which is also what Flowable 8's engine core now uses internally — this project's own JSON handling targets Jackson 3 to match, rather than pulling in the deprecated Jackson-2-compatibility module. If you extend this project and add a dependency that only ships a Jackson 2 integration, check mvn dependency:tree for com.fasterxml.jackson.databind vs tools.jackson.core:jackson-databind conflicts.

The async executor is deliberately disabled (flowable.async-executor-activate: false) since this process has no timers or async steps — every transition after a task is completed happens synchronously, so a client never reads stale status.

Project layout

src/main/resources/processes/maker-checker.bpmn20.xml   the one BPMN process
src/main/java/com/makerchecker/domain/                  ApprovalRequest, AuditEvent
src/main/java/com/makerchecker/service/                 request lifecycle, task actions, webhooks
src/main/java/com/makerchecker/web/                      REST controllers and DTOs
src/main/java/com/makerchecker/security/                 API key + trusted-header auth
examples/expense-approval/                                a full worked example

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages