From Requirement To Design
A Klok integration starts with a business requirement, not a route class. This page is the architect's part of the way: turning the business need and its information needs into a design that developers can build, written down as the solution document before the first route. The whole way, with who does what at each step, is From Business Need To Running Integration, and the business's part of the first steps is in the same chapter.
Workflow Overview
Step 1: The Business Need
The need comes from the business, in business language: the problem, the outcome, the owners, the systems, the volumes, and how fresh, available and recoverable the information must be (Describing The Business Need). Check that it names the owning tenant and domain, every system and its owner, the volumes and the service levels, and turn every gap into an open question rather than an assumption.
Step 2: Context Analysis
Search existing assets before creating new ones: solutions, systems, datamodels, topics, integration projects, existing legs, generated documentation, open issues and Kloker findings. Finding What Already Exists lists where to look and what the analysis produces: reusable components, new components, information model levels, legs and patterns, topic names and open questions.
Use Kloker when helpful (Ask Kloker, or an impact analysis started on Kloker → Tasks in klok.dev), and treat its
output as analysis that must be reviewed. A change starts as a change request on Build → Changes, where Plan with
Kloker drafts the plan as a merge request in the registry and the change request's page follows the questions, issues,
merge requests and beads until the change is done (Changes and
work); klok agent plan runs the same
planning from a terminal. The older planning workspace on a solution's page fails in production today
(frontend-klok-dev#79).
Step 3: Solution Shape
Decide whether the flow is a standard event flow, a batch flow, a request-reply exception, a tenant bridge, a schema migration bridge, or a tactical workaround.
Key questions:
- Is the source push or pull?
- Is the target event-driven, file-based, API-based, or queue-based?
- Is immediate response required? Work that can take longer than a request's time budget is a task behind a
202, not a long synchronous call (Event-driven with sync compatible interfaces). - Is strict ordering required?
- Is payload size large enough for claim check or chunking?
- Do other systems or domains read the information? Then it travels as class B or C.
- Are there cross-tenant ownership issues?
Step 4: Model Decisions
Choose or create the model that belongs on the broker (see Creating A Datamodel). The business owns the meaning of the information, and its answers (owners, readers, freshness, the rules that give the information its meaning) are collected in From Business Need To Information Needs. Data shared between systems or domains should normally travel as Class B or Class C. Class X may be sent over the broker too; when it is, record which readers depend on that system.
Step 5: Legs And Patterns
Split every flow into legs. One service that polls a system, maps the data and posts it to another system hides three legs. Onramps and offramps stay thin, handling protocol and format; enrichment, splitting and aggregation belong in a processing leg or in a framework capability.
Choose the smallest route pattern that fits:
- Onramp for source system -> broker.
- Processing for broker -> broker transformations.
- Offramp for broker -> target system.
- Channel adapter for protocol conversion only, the payload as received: when it already is the model the readers need, or when receiving with minimal handling is motivated and a later leg maps (Ingress, egress, onramp and channel adapter).
- Custom only when standard patterns cannot express the flow.
- Sync variants only when the caller truly requires request-reply.
Name every leg with its route id, <TENANTSHORT><NNN><LEG><seq>_<Description>: the solution id, the leg letter (I
ingress, P processing, E egress, A API, S sub route, T timer) and a sequence not used before for that leg in
the solution. The route id is also the class name and the configuration prefix (Naming
Standards).
Integration logic is written as Java Klok routes on the Klok Quarkus extension: they are documented by the platform with
their topics, datamodels and configuration, and related integrations group in one project and reuse its services. Doing
integration work with the Python or TypeScript broker clients, or inside an application, is a tactical choice; the
solution document tags it [TACTICAL] with its motivation, its cost and the condition for removing it. An external
engine the solution uses (a GPU model server, a vendor service) stays a simple REST service; priority, queues, retries,
claim checks and task state live in a Java leg.
Step 6: Topics, Purposes And Access
- A topic carries one datamodel and is named after it. The framework computes the name from the datamodel and the purpose, so nobody writes a topic name by hand.
- When one datamodel serves several flows, each flow gets a purpose. The purpose is the publisher's: the solution requires it, the producer sets it and the consumer reads the same one (Topic Purpose). The legs table names the purpose of every topic.
- Write narrow, consume wide. A service publishes only in its own tenant's namespace. Reading a topic of another domain or
tenant is a
consumegrant on that one topic, approved by its owner. The topic decides the tenant, never a field in the message. - Topics are not created automatically. klok.dev creates the generic topic of a datamodel when the datamodel is published, and Ensure does it for a datamodel made in GitLab; purpose topics, request/reply pairs and grants are requested in klok.dev or in a merge request to the tenant's broker file (Topics On The Klok Broker).
Step 7: Write The Solution Document
The design is written down before the first route, as the solution document in the tenant's integration-solutions
registry (solutions/<SOLUTIONID>_<slug>/README.md and solution.meta.json; the registry's own README lists the
sections). Besides the business context, the systems, the datamodel and the flows, it answers two questions that decide
the amount of work:
- Which services does the solution need, and of which kind? A new project, new routes in an existing project, an existing service that needs a slight change, an existing service reused as it is, or a change in a client application.
- Which legs are there, and how do they interact? Every route with its id, project, pattern, topics and datamodels,
and the flows between them as diagrams. A leg that is not built yet is marked
planned.
A new solution's id is taken from the code, never from the next free number: search the integration repositories,
including branches that are pushed but not merged, and run klok solutions validate in the registry. Adding the
solution's solution.meta.json on main is what allocates the id. Route details and configuration stay in each
project's klok-docs/, and the solution document links to them instead of copying them.
Step 8: Review Before Code
Before coding, the design should be clear enough that another developer can explain:
- What each route does.
- Which data class is entering and leaving each route.
- Which topic each route consumes or publishes, with its purpose.
- How failures are observed.
- How access and secrets are handled.
- What tests prove the behavior.
The solution document is reviewed as a merge request, and the business approves the sections that are its own (Reviewing A Solution Document).
Maintenance Follows The Same Path
A fix or a change to an existing flow starts from the same place: find the solution from the route id's prefix, read its
document, and check that it still matches the code with klok solutions check. A change that adds, removes or alters a
leg (a topic, a purpose, a datamodel, an API, a task type) updates the solution document in the same change as the code,
so the registry keeps describing the integration landscape that is built and deployed. When the document and the code
disagree, the code on main is what is built; correct the document, or file an issue when the code is the one that is
wrong. Coding agents follow this process through the klok-solution skill.