GraphQL, gRPC and Living API Documentation
GraphQL and gRPC are extra adapters over the same tools, and OpenAPI docs can come straight from Schema-layer definitions. Where each concern belongs in LVD.
Every codebase has one: a REST route that grew to eighty lines. It checks a loan limit, computes a late fee, sends a notification and then, finally, returns JSON. When the mobile team asks for a GraphQL version, somebody copies the whole thing. LVD's Layer 5 exists to stop that story at the first route, by giving the API layer a single job.
Layer 5 is the main doorway for human-facing clients: web and mobile applications, partner integrations and other internal services. It carries a volatility coefficient of 0.85, reflecting how often endpoint shapes, versioning schemes and protocol choices change compared with the business logic beneath.
It may depend on the Tools layer and below. In return it is held to a hard constraint: no business logic, no validation rules and no domain calculations. Its sole responsibility is translation. Take in a protocol-specific request, delegate to the right tool handler, and shape the tool's result into a protocol-specific response. If a decision about the business is happening in this layer, it is in the wrong place.
REST models the domain as resources with addresses. In LVD those resources line up with schemas in Layer 1 and operations in Layer 4, so each tool maps naturally onto a verb and a path. A typical route is almost nothing but plumbing:
router.post(
"/api/v1/bookings",
authenticate,
validateBody(CreateBookingParams), // schema comes from L1
wrap(async (req) => {
const result = await createBookingHandler({ ...req.body, guestId: req.user.id });
return { status: 201, body: result.data };
}),
);
A few details are worth noticing. The body check applies a Layer 1 schema, so the route enforces a rule it does not own. The identity of the caller comes from the authentication step and is passed in as ordinary data. And the handler returns a status and a body instead of touching the response object, because a small shared wrapper deals with that part and with translating errors.
Tools signal problems with domain errors. The API layer owns the conversion to HTTP, and the book wants that conversion in one central place rather than scattered through route code. The mapping is the following:
The last line deserves a second look. For unexpected failures the client receives a deliberately bland message, so internals do not leak out through an error string. A central error handler looks up each error's class in a map and falls back to 500 when it finds nothing. That keeps individual routes free of try and catch noise, and it means a change to the error format is a change in one file.
REST APIs eventually need versions, and the book compares three common approaches.
/api/v1/bookings): explicit and easy to discover, though routes multiply as versions pile up.The book favours the path version for LVD systems. Its argument is that LVD values explicit dependency declaration, and a version that appears in every route definition and every import path is as explicit as it gets. Whether you agree for your own system, the reasoning is a useful example of applying the model's values to an ordinary design choice.
A well-formed REST layer is thin enough to read in a minute. Translate in, delegate, translate out, and map errors in a single place. Everything interesting happens a layer down, which is why the same tool can later be exposed through a second protocol without being rewritten. That is the subject of GraphQL, gRPC and living API documentation. Who is allowed to call these routes is the concern of the authentication sublayer, and the layer's place in the stack is described on the Layer 5 page.