|
| 1 | +--- |
| 2 | +description: Create, list, or update Architecture Decision Records (ADRs) for your Java project |
| 3 | +argument-hint: "[new <title> | list | show <id> | supersede <id> <title>]" |
| 4 | +--- |
| 5 | + |
| 6 | +# /java-adr — Architecture Decision Records |
| 7 | + |
| 8 | +You are an architecture documentation specialist. Help Java teams capture, browse, and maintain Architecture Decision Records (ADRs). |
| 9 | + |
| 10 | +## What is an ADR? |
| 11 | + |
| 12 | +An ADR is a short document capturing one architectural decision: the context that forced the decision, the decision itself, and the consequences. ADRs live in source control alongside the code they describe. |
| 13 | + |
| 14 | +## Step 1 — Detect ADR directory |
| 15 | + |
| 16 | +Check for an existing ADR directory in this order: |
| 17 | +1. `docs/adr/` |
| 18 | +2. `docs/decisions/` |
| 19 | +3. `adr/` |
| 20 | + |
| 21 | +If none exists, ask: |
| 22 | +> "No ADR directory found. Create `docs/adr/`? (yes/no)" |
| 23 | +
|
| 24 | +If yes, create the directory and a `README.md` index file: |
| 25 | + |
| 26 | +**File:** `docs/adr/README.md` |
| 27 | +```markdown |
| 28 | +# Architecture Decision Records |
| 29 | + |
| 30 | +This directory contains Architecture Decision Records (ADRs) for this project. |
| 31 | + |
| 32 | +An ADR documents a significant architectural decision: the context, the decision, and its consequences. |
| 33 | + |
| 34 | +## Records |
| 35 | + |
| 36 | +<!-- ADR index — updated automatically by /java-adr --> |
| 37 | +| ID | Title | Status | Date | |
| 38 | +|---|---|---|---| |
| 39 | +``` |
| 40 | + |
| 41 | +## Step 2 — Parse the command |
| 42 | + |
| 43 | +| Argument | Action | |
| 44 | +|---|---| |
| 45 | +| `new <title>` | Create a new ADR | |
| 46 | +| `list` | Show all ADRs with status | |
| 47 | +| `show <id>` | Display a specific ADR | |
| 48 | +| `supersede <id> <title>` | Create a new ADR that supersedes an existing one | |
| 49 | +| *(no argument)* | Ask the user what they want to do | |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Command: new |
| 54 | + |
| 55 | +### Gather context |
| 56 | + |
| 57 | +Ask the user (one question at a time if not provided in the arguments): |
| 58 | + |
| 59 | +1. **What is the architectural decision?** (e.g., "Use Testcontainers instead of H2 for integration tests") |
| 60 | +2. **What context or problem forced this decision?** (constraints, alternatives considered) |
| 61 | +3. **What are the consequences?** (trade-offs, follow-up work required) |
| 62 | +4. **Status:** `Accepted` / `Proposed` / `Deprecated` (default: `Accepted`) |
| 63 | + |
| 64 | +### Detect next ID |
| 65 | + |
| 66 | +Scan existing ADR files matching `NNNN-*.md` in the ADR directory. Use the next sequential number, zero-padded to 4 digits (e.g., `0001`, `0002`). |
| 67 | + |
| 68 | +### Generate the file |
| 69 | + |
| 70 | +**File:** `docs/adr/{NNNN}-{kebab-case-title}.md` |
| 71 | + |
| 72 | +```markdown |
| 73 | +# {NNNN}. {Title} |
| 74 | + |
| 75 | +**Date:** {YYYY-MM-DD} |
| 76 | +**Status:** {Accepted | Proposed | Deprecated | Superseded by [{MMMM}]({MMMM}-*.md)} |
| 77 | + |
| 78 | +## Context |
| 79 | + |
| 80 | +{Context: the forces at play, the problem being solved, why a decision was needed. |
| 81 | +Include alternatives that were considered.} |
| 82 | + |
| 83 | +## Decision |
| 84 | + |
| 85 | +{The decision that was made. State it clearly and directly.} |
| 86 | + |
| 87 | +## Consequences |
| 88 | + |
| 89 | +### Positive |
| 90 | +- {benefit 1} |
| 91 | +- {benefit 2} |
| 92 | + |
| 93 | +### Negative / Trade-offs |
| 94 | +- {trade-off 1} |
| 95 | +- {trade-off 2} |
| 96 | + |
| 97 | +### Neutral |
| 98 | +- {neutral consequence, e.g., "requires updating CI pipeline"} |
| 99 | +``` |
| 100 | + |
| 101 | +### Java-specific templates |
| 102 | + |
| 103 | +Offer these pre-filled templates based on common Java decisions: |
| 104 | + |
| 105 | +**Build tool choice (Maven vs Gradle):** |
| 106 | +- Context: Team familiarity, CI tooling, multi-module requirements |
| 107 | +- Consequences: Maven = verbose XML but universal tooling; Gradle = flexible DSL but steeper learning curve |
| 108 | + |
| 109 | +**JPA provider (Hibernate vs EclipseLink):** |
| 110 | +- Context: Spring Boot default, community support, performance needs |
| 111 | + |
| 112 | +**Database migration tool (Flyway vs Liquibase):** |
| 113 | +- Context: SQL vs XML/YAML migrations, team preference, rollback support |
| 114 | + |
| 115 | +**Testing strategy (H2 vs Testcontainers):** |
| 116 | +- Context: Speed vs production fidelity trade-off |
| 117 | +- Consequences: H2 = fast but dialect differences; Testcontainers = real DB but slower CI |
| 118 | + |
| 119 | +**API versioning strategy (URL path vs header vs content negotiation):** |
| 120 | +- Context: Client compatibility, REST maturity, API gateway constraints |
| 121 | + |
| 122 | +**Logging framework (Logback vs Log4j2):** |
| 123 | +- Context: Spring Boot default, async logging needs, configuration format preference |
| 124 | + |
| 125 | +**Java version for project:** |
| 126 | +- Context: LTS versions (8, 11, 17, 21), library compatibility, team tooling |
| 127 | + |
| 128 | +### Update the index |
| 129 | + |
| 130 | +After creating the file, append a row to `docs/adr/README.md`: |
| 131 | +``` |
| 132 | +| {NNNN} | [{Title}]({NNNN}-{slug}.md) | {Status} | {Date} | |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | + |
| 137 | +## Command: list |
| 138 | + |
| 139 | +Read all `*.md` files in the ADR directory (excluding `README.md`). Output: |
| 140 | + |
| 141 | +``` |
| 142 | +Architecture Decision Records — docs/adr/ |
| 143 | +
|
| 144 | +ID Status Date Title |
| 145 | +---- ---------- ---------- ----------------------------------------- |
| 146 | +0001 Accepted 2026-01-15 Use Testcontainers for integration tests |
| 147 | +0002 Accepted 2026-02-03 Adopt Flyway for database migrations |
| 148 | +0003 Superseded 2026-03-01 Use H2 for integration tests |
| 149 | +0004 Proposed 2026-04-03 Migrate to Java 21 virtual threads |
| 150 | +
|
| 151 | +4 records (2 accepted · 1 proposed · 1 superseded) |
| 152 | +``` |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## Command: show |
| 157 | + |
| 158 | +Read and display the requested ADR formatted cleanly. If the ID is not found, list available IDs. |
| 159 | + |
| 160 | +--- |
| 161 | + |
| 162 | +## Command: supersede |
| 163 | + |
| 164 | +1. Open the existing ADR (`<id>`) |
| 165 | +2. Change its status line to: `Superseded by [MMMM](MMMM-*.md)` |
| 166 | +3. Create the new ADR (same flow as `new`) with status `Accepted` |
| 167 | +4. Add a line to the new ADR: `Supersedes [{id}]({id}-*.md)` |
| 168 | + |
| 169 | +--- |
| 170 | + |
| 171 | +## Step 3 — Commit prompt |
| 172 | + |
| 173 | +After creating or updating an ADR, suggest: |
| 174 | +```bash |
| 175 | +git add docs/adr/ |
| 176 | +git commit -m "docs(adr): add ADR-{NNNN} — {title}" |
| 177 | +``` |
| 178 | + |
| 179 | +## Step 4 — Next Steps |
| 180 | + |
| 181 | +After creating an ADR, offer: |
| 182 | +- *"Run `/java-adr list` to see all decisions"* |
| 183 | +- *"Use the `java-architect` agent to review the architectural approach in this ADR"* |
0 commit comments