Skip to content

Commit f4b16db

Browse files
authored
docs(api): add API stability policy (G3) (#88)
Wires up Track G3 from the v1.6.5→1.7 readiness taskboard — the third and final onboarding-clarity PR for the 1.6.6 Maven Central debut (after G1 which-template-system #86 and G2 examples-maturity #87). ADR-0003 defines the @internal annotation mechanism, but there has been no user-facing policy that tells callers: - What "Stable" actually promises across patch / minor / major. - Where Extension SPI sits and what the @beta annotation will mean once it lands. - That sealed hierarchies in Stable types can grow new permits in minor releases — and what that means for exhaustive switch code. - How long a @deprecated element stays before it goes away. - Which package belongs to which tier without reading Javadoc per element. docs/api-stability.md is the user-facing policy: §1 Stability tiers — Stable / Extension SPI / Internal / Experimental with marker, scope, breaking-change rules, and the explicit promise each tier carries. §2 Sealed hierarchies — additive permits must degrade gracefully without default-branch failures; CHANGELOG names every new public permit; @internal sealed types are explicitly outside the policy. §3 Deprecation window — ≥ 1 minor release with @deprecated for Stable / Extension SPI; removed in next major (Stable) or next minor with CHANGELOG callout (Extension SPI). Internal / Experimental: no window required. §4 Per-package tier — lookup table covering com.demcha.compose.* plus the legacy packages. §5 Anti-policy — what we explicitly do NOT promise (pixel- stable PDFs, bit-stable bytes, sealed-permit exhaustiveness in Stable across minor releases). §6 References — cross-links to ADR-0003 / 0004 / 0011 / 0015 and the architecture guard tests that pin the policy in code. CanonicalSurfaceGuardTest.PUBLIC_MARKDOWN_ALLOWLIST gains a new entry for docs/api-stability.md (same audit-log precedent as the G1 which-template-system page and the v1.5→v1.6 migration log) — the §4 tier table and §3 deprecation example name retired legacy types on purpose. Cross-links from §1 and §4 point at G1's which-template-system page for the template-surface migration path; the two pages reference each other naturally (templates page covers template surfaces; this page covers everything else). Verification: - ./mvnw -B -ntp test -pl . -Dtest='CanonicalSurfaceGuardTest,DocumentationCoverageTest,DocumentationExamplesTest,VersionConsistencyGuardTest' -> 30 tests, 0 failures, 0 errors (~19s) CHANGELOG entry added to v1.6.6 — Planned under the existing ### Documentation subsection alongside G1 and G2.
1 parent d464658 commit f4b16db

3 files changed

Lines changed: 251 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ JitPack continue to resolve through the existing coordinates.
6666
maturity legend introduces the five tiers and links to
6767
`docs/templates/which-template-system.md` for the V1 → V2 path that
6868
the **Legacy** tier points at.
69+
- **New API stability policy: [`docs/api-stability.md`](docs/api-stability.md)**
70+
(Track G3). User-facing companion to
71+
[ADR-0003](docs/adr/0003-api-stability-and-internal-marker.md): pins
72+
the four stability tiers (**Stable**, **Extension SPI**, **Internal**,
73+
**Experimental**) with what each one promises in patch / minor /
74+
major releases, the sealed-hierarchy permit-list policy (additive
75+
variants must degrade gracefully without `default`-branch failures),
76+
the deprecation window (≥ 1 minor release with `@Deprecated`, removed
77+
in next major), a per-package tier-lookup table for the canonical
78+
surface plus the legacy packages headed for 2.0 removal, and an
79+
"anti-policy" section (no pixel-stable PDFs, no bit-stable artefact
80+
bytes, no sealed-permit exhaustiveness across minor releases for
81+
Stable hierarchies). `CanonicalSurfaceGuardTest` allowlist extended
82+
so the page can name `com.demcha.templates.*` / `com.demcha.compose.v2.*`
83+
and the legacy `pdf(Path)` factory in the package-tier and
84+
deprecation-example sections.
6985

7086
## v1.6.5 — 2026-05-30
7187

docs/api-stability.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
# API Stability Policy
2+
3+
GraphCompose follows **Semantic Versioning** (major.minor.patch). This
4+
page is the user-facing contract for which parts of the public surface
5+
that promise covers, what breaking changes are allowed in each release
6+
type, and how sealed hierarchies, deprecations, and unannounced
7+
internal changes are handled.
8+
9+
The mechanism side of the same decision — how `@Internal` is wired up
10+
and which guard tests enforce it — lives in
11+
[ADR-0003](adr/0003-api-stability-and-internal-marker.md). This page is
12+
the **policy** that ADR's mechanism enforces.
13+
14+
---
15+
16+
## 1. Stability tiers
17+
18+
Every public class, method, field, and annotation that lives under
19+
`com.demcha.compose.*` falls into exactly one of six tiers. The tier
20+
is signalled by the package it lives in (with one exception, `@Internal`,
21+
which can appear on individual elements too) and by an explicit
22+
annotation marker where one exists.
23+
24+
The **Supported** and **Legacy** tiers mirror the same labels used in
25+
[`docs/templates/which-template-system.md` § 1](templates/which-template-system.md):
26+
this page is the package-wide version of that template-only status
27+
matrix.
28+
29+
| Tier | Marker | Used for | Breaking changes allowed in |
30+
|---|---|---|---|
31+
| **Stable** | _(default — no annotation)_ | The canonical authoring surface that user code is meant to call: `GraphCompose.document(...)`, `DocumentSession`, `DocumentDsl`, `RowBuilder` / `SectionBuilder` / `ParagraphBuilder` and friends, `DocumentInsets` / `DocumentColor` / `DocumentTextStyle`, the `BusinessTheme` and `CvTheme` factories, the recommended template presets in `cv.v2.*` and `coverletter.v2.*`. | **Major releases only.** |
32+
| **Supported** | _(no annotation; called out in the page's Javadoc)_ | A canonical surface that ships through 1.x but won't be in 2.0 — its replacement is already the Stable path. The `cv.presets.*` "classic" CV preset surface is the only Supported tier in 1.x today (replaced by `cv.v2.*` per [`which-template-system.md`](templates/which-template-system.md)). Bug fixes + behaviour-preserving refactors only. | **Minor releases for behaviour-preserving refactors; removed wholesale in 2.0.** |
33+
| **Extension SPI** | `@Beta` _(annotation arriving in a near-term 1.6.x release; this row already describes the policy that will apply)_ | Public extension points that authors are expected to **implement**, not only call: render-handler interfaces, `NodeDefinition`, custom `Theme` subtype contracts, fragment payload interfaces designed for extension. | Minor releases, with a one-minor deprecation window where possible. |
34+
| **Experimental** | `@Beta` _(same annotation as Extension SPI; the distinction lives in the docstring)_ | A brand-new public type shipping in its first minor release before its contract has stabilised. The contract is in active flux. | Any minor release, including removal. No deprecation window. |
35+
| **Internal** | [`@Internal`](../src/main/java/com/demcha/compose/document/api/Internal.java) (per-element or per-package) | Engine surface: everything in `com.demcha.compose.document.layout.*`, `com.demcha.compose.engine.*`, render-pipeline payload records, `LayoutCompiler`, `NodeDefinitionSupport`, the placement / measure / split contracts. Technically `public` for cross-package collaboration; not part of the contract. Canonical list lives in [ADR-0003](adr/0003-api-stability-and-internal-marker.md) § *Coverage*. | **Any release.** No deprecation window, no CHANGELOG entry required. |
36+
| **Legacy** | _(no annotation today; flagged in [`which-template-system.md`](templates/which-template-system.md) § 4 and in CHANGELOG `### Deprecations`)_ | Pre-rebuild surface kept only so downstream callers from before the v1.6 rebuild keep compiling: `com.demcha.templates.*` (the original `MainPageCV` / `MainPageCvDTO` / `ModuleYml` / `TemplateBuilder` family), `com.demcha.compose.v2.*` (the original engine-direct builders). Frozen — bug fixes only. | **Removed in 2.0**; no patch / minor changes other than security fixes. |
37+
38+
> The repo's [`@Internal`](../src/main/java/com/demcha/compose/document/api/Internal.java)
39+
> annotation already exists and is enforced by
40+
> [`InternalAnnotationCoverageTest`](../src/test/java/com/demcha/documentation/InternalAnnotationCoverageTest.java)
41+
> and `InternalAnnotationDocumentationTest`. The `@Beta` annotation is
42+
> still pending — until it lands, Extension SPI and Experimental tiers
43+
> are signalled in Javadoc prose only; this page describes the policy
44+
> the annotation will encode once it ships.
45+
46+
### What each tier promises
47+
48+
- **Stable** — your code that imports a Stable type compiles and runs against the next 1.x.y release without code changes; behaviour is preserved across patch releases and additive in minor releases. A removal is a major-version event called out in the CHANGELOG migration section.
49+
- **Extension SPI** — implementations you wrote against the SPI continue to load in any patch release. In a minor release the SPI **may** require small adaptations; the previous shape is `@Deprecated` for at least one minor release first, and the CHANGELOG entry calls out the migration explicitly.
50+
- **Internal** — no promises. The shape can change in any release without notice; CHANGELOG entries are optional and usually omitted to keep the user-facing changelog focused on the public surface. If you imported an `@Internal` type, you opted out of the stability contract — please open an issue so a stable wrapper can be designed.
51+
- **Experimental** — no promises within minor releases. We ship Experimental APIs to gather feedback before locking the shape. Once the contract stabilises (typically by the next minor release) the annotation is dropped and the type joins **Stable** or **Extension SPI**; the CHANGELOG transition is called out explicitly.
52+
53+
---
54+
55+
## 2. Sealed hierarchy policy
56+
57+
GraphCompose uses sealed interfaces in several places to keep visitor
58+
code exhaustive. The public ones — the ones this policy actually covers —
59+
are:
60+
61+
- [`Block`](../src/main/java/com/demcha/compose/document/templates/blocks/Block.java) (Stable)
62+
- [`CvSection`](../src/main/java/com/demcha/compose/document/templates/cv/v2/data/CvSection.java) (Stable)
63+
- [`InlineRun`](../src/main/java/com/demcha/compose/document/node/InlineRun.java) (Stable)
64+
- [`ShapeOutline`](../src/main/java/com/demcha/compose/document/style/ShapeOutline.java) (Stable)
65+
- [`TemplateModuleBlock`](../src/main/java/com/demcha/compose/document/templates/support/common/TemplateModuleBlock.java) (Extension SPI)
66+
67+
Sealed types under `@Internal` packages — `ParagraphSpan` and
68+
`PlacementContext` — are outside this policy by definition; their permit
69+
list can change in any release without notice.
70+
71+
A `sealed interface X permits A, B, C` carries a stronger contract than
72+
a regular interface: every implementation is known to the compiler, so
73+
a `switch (block)` over the permits list can be exhaustive.
74+
**Adding a new permit is therefore a breaking change** for any caller
75+
that switches on the sealed type without a `default` branch — even
76+
though it's purely additive at the source level.
77+
78+
### Policy
79+
80+
1. **Stable sealed hierarchies are additive in minor releases only when
81+
the new variant carries a sensible default rendering for callers
82+
that did not switch on it.** Concretely: if a caller pattern-matches
83+
on `Block` and hits a `NewlyAddedBlock` it didn't expect, the
84+
default rendering must visually degrade gracefully — typically by
85+
delegating to the closest stable variant (often `ParagraphBlock`)
86+
rather than throwing.
87+
2. **The CHANGELOG entry for the minor release names the new permit
88+
explicitly** under `### Public API` so callers know to audit their
89+
visitor code. Example wording, from the v1.6.4 cut:
90+
> Added two new public Block types — `WorkHistoryBlock` and
91+
> `EducationBlock` — that let template authors declare work-history
92+
> and education entries with explicit fields. The sealed `Block`
93+
> permit list grows from six to eight; existing `MultiParagraphBlock`
94+
> work-history strings continue to parse.
95+
3. **Internal sealed hierarchies have no permit-list policy.** The
96+
compiler enforces exhaustiveness for engine code; the public contract
97+
doesn't surface them at all.
98+
4. **Removing a permit is a major-version event** for any tier other
99+
than `@Internal`.
100+
101+
The same policy applies to sealed *classes* (records and class
102+
hierarchies). The mechanism is identical.
103+
104+
---
105+
106+
## 3. Deprecation window
107+
108+
A Stable API element marked `@Deprecated` is removed only in a major
109+
release, and only after the deprecation has been in effect for at least
110+
one full minor release.
111+
112+
### Rules
113+
114+
| Tier | Minimum deprecation window | Removed in |
115+
|---|---|---|
116+
| **Stable** | ≥ 1 minor release with `@Deprecated`. | Major. |
117+
| **Supported** | Already deprecated by category — entire tier is removed in the next major. | Major (entire tier). |
118+
| **Extension SPI** | ≥ 1 minor release with `@Deprecated`. | Next minor that calls out the migration in CHANGELOG `### Public API`. |
119+
| **Experimental** | None required. | Any minor. |
120+
| **Internal** | None required. | Any. |
121+
| **Legacy** | Already deprecated by category — frozen at current shape, removed in next major. | Major (entire tier). |
122+
123+
### What a deprecation must include
124+
125+
Every `@Deprecated` element ships with a Javadoc note pointing to its
126+
replacement. The format — illustrated with placeholder type names; the
127+
real shape uses the actual canonical replacement:
128+
129+
```java
130+
/**
131+
* @deprecated since 1.X.0; removed in 2.0.
132+
* Use {@link com.demcha.compose.canonical.ReplacementType#replacement(...)} instead.
133+
* The migration is one of:
134+
* - same shape, different package — swap the import;
135+
* - same name, narrower contract — adjust call sites per ADR-NNN;
136+
* - no replacement, the problem itself moved — see CHANGELOG migration note.
137+
* Pick the bullet that applies.
138+
*/
139+
@Deprecated(forRemoval = true, since = "1.X.0")
140+
public static LegacyReturn legacyMethod(LegacyArg arg) { ... }
141+
```
142+
143+
If a migration target exists, link it with `{@link ...}`. If the
144+
deprecation is *"this will simply go away in 2.0 and there is no
145+
replacement because the problem itself moved,"* say so explicitly in
146+
prose so the reader knows not to look for one.
147+
148+
### Currently slated for removal in 2.0
149+
150+
See [`docs/templates/which-template-system.md` § 4](templates/which-template-system.md#4-deprecation-inventory--1x--20)
151+
for the full deprecation inventory.
152+
153+
---
154+
155+
## 4. Tier mapping per package
156+
157+
A quick lookup so callers can classify an import without reading
158+
Javadoc per element.
159+
160+
| Package | Tier | Notes |
161+
|---|---|---|
162+
| `com.demcha.compose` (the `GraphCompose` factory class) | **Stable** | The single entry point. |
163+
| `com.demcha.compose.document.api` | **Stable** | `DocumentSession`, `DocumentBuilder`, `PageBackgroundFill`, and the `@Internal` marker itself live here. |
164+
| `com.demcha.compose.document.dsl` | **Stable** | All builder types (`RowBuilder`, `SectionBuilder`, `ParagraphBuilder`, etc.). |
165+
| `com.demcha.compose.document.node` | **Stable** | Node records (`RowNode`, `SectionNode`, `ParagraphNode`, ...). Sealed where relevant — see § 2. |
166+
| `com.demcha.compose.document.style` | **Stable** | `DocumentColor`, `DocumentInsets`, `DocumentTextStyle`, `DocumentTransform`, ... |
167+
| `com.demcha.compose.document.templates.cv.v2.*` | **Stable** | Layered CV presets, `CvDocument`, `CvTheme`. Recommended template surface. |
168+
| `com.demcha.compose.document.templates.coverletter.v2.*` | **Stable** | Layered cover-letter presets. |
169+
| `com.demcha.compose.document.templates.builtins` | **Stable** | `InvoiceTemplateV2`, `ProposalTemplateV2`, `BusinessTheme`. |
170+
| `com.demcha.compose.document.templates.cv.presets.*` | **Stable but Supported** | The "classic" v1.6 rebuild surface. See [`which-template-system.md`](templates/which-template-system.md). Supported through 1.x; removed in 2.0. |
171+
| `com.demcha.compose.document.templates.support.common` | **Extension SPI** | Helpers template authors build new presets against. `@Beta` arrives in Track H2. |
172+
| `com.demcha.compose.document.layout.*` | **Internal** | Marked `@Internal` at the package level. Engine surface. |
173+
| `com.demcha.compose.engine.*` | **Internal** | Engine surface; not part of the public contract regardless of `public` keyword. |
174+
| `com.demcha.templates.*` | **Legacy** | Pre-rebuild surface; removed in 2.0. See [`which-template-system.md`](templates/which-template-system.md). |
175+
| `com.demcha.compose.v2.*` | **Legacy** | Pre-rebuild engine-direct surface; removed in 2.0. |
176+
177+
---
178+
179+
## 5. What we don't promise (anti-policy)
180+
181+
- **Pixel-stable PDF output across patch releases.** The layout engine
182+
preserves *structural* invariants (page count, fragment ordering,
183+
cell-content order) under semver, but pixel-exact rendering can
184+
shift by a few sub-pixels when PDFBox bumps, font metrics change, or
185+
a kerning fix lands. Layout regression tests (see
186+
`LayoutSnapshotRegressionExample` in the examples README) capture
187+
structure, not pixels; visual regression tests (`*VisualRegressionTest`)
188+
ship with calibrated `mismatchedPixelBudget` values rather than zero.
189+
- **Bit-stable artefact bytes.** PDFs include creation timestamps,
190+
resource ordering hashes, and other metadata that can vary even when
191+
output is visually identical. Compare semantically, not by file hash.
192+
- **Internal package shape across releases.** See § 1, tier Internal.
193+
- **Sealed hierarchy permits' exhaustiveness across minor releases for
194+
Stable hierarchies.** See § 2. Switching on a sealed `Block` without
195+
a `default` branch *will* fail to compile cleanly on the next minor
196+
release that adds a new permit — by design.
197+
198+
---
199+
200+
## 6. References
201+
202+
- [ADR-0003 — API stability boundary and the `@Internal` marker](adr/0003-api-stability-and-internal-marker.md)
203+
— the mechanism side (how `@Internal` is wired up and the architecture
204+
guards that enforce it).
205+
- [ADR-0004 — PDF fragment render handler SPI is public](adr/0004-pdf-handler-spi-extension.md)
206+
— a worked example of opening an Extension SPI seam.
207+
- [ADR-0011 — Templates v2 architecture](adr/0011-templates-v2-architecture.md)
208+
and [ADR-0015 — Layered template architecture](adr/0015-layered-template-architecture.md)
209+
— the architectural justification for the `classic` / `layered`
210+
template tiers in § 4.
211+
- [`docs/templates/which-template-system.md`](templates/which-template-system.md)
212+
— the recommended-vs-legacy decision guide for template surfaces;
213+
this stability policy lives one level up and covers all packages,
214+
not just templates.
215+
- [`InternalAnnotationCoverageTest`](../src/test/java/com/demcha/documentation/InternalAnnotationCoverageTest.java)
216+
and [`InternalAnnotationDocumentationTest`](../src/test/java/com/demcha/compose/document/api/InternalAnnotationDocumentationTest.java)
217+
— the architecture guards that fail the build if the package-level
218+
`@Internal` marker disappears from `document.layout` or the
219+
annotation's contract drifts from this policy.
220+
221+
---
222+
223+
*This page is maintained in lockstep with the public surface. When a
224+
new public package lands, a sealed hierarchy gains a permit, or a
225+
deprecation crosses its window, update §1 (tier matrix), §2 (sealed
226+
policy if relevant), §3 (deprecation table), and §4 (package tier
227+
lookup) in the same commit.*

src/test/java/com/demcha/documentation/CanonicalSurfaceGuardTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ class CanonicalSurfaceGuardTest {
5555
// so callers can identify legacy imports in their own code and
5656
// see the canonical-DSL replacement. Same purpose as the
5757
// migration log above.
58-
"docs/templates/which-template-system.md");
58+
"docs/templates/which-template-system.md",
59+
// User-facing API stability policy. The package-tier lookup
60+
// table names com.demcha.templates.* and com.demcha.compose.v2.*
61+
// explicitly so callers can classify any import as Stable /
62+
// Extension SPI / Internal / Legacy. The deprecation example
63+
// also shows the legacy `pdf(Path)` factory paired with its
64+
// canonical-DSL replacement. Same audit-log rationale.
65+
"docs/api-stability.md");
5966
private static final List<String> FORBIDDEN_PUBLIC_AUTHORING_IMPORTS = List.of(
6067
"import com.demcha.compose.engine.");
6168

0 commit comments

Comments
 (0)