Repository navigation
Conversation
Each Quarkus capability is an extension: adding one to the pom is enough for its build steps to wire the feature at build time, which is why there is no auto-configuration scanning at startup. Most extensions here (Panache, PostgreSQL JDBC driver, Flyway, Bean Validation, JWT, OpenAPI, health, cache, scheduler) are versioned by the Quarkus platform BOM already imported in dependencyManagement, so none of them carries a version of its own and they cannot drift apart.
quarkus-http-problem is the exception: it lives in the Quarkiverse, outside the BOM, so its version is a property referenced via ${...}. Its Maven group is io.quarkiverse.httpproblem (the older resteasy-problem group stops at 3.32) and 3.33.2 is the last release of the 3.33 line, matching the platform. quarkus-flyway-postgresql is needed because recent Flyway versions ship database support as separate modules.
On the test side quarkus-junit-mockito lets @InjectMock replace CDI beans in service tests. No Testcontainers dependency is added on purpose: Dev Services already starts PostgreSQL for dev and @QuarkusTest as soon as the JDBC extension is present and no datasource URL is configured.
Every 2xx response of the API wraps its payload in this generic record, so clients always find the same success, message, data and timestamp fields whatever the endpoint. A Java record fits because the envelope is immutable data with no behaviour: the compiler generates the constructor, accessors, equals and hashCode, and Jackson serialises it out of the box through quarkus-rest-jackson. The type is deliberately success-only and exposes a single success() factory. Errors follow a different contract (RFC 9457 Problem Details, produced by an extension), so there is no error factory here and no ApiResponse of Void used as an error shape.
List endpoints never return a bare list: they return an ApiResponse whose data is a PageResponse, so pagination metadata travels with the elements. The record carries the page content, the zero-based page index, the page size, the total element count and the total page count. The of() factory derives totalPages from totalElements and size with an integer ceiling division, which keeps that arithmetic in one place instead of repeating it in every service. A non-positive size yields zero pages rather than a division by zero.
Services signal a missing entity by throwing this exception. It extends HttpProblem from the quarkus-http-problem extension, which is itself a RuntimeException that the extension's built-in mapper renders as an RFC 9457 application/problem+json document. Extending it directly means there is no custom ExceptionMapper to write and no DTO to build: the builder sets the type, title, status and detail and the extension does the rest. The problem type is a constant URI so every 404 of this kind is identifiable by clients independently of the human readable detail. The status is 404 and the detail carries the specific message, for example which product id was not found.
This is the second business exception, for requests that are well formed but refused by a domain rule, such as deleting a category that still has products. It follows the same mechanism as the not found exception, so nothing new needs wiring. It maps to 422 Unprocessable Content rather than 400: the syntax of the request is valid, it is the state of the domain that forbids the operation. Keeping that distinction lets clients tell a malformed request apart from a rule violation.
…tion quarkus-smallrye-health already ships a default readiness check, but it only proves that the application is running. This custom @readiness check goes further by borrowing a connection from the pool and asking the driver whether it is valid, so /q/health/ready turns DOWN when PostgreSQL is unreachable. That is the signal an orchestrator uses to stop routing traffic to an instance without restarting it. The connection is obtained in a try-with-resources block so it always returns to the pool, and the DOWN response carries only a short generic reason: exception messages can reveal hostnames or schema details and this endpoint is usually reachable without authentication.
Liveness answers a different question from readiness: should this process be restarted? The check therefore inspects only JVM-local state and reports DOWN when threads are deadlocked, a condition that a restart can actually fix. It also exposes uptime and thread count as data, which makes /q/health/live useful when debugging. The database is left out on purpose. If liveness depended on it, a database outage would make the orchestrator restart every healthy instance, turning a dependency failure into a full application outage. Dependencies belong to readiness only.
Flyway migrations are the single source of truth for the database schema: Hibernate only maps to it and never generates it. V1 creates every table of both domains in one script, the identity and RBAC tables (users, roles, permissions and their join tables, the three token tables, audit logs) and the e-commerce tables (categories, products, customers, orders). The two domains share one database but no foreign key crosses from one to the other. Rules the database can enforce itself are declared here rather than left to code alone: unique email, role name and permission pair, positive price and quantity, and foreign keys with indexes on every referencing column. Join tables and token tables cascade from their owner, audit logs keep their rows when the acting user is deleted, and e-commerce foreign keys do not cascade so a referenced row cannot be deleted silently. No seed data is inserted here.
SmallRye JWT signs tokens with a private key and verifies them with the matching public key, both read from PEM files. Having a pair on the classpath means the application and its tests can issue and validate tokens out of the box, without any setup before the first run. These keys are public by construction since they live in the repository, so they are strictly for development and tests. The production profile deliberately gets no default location: it must be given real keys through the environment, otherwise the application refuses to start rather than silently trusting a key everyone can read.
Configuration keys can be prefixed with %dev, %test or %prod to apply to one profile only, and an unprefixed key is the default for all of them. The datasource url is set only for prod: with the JDBC extension present and no url configured, Dev Services starts a PostgreSQL container for dev and tests by itself, pinned here to version 16 so it matches production. Real connection details come from environment variables and the password has no default. Flyway runs at startup and Hibernate is set to leave the schema alone, so migrations stay the single source of truth; setting it explicitly also prevents Dev Services from switching Hibernate to drop-and-create. The tests use a fixed port because the default test port is frequently taken on a developer machine. JWT settings declare the issuer, the token lifetime and the key locations. The quarkus-http-problem version in use exposes no option for a type URI prefix or for stack traces, so the problem type stays a constant on each exception and stack traces are never included in responses.
The scaffold put four Dockerfile variants under src/main/docker, all expecting a jar built beforehand on the host. The project keeps its Dockerfiles at the repository root instead, where docker-compose finds them, and builds inside the image so that no local Java or Maven setup is needed. The native variants come back with the branch that covers native compilation.
The generated .dockerignore excluded everything except the target directory, which only works when the jar is built on the host before the image. A multi-stage build compiles inside the image, so the context must now include pom.xml and src. Everything else stays excluded to keep the context small and to make sure local files such as keys, environment files or build output never end up in an image layer.
The first stage compiles and packages with Maven, the second keeps only a JRE and the Quarkus output, so the final image carries no build tools. The pom is copied before the sources so Docker caches the dependency download until the pom changes, which makes rebuilds after a code change much faster. The application runs from the fast-jar layout Quarkus produces, whose dependencies live in separate directories that rarely change, and as a non-root user. Tests are skipped inside the build because they depend on Dev Services, which needs a Docker daemon that a build stage does not have; they run in CI instead.
Compose runs the packaged application next to a real PostgreSQL 16. It is only for that use: in dev and tests Dev Services provisions the database by itself, so nothing here is needed to work on the code. The app waits for the database healthcheck before starting, and Flyway then creates the schema on first launch. All settings come from the environment, and the database password is required rather than defaulted so a forgotten .env fails loudly instead of running with a well-known password. The production JWT key pair is mounted read-only from a keys directory that git ignores, and the published port is configurable because 8080 is often already taken on a developer machine.
The workflow checks out the code, installs Java 21 with the Maven cache enabled and runs the whole build through the Maven wrapper, so the CI uses exactly the Maven version the project pins. It triggers on pushes and pull requests targeting master or develop. There is deliberately no services block for PostgreSQL. Dev Services starts its own database container through the Docker daemon that ubuntu-latest runners already provide, the same way it does on a developer machine, so the test setup is identical locally and in CI and nothing has to be kept in sync by hand.
…scaffold The hello endpoint and its two tests only existed to prove that the freshly generated project worked. The real endpoints arrive with the feature branches and the health checks now give a genuine way to see the application running, so keeping the sample would leave dead code and a public route that belongs to nothing in the specification.
A plain JUnit test is enough here because the record has no dependency: it checks that success() marks the envelope as successful and carries the message, the payload and a timestamp. Nothing needs the Quarkus container, so the test runs in milliseconds.
The total number of pages is derived with an integer ceiling division, which is exactly the kind of small computation that breaks on boundaries. The tests cover an exact multiple, a remainder, an empty result and a size of zero, so a future change to the formula cannot silently produce a wrong count or a division by zero.
@QuarkusTest boots the whole application once and RestAssured calls it on the configured test port, so these tests exercise the real endpoints instead of the check classes in isolation. Readiness must report the database check UP, which also proves that Dev Services started PostgreSQL and that the datasource is wired, and liveness must report the application check. No container is declared in the test: Dev Services provisions the database as soon as the test profile starts, so the same test runs unchanged on a laptop and on a CI runner.
The application migrates at startup, so the injected DataSource already points at a migrated schema. The tests assert that the thirteen expected tables exist, that the schema history records version 1 as successful, and that inserting two users with the same email is rejected by the database itself with a unique violation. The last check matters because a constraint declared in SQL protects the data even when application code forgets a validation. The test cleans up the row it inserts so it leaves the shared test database as it found it.
A small resource that exists only under src/test throws the two business exceptions, an unexpected exception and a Bean Validation failure, so the tests can look at what actually goes over HTTP. They assert the application/problem+json content type, the type, title, status and detail fields, the violations array for a validation failure, and the absence of any ApiResponse field on an error. The unexpected exception case also checks that the response leaks neither the exception class nor a stack trace: the extension replaces the details with a generic 500 and only logs them server side. The test resource is not part of the application, it is compiled and exposed only when the tests run.
Everything under src/main/resources is copied into the application jar and therefore into the Docker image. The private key of the development pair is public by construction since it is committed, so shipping it in a production artifact would let anyone who knows it forge valid tokens if a deployment ever fell back to the classpath key. The pair now lives in a dev-keys directory at the repository root, outside the packaged resources. The dev and test profiles point to it through a file location relative to the project root, while the prod profile keeps no default and requires real keys from the environment. A round trip that signs and parses a token confirmed the new locations work, and the built jars contain no PEM file.
The check deliberately returns a short generic reason to the caller, but swallowing the exception left operators with no trace of the real cause when readiness turned DOWN, whether bad credentials, a network failure or an exhausted pool. The exception is now logged at warn level on the server, so diagnosis stays possible while the HTTP response still reveals nothing about hosts or schema.
The nested record was the only new type without the project's Javadoc block, so it now carries the same header as every other type.
The application runs as an unprivileged user whose uid differs from the host user, and a key generated by openssl is readable by its owner only. Without a hint the container could not read the mounted private key and would fail at startup with a permission error. The setup comment now asks for readable key files and reminds that the directory is ignored by git and mounted read-only.
…built The core-architecture checklist is ticked now that each task is implemented and covered by a passing build. The references that turned out to be outdated are corrected: the Quarkus stream is the 3.33 LTS line, and quarkus-http-problem is published under the io.quarkiverse.httpproblem group and package rather than the older resteasy one. The checklist item about configuring the problem type prefix and stack traces now states the actual behaviour: the version in use exposes no such options, so the type is a constant on each exception and stack traces are never included in a response.
This completes the move of the development key pair out of the packaged resources. A profile list such as %dev,test applies one value to several profiles at once, so dev and test read the keys from the file system relative to the project root, while prod keeps requiring real key locations from the environment and has no default. The comment above the settings explains why the location matters: only files outside src/main/resources stay out of the jar and the Docker image.
Every branch goes through a pull request, so the template gives each one the same structure: which branch it is, the README checklist copied and ticked, a short commit summary, and two checklists. The test checklist states what must be green before merging, and the review checklist turns the project's non-negotiable rules into questions a reviewer answers one by one, such as declarative permission checks or errors rendered as Problem Details. Having those rules written next to every change makes them hard to forget and gives a review a concrete list to work through instead of an impression.
The commit convention is only useful if it holds for every commit, so a second workflow checks it automatically. It walks the commits between the base and the head of the pull request, skips merge commits, and fails when a subject does not match the type(scope): summary shape with one of the allowed types. The check reads the history rather than the pull request title because the branches are merged with a merge commit and each atomic commit stays visible. Fetching the full depth is required, otherwise the base commit would not exist in the checkout and the range could not be computed.
feat(core-architecture): project scaffold, error handling, health checks, schema and Docker/CI setup
The service test now mocks the order repository and adds the refusal case, while the existing case still covers deletion without orders.
The service test mocks the order repository and adds the refusal case next to the deletion without orders.
The three tasks are ticked: the entity, repository and service with the computed total, the resource, and the tests.
feat: orders with a computed total
The ignore file excludes everything except what the image builds need. The native image is built by a Mandrel builder image that ships no Maven, so it runs the project's Maven wrapper, and the wrapper script and its .mvn directory must therefore be part of the context. Everything else stays excluded, so the context remains small and free of local files such as keys and build output.
The first stage compiles the application to a native executable with Mandrel, Red Hat's GraalVM distribution, through the pom's native profile. The second stage copies only that binary onto a micro runtime image with the few C libraries it links against: no JVM, no Maven and no sources ship, which is where the small image and the fast start come from. It mirrors Dockerfile.jvm on purpose, with the dependency download cached before the sources are copied, tests skipped in the build stage because Dev Services needs a Docker daemon, and a non-root user at runtime.
The script starts the application in the mode it is given, waits for the readiness endpoint, sends the same fixed mix of requests, and prints one table row with the time until ready, the startup time Quarkus reports and the resident memory after the load. Running the identical script on the JVM jar and on the native binary is what makes the comparison fair. The memory is read after the load and not at idle, since a JVM grows once it has served traffic while a native binary starts close to its steady size.
A separate job builds the native executable in a Mandrel container, measures JVM mode against native mode with the measurement script, publishes the table in the job summary, and checks that Dockerfile.native builds. It is independent of the test job, so its many minutes never delay the fast feedback of the tests. Unlike the test job it declares a PostgreSQL service: Dev Services only exists in dev and test mode, and the packaged application needs a real database to start.
The native build failed because a static SecureRandom is created while the GraalVM image is built: its seed would be frozen into the image heap, and every started instance would produce predictable tokens, so the compiler refuses it. The generator is now a field of the application scoped bean, created when the running application starts. It is seeded for real at run time, and behaves the same in JVM and native mode, so this is a correctness gain and not only a workaround.
The port was given as a -D option after the command, which for a jar lands after -jar and is passed to the application as an ordinary argument, so the JVM ignored it and the script probed a port nobody listened on, forever. An environment variable is read by Quarkus in every packaging mode, so the same line now works for the jar and for the native binary. The readiness wait also gives up after two minutes and prints the end of the log, so a misconfigured start fails the job with an explanation instead of hanging it.
The notes explain the two ways to build the executable, the Dockerfile and the Maven container build, and give the figures measured by the CI job for the same load in both modes: startup goes from about four seconds to about a tenth of a second, and memory after the load is about halved. They also list the caveats, so the numbers are read as an order of magnitude and not as a benchmark. They record the one code change the native compiler forced, the static random generator, because it shows the closed world model in practice: whatever runs at class initialisation is executed at build time. They also say why the build was done in CI, since a local Docker VM of 1.4 GiB cannot hold the compiler.
The four tasks are ticked. The local build task carries a note saying the executable was built by the CI job, because the development machine's Docker VM is too small for the native compiler, and points to the notes file for the figures.
The exit trap now waits for the process after stopping it, so when the JVM measurement is followed by the native one, the port is really free and the second start cannot be answered by the first application still shutting down. The load loop also checks each status code. A refused connection or a server error now fails the run instead of being counted as load, since figures taken while the requests never reached the application would look plausible and mean nothing.
feat: native build and startup measurements
…QL client The two extensions sit next to the blocking JDBC stack. Both talk to the same PostgreSQL database, and Dev Services still provisions the container, so the tests need no manual container setup. Their versions come from the Quarkus BOM. The reactive slice of the project is deliberately small, one streaming endpoint, to show that blocking and reactive code coexist in one application.
…atasource A persistence unit is either blocking, over JDBC, or reactive, over the Vert.x client, never both. The existing entities stay in the default unit, and a named reactive unit maps only the package holding the streaming entity. Schema management stays off there too, because Flyway is the only owner of the schema. The named unit needs a named reactive datasource, which reuses the connection Dev Services computes for the default one, so no second empty database starts. In production the reactive client expects a postgresql:// URL and not the JDBC one, so it reads its own variable.
The packaged application now needs a reactive URL in addition to the JDBC one, since the reactive client does not accept the jdbc: form. It points at the same host and database, and the user name and password are reused, so nothing new has to be set in the environment file.
This read-only mapping of the orders table lives in its own package because it belongs to the reactive unit and not to the blocking one. Customer and product are mapped as plain id columns, so the blocking entities never have to be dragged into the reactive unit. It is never written: the blocking order service owns the writes and Flyway owns the schema. The entity only exists so the streaming endpoint can reload a committed order without blocking.
It follows the same repository pattern as the blocking side, taken from the reactive Panache variant: every method returns a Mutiny Uni, an asynchronous result of zero or one item, instead of a value. It is used only by the streaming endpoint, and the blocking repository and service keep serving everything else.
The event is a plain record carrying only the id of the order. Consumers reload the row after the commit, so the event never holds an entity that could be stale or attached to a closed session.
The bean observes the order created event with the AFTER_SUCCESS transaction phase, so the observer only runs once the creating transaction commits and never for a rolled back order. It pushes the id into a hot broadcast processor, which delivers it to every current subscriber and replays nothing to late ones. Each subscription gets its own bounded buffer, so a slow client fails alone and order creation never waits for anyone. It also hops back onto the Vert.x context of the request before reloading the order through the reactive repository, since Hibernate Reactive must run on such a context.
After persisting the order, the blocking service fires a synchronous CDI event inside its transaction. It knows nothing about who listens, which keeps the imperative code untouched and lets the reactive side decide when to react: observers declared for the after-success phase only run once the transaction commits.
GET /api/v1/orders/stream returns a Mutiny Multi as Server-Sent Events: one long-lived response with one JSON event per new order. Quarkus REST subscribes and applies backpressure, so there is no manual thread handling. The success envelope does not apply to a stream, each element is a bare order response, and the same ORDER:READ permission protects it. The method is marked blocking because the token blacklist filter runs a JDBC query, which is forbidden on the event loop where a Multi endpoint would otherwise be dispatched. That only concerns the request pipeline, the stream itself stays reactive.
Creating an order now fires an event, so the plain Mockito tests, which build the service without a container, need a mock of the event source to avoid a null pointer. Their assertions are unchanged.
The tests subscribe with an AssertSubscriber and wait with a timeout, so the test thread is never blocked. They check that a committed order arrives with all its fields, that a rolled back one emits nothing, that two subscribers both receive it, and that a late subscriber gets no replay. The subscription runs in a duplicated Vert.x context marked safe, which is what Quarkus REST provides for each request and what Hibernate Reactive Panache requires.
A JDK HTTP client opens the stream asynchronously, an order is then posted through the normal endpoint, and a data line with the new order must arrive within a timeout. The test also checks the event stream content type, the 401 without a token and the 403 without the read permission, and closes the stream at the end so no connection leaks.
The five tasks are ticked: the reactive dependencies and persistence unit, the reactive repository, the CDI event bridged into a Multi, the SSE endpoint, and the tests.
Each broadcast id is reloaded from the database before it is sent. A missing row or a transient error used to fail that step and terminate the whole subscription, so a client would silently lose every later order until it reconnected. A missing row is now skipped, and a failed reload is logged and dropped, so one bad element costs one event and not the connection.
feat: reactive SSE stream of new orders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch
develop -> master (release of the whole tutorial)
Task checklist
Commit summary
Every feature branch was merged into
developthrough its own pull request with a green CI, aftermvn verifyand a code review. This pull request promotesdeveloptomaster: the full identity and RBAC domain, the e-commerce domain (categories, products with a cache, customers, orders), the GraalVM native build with measurements, and the reactive SSE stream of new orders.Test checklist
mvn verifyis green on the whole project (188 tests), and the native CI job is greenCode review checklist
ApiResponse<T>, errors are RFC 9457 Problem Details@PermissionsAllowed)@CacheResulthas its matching@CacheInvalidateAuditLogger