service.abstract.md

A short markdown file beside a service module. It holds the invariants — rules that must always hold — which the code obeys but cannot explain, and nothing else.
One rule from the oauth module shows the difference:
What the Code Says
refreshRotationGraceMs = 30_000
oauth.service.ts hands this window to refreshSession: a refresh token reused within 30 seconds of its rotation is rotated again, not revoked.
What the Abstract Adds
Why. A client that holds the same token twice is not a thief, and treating it as one signs the user out of an app that did nothing wrong.
The second card is the abstract's whole job. The file sits in the module folder; the folder keeps its underscore and the file name drops it: lib/_oauth/oauth.abstract.md.
When to touch it
  • Before you change the module, read it first.
  • When an invariant, a workflow or public behaviour changes, update it.
  • When only formatting, imports or style change, leave it alone.

The Four Parts

An abstract has four parts, and the last is optional. All thirty-three abstracts in this workspace open with a title, one sentence and ## Rules, and so does the scaffold a new service module starts from.
The whole skeleton:
apps/koyo/lib/_payment/payment.abstract.md
1# payment Service Abstract23<One sentence: what this module owns, stated as fact.>45## Rules67- <An invariant the code obeys but cannot explain.>8- <Two to five of them.>910<state> -> <state> -> <state>
# <service> Service Abstract
One title line: the module name as the folder spells it, minus the underscore.
One sentence
What the module owns, stated as fact rather than a promise. No heading above it.
## Rules
Two to five bullets, each an invariant a reader could not derive from the code.
Workflow chain
Optional. One line with no heading: bare arrows between states.
authorize -> pending -> approved | denied -> code
A real one: oauth
libs/shared/lib/_oauth/oauth.abstract.md is the best one in the workspace. Here it is in full, unedited:
libs/shared/lib/_oauth/oauth.abstract.md
1# oauth Service Abstract23Issues, from the same process that serves `/mcp`, the OAuth 2.1 tokens that MCP endpoint accepts: authorization-server4metadata, authorization with PKCE and a consent page, client registration, token exchange and refresh.56## Rules78- Every access token is signed with the app's own secret and names the MCP endpoint as `aud`, so `AccountMiddleware`9  accepts it unchanged and `McpAuth` verifies it through `option.setMcp`. Guards stay the only authorization decision;10  no scope narrows what the token may do.11- An authorization request lives ten minutes, binds to the first signed-in account that opens it, and is decided once.12  A code lives sixty seconds and is consumed on first exchange, whether or not that exchange succeeds.13- PKCE `S256` is the only method. A redirect URI must be registered and match exactly, except that a loopback address14  may vary its port; a private-use scheme is accepted only when configuration names it.15- Refresh tokens rotate on use through `refreshSession`; a token reused within thirty seconds of its rotation is answered with16  a rotation of its own (a client that holds it twice is not a thief), one reused later revokes that grant's lineage only — never17  the account's other sessions. A refresh presented by a client other than the one it was issued to is refused.18- Registration is open (RFC 7591), rate-limited per address and public-client only; a `client_id` that is an HTTPS URL is19  read as a Client ID Metadata Document — resolved first and refused when it points into a private range, never fetched20  from the server's own network — unless configuration turns the feature off.21- A grant is revoked as a whole (RFC 7009 `/oauth/revoke` by the client, or the account's owner disconnecting it): its22  refresh lineage is closed and the lineage id is denylisted for an access token's lifetime, which is how a stateless23  token dies early. Revocation answers 200 whether or not the token was live, so it cannot be used to probe tokens.24- A token this server minted names its client and the MCP resource; a browser session names neither. That difference is25  what `isAgentCall` / `Person` read to keep an act a person may take from being taken on a model's say-so.26- None of these endpoints is published to MCP: they are the protocol and the account's own controls, not tools.2728authorize -> pending -> approved | denied -> code -> token -> refresh -> revoked
  • Eight rules and one chain. The service file runs to about five hundred lines, so it carries more than the usual two to five.
  • No field lists, types or signatures. A name such as AccountMiddleware or refreshSession appears only to say who enforces the decision.
  • Every rule is a decision. Left unwritten, the next reader would have to reverse-engineer it from the code.
  • More than half guard security. They stop a plausible change to PKCE, redirect matching, token reuse or revocation from opening a hole.

Fill In The Scaffold

A new service module starts with an abstract already in this shape: its title, a placeholder sentence and two placeholder rules. Every line in angle brackets is a prompt, and none of them survives the first real edit.
What akan create-service payment writes:
apps/koyo/lib/_payment/payment.abstract.md
1# payment Service Abstract23<One sentence: the workflow or integration this service owns, stated as fact.>45## Rules67- <An invariant the code obeys but cannot explain: a lifetime, a refusal, an ordering, and its reason.>8- <Two to five of them. If the service moves something through states, end the file with one arrow line.>
What each line becomes:
# payment Service Abstract
Written for you from the folder name, minus the underscore. Keep it.
<One sentence …>
Replaced by what the module owns, stated as fact.
## Rules
Stays. Both placeholder bullets become the module's real invariants, two to five in all.
Workflow chain
Not in the scaffold. Add one last line of arrows if the service moves something through states.
A field's meaning
Not here: a trailing comment beside the field, in the constant.ts that declares it.

What Counts As A Rule

Use the same test as for code comments: does this sentence carry a fact that is nowhere in the code? A bullet that passes stays true for years; one that fails goes stale the first time a field is renamed.
Worth a bullet
A lifetime or threshold, and its reason
A code lives sixty seconds; an authorization request lives ten minutes.
A refusal that looks like an oversight
Revocation answers 200 whether or not the token was live, so it cannot probe tokens.
Why an obvious alternative was rejected
A client holding the same refresh token twice is not a thief.
A scope boundary enforced call by call
A late reuse revokes that grant's lineage only, never the account's other sessions.
Not worth a bullet
  • Field lists, types and method signatures. The constant and signal files are shorter than a sentence describing them.
  • What the root AGENTS.md already tells every module, such as keeping business behaviour in the service.
  • To-dos, roadmaps and related-module lists. The import graph already shows which modules are related.
Language
Korean is normal in an abstract and common here: security, util, localFile and shared are all written in it. What is never normal is a language split inside one file.

Released under the MIT License

Connect your AI to these docs

MCPhttps://akanjs.com/mcp
Copyright © 2026 Akan.js All rights reserved.System managed bybassman