Skip to content

Task Workflow Server

In plain English

A team task management web API with signed user authentication and step-by-step status rules preventing work from skipping required stages.

A Java 21 and Spring Boot 3.3 workflow REST API with JWT authentication, state-machine enforcement, multi-criteria JPA queries, and RFC 7807 ProblemDetail.

1. Why I built it

Built to practise clean Spring Boot layering, stateless security filters, scalar repository queries, and integration testing with MockMvc.

Problem being solvedUnrestricted updates break workflow ordering, lazy entity collections cause N+1 SQL queries, and weak or short JWT keys introduce configuration bugs.

2. How it works

Structured across `controller`, `service`, `repository`, `domain`, `security`, and `dto` packages, with Docker and PostgreSQL Compose support.

Permissive CRUD endpoints let API consumers jump straight from `BACKLOG` to `DONE` and expose unstructured error payloads. Spring Workflow API models valid transitions inside `TaskStatus.canTransitionTo()` with Java 21 pattern-matching switch expressions and maps violations to HTTP `422 Unprocessable Entity` using Spring's RFC 7807 `ProblemDetail`.

Authentication pairs BCrypt password hashing with stateless HS256 JWT bearer tokens guarded by a minimum 32-byte non-blank key check inside `JwtTokenService`. Project summaries avoid N+1 lazy collection loads by querying `taskRepository.countByProjectId(project.getId())`.

Integration tests execute cleanly offline against H2 in PostgreSQL mode via MockMvc, complemented by a multi-stage `Dockerfile` (`1.2.0`) and PostgreSQL 16 Compose stack.

3. Output & Source Specimen

TaskStatus Finite State Machine & REST Error Mapping

01BACKLOG ---> IN_PROGRESS | ARCHIVED (BACKLOG -> DONE => HTTP 422 ProblemDetail)
02IN_PROGRESS ---> BACKLOG | IN_REVIEW | DONE | ARCHIVED
03IN_REVIEW ---> IN_PROGRESS | DONE | ARCHIVED
04DONE ---> IN_PROGRESS | ARCHIVED
05ARCHIVED ---> BACKLOG
Legal state transitions enforced by TaskStatus.canTransitionTo()Run checks: mvn test -B

Interactive status checker (mirrors the real workflow switch rules)

Task Workflow Rules

Check Which Task Moves Are Allowed

See project details
Backlog
Current
In Progress
Valid next
In Review
Skipped
Done
Blocked target
Archived
Valid next
1. Pick starting stage
2. Pick destination stage
Blocked Automatically

Backlog -> Done

Blocked before reaching the database so tasks cannot skip review steps.

4. Design Decisions & Challenges

Key Design Decisions

  • 01.Placed transition rules directly on `TaskStatus` so state constraints are unit-testable outside Spring.
  • 02.Replaced `project.getTasks().size()` with scalar `taskRepository.countByProjectId()` queries.
  • 03.Enforced non-blank >= 32-byte secret keys in `JwtTokenService`.

Edge Cases Handled

  • Verifying authenticated routes, partial `PATCH` mutations, `409` duplicate keys, and illegal `422` jumps end-to-end inside `TaskFlowIntegrationTest`.

5. Testing & Limits

Automated Checks

Verified by 5 MockMvc integration tests in `TaskFlowIntegrationTest` covering case-normalised auth registration, `422` transition guards, `PATCH` edits, `409` conflicts, grouped project task-count aggregation, `GET /api/v1/tasks/stats`, and filtered pagination.

Current Limits & Next Steps

  • Uses short-lived stateless JWTs without a server-side token revocation blocklist or refresh token rotation.

6. Key Takeaways

What building Task Workflow Server reinforced

RFC 7807 `ProblemDetail` gives clients uniform error parsing, and failing fast on short JWT secrets catches config errors at startup.

  • — 5 MockMvc integration tests and Maven builds pass in CI.
  • — Source hosted at github.com/16lv/spring-workflow-api.

Recent Activity

Latest repository updates

All changes for 16lv/spring-workflow-api

feat: normalize email inputs in AuthService and add GET /api/v1/tasks/stats

Trimmed and lowercased registration/login emails inside AuthService and added grouped task status counts via TaskController.getTaskStatusStats().

2026-11-2403a5b00

perf: aggregate project task counts in a single grouped JPQL query

Replaced per-project countByProjectId and countByProjectIdAndStatus lookups inside WorkflowService.listProjects() with a grouped TaskItemRepository.findProjectTaskCounts() projection.

2026-11-2354a3587

Add owner-checked project deletion with 403 Forbidden ProblemDetail handler

Added DELETE /api/v1/projects/{code} enforcing project owner verification via Spring Security AccessDeniedException mapped onto RFC 7807 403 responses.

2026-11-21f03d30a