-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathllms-full.txt
More file actions
7277 lines (5059 loc) · 273 KB
/
Copy pathllms-full.txt
File metadata and controls
7277 lines (5059 loc) · 273 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Archgate CLI
> Archgate is a CLI tool for AI governance via Architecture Decision Records (ADRs). It combines human-readable documentation with machine-checkable TypeScript rules to enforce architectural decisions across codebases — for both humans and AI agents.
Archgate lets teams write an ADR once and enforce it everywhere. ADRs are Markdown files with YAML frontmatter that describe architectural decisions. Companion `.rules.ts` files contain automated TypeScript checks that run against the codebase and report violations with file paths and line numbers.
## Key capabilities
- **Executable rules**: Write compliance rules in TypeScript. Archgate runs them against your codebase and reports violations with file paths and line numbers.
- **CI integration**: Wire `archgate check` into any CI/CD pipeline. Exit code 1 blocks merges when rules are violated.
- **AI-aware governance**: Editor plugins give AI agents (Claude, Cursor, Copilot) live access to ADRs. Agents read decisions before writing code and validate after.
- **Editor plugins**: Claude Code, VS Code, Cursor, and Copilot CLI plugins give AI agents role-based governance skills.
- **Self-governance**: Archgate governs its own development using the same tool.
## Installation
Install standalone (no Node.js required): `curl -fsSL https://raw.githubusercontent.com/archgate/cli/main/install.sh | sh` (macOS/Linux) or `irm https://raw.githubusercontent.com/archgate/cli/main/install.ps1 | iex` (Windows PowerShell). Also available via npm (`npm install -g archgate`) or direct download from GitHub Releases.
## Documentation
- [Getting Started — Installation](https://cli.archgate.dev/getting-started/installation/): Install on macOS, Linux, or Windows via npm, Homebrew, or standalone binary.
- [Getting Started — Quick Start](https://cli.archgate.dev/getting-started/quick-start/): Set up Archgate in under 5 minutes with your first ADR and rule.
- [Core Concepts — ADRs](https://cli.archgate.dev/concepts/adrs/): How Architecture Decision Records work as both documentation and executable rules.
- [Core Concepts — Rules](https://cli.archgate.dev/concepts/rules/): The TypeScript rule system that turns ADR decisions into automated compliance checks.
- [Core Concepts — Domains](https://cli.archgate.dev/concepts/domains/): Organize ADRs by domain for targeted governance.
- [Guide — Writing ADRs](https://cli.archgate.dev/guides/writing-adrs/): Complete guide to writing effective ADRs with YAML frontmatter and markdown structure.
- [Guide — Writing Rules](https://cli.archgate.dev/guides/writing-rules/): Write TypeScript rules using the satisfies RuleSet pattern with file matching and violation reporting.
- [Guide — CI Integration](https://cli.archgate.dev/guides/ci-integration/): Add Archgate checks to GitHub Actions, GitLab CI, or any pipeline.
- [Guide — Claude Code Plugin](https://cli.archgate.dev/guides/claude-code-plugin/): Give AI agents a governance workflow that reads ADRs, validates code, and captures patterns.
- [Guide — VS Code Plugin](https://cli.archgate.dev/guides/vscode-plugin/): Real-time ADR compliance in VS Code.
- [Guide — Copilot CLI Plugin](https://cli.archgate.dev/guides/copilot-cli-plugin/): Add architecture governance to GitHub Copilot CLI.
- [Guide — Cursor Integration](https://cli.archgate.dev/guides/cursor-integration/): Configure Cursor IDE with Archgate agent rules and skills.
- [Guide — Pre-commit Hooks](https://cli.archgate.dev/guides/pre-commit-hooks/): Automatically check ADR compliance before every commit.
- [Reference — CLI Commands](https://cli.archgate.dev/reference/cli-commands/): Complete reference for init, check, adr create/list/show, login, and more.
- [Reference — Rule API](https://cli.archgate.dev/reference/rule-api/): TypeScript API reference for RuleSet with satisfies, RuleContext, and violation reporting.
- [Reference — ADR Schema](https://cli.archgate.dev/reference/adr-schema/): YAML frontmatter schema and markdown structure reference for ADRs.
- [Examples — Common Rule Patterns](https://cli.archgate.dev/examples/common-rule-patterns/): Ready-to-use rule patterns for naming conventions, import restrictions, and more.
## Full documentation
For the complete documentation in a single file, see [llms-full.txt](https://cli.archgate.dev/llms-full.txt).
## Optional
- [GitHub Repository](https://github.com/archgate/cli)
- [Editor Plugin Beta](https://plugins.archgate.dev)
- [npm Package](https://www.npmjs.com/package/archgate)
---
# Full documentation
Below is the complete English documentation for Archgate CLI.
## Archgate
Source: https://cli.archgate.dev/
## How it works
Archgate has two layers that work together:
1. **ADRs as documents** — Markdown files with YAML frontmatter that describe architectural decisions in plain language. Humans read them. AI agents read them. Everyone stays aligned.
2. **ADRs as rules** — Companion `.rules.ts` files with automated checks written in TypeScript. They run against your codebase and report violations with file paths and line numbers.
When you run `archgate check`, the CLI loads every ADR that has `rules: true` in its frontmatter, executes the companion rules file, and reports any violations. Exit code 0 means your code complies. Exit code 1 means it does not.
## Key Features
Write rules in TypeScript. Archgate runs them against your codebase and
reports violations with file paths and line numbers. Rules live next to the
decisions they enforce.
Wire `archgate check` into your pipeline. Exit code 1 blocks merges when
rules are violated. Works with GitHub Actions, GitLab CI, or any CI system
that respects exit codes.
Editor plugins give AI agents direct access to your ADRs via CLI commands.
They read decisions before writing code and validate after. No copy-pasting
rules into prompts.
Archgate governs its own development. The same tool that checks your code
checks ours. Our own ADRs enforce command structure, error handling, output
formatting, testing, and more — [see them on
GitHub](https://github.com/archgate/cli/tree/main/.archgate/adrs).
## Editor plugins
The Archgate CLI works standalone, but **editor plugins** unlock a full AI guardrails workflow. Plugins give AI agents role-based skills so they read your ADRs before coding, validate after, and capture new patterns for your team -- automatically.
The Claude Code plugin adds five skills: developer, architect,
quality-manager, adr-author, and onboard. Agents follow a structured
read-validate-capture loop on every task.
The Cursor plugin provides pre-built agent rules and skills that give
Cursor's AI agent the same guardrails workflow as Claude Code.
Editor plugins are currently in beta. Run `archgate login` to sign up and authenticate, then `archgate init --install-plugin` to set up the plugin.
## Learn more
---
## Getting Started: Installation
Source: https://cli.archgate.dev/getting-started/installation/
## Install standalone (recommended)
The fastest way to install Archgate — no Node.js or package manager required:
```bash
# macOS / Linux
curl -fsSL https://cli.archgate.dev/install-unix | sh
# Windows (PowerShell)
irm https://cli.archgate.dev/install-windows | iex
# Windows (Git Bash / MSYS2)
curl -fsSL https://cli.archgate.dev/install-unix | sh
```
This downloads a pre-built binary for your platform and installs it to `~/.archgate/bin/`. The installer detects your shell profiles and offers to add the directory to your PATH.
On Windows, the PowerShell installer also detects Git Bash shell profiles (`.bashrc`, `.bash_profile`, `.profile`) and offers to configure PATH there as well.
You can customize the install with environment variables:
| Variable | Description | Default |
| ---------------------- | ------------------------------------------- | ----------------- |
| `ARCHGATE_VERSION` | Install a specific version (e.g. `v0.11.2`) | Latest release |
| `ARCHGATE_INSTALL_DIR` | Custom install directory | `~/.archgate/bin` |
You can also download binaries directly from [GitHub Releases](https://github.com/archgate/cli/releases).
## Install via npm
Install Archgate globally using your preferred Node.js package manager:
```bash
# npm
npm install -g archgate
# Bun
bun install -g archgate
# Yarn
yarn global add archgate
# pnpm
pnpm add -g archgate
```
This installs a lightweight wrapper that delegates to a platform-specific binary. The CLI itself is a standalone binary compiled with Bun — Node.js is only needed for the npm/yarn/pnpm wrapper.
## Install as a dev dependency
You can also add Archgate as a dev dependency in your project and run it through your package manager's script runner. This is useful for pinning a specific version per project or running checks in CI without a global install.
```bash
# npm
npm install -D archgate
# Bun
bun add -d archgate
# Yarn
yarn add -D archgate
# pnpm
pnpm add -D archgate
```
Then run Archgate via your package manager:
```bash
# npm / Yarn / pnpm
npx archgate check
# Bun
bun run archgate check
```
Or add a script to your `package.json`:
```json
{ "scripts": { "check:adrs": "archgate check" } }
```
```bash
# Works with any package manager
npm run check:adrs
bun run check:adrs
yarn check:adrs
pnpm check:adrs
```
## Install via pip (Python)
Install Archgate globally using pip or pipx:
```bash
# pip
pip install archgate
# pipx (recommended for CLI tools)
pipx install archgate
```
This installs a lightweight Python wrapper that delegates to a platform-specific binary. Python 3.8+ is required.
## Install via dotnet
Install Archgate as a .NET global tool:
```bash
dotnet tool install -g archgate
```
Requires .NET 8.0+ SDK. The tool downloads the platform binary on first run.
## Install via Go
Install Archgate using `go install`:
```bash
go install github.com/archgate/cli/shims/go/cmd/archgate@latest
```
Requires Go 1.21+. The compiled Go wrapper downloads the platform binary on first run.
## Install via RubyGems
Install Archgate as a Ruby gem:
```bash
gem install archgate
```
Requires Ruby 2.7+. The gem downloads the platform binary on first run.
## Install via Maven / jbang (Java)
Install Archgate using jbang:
```bash
jbang app install archgate@dev.archgate
```
Or download the executable JAR from Maven Central (`dev.archgate:archgate-cli`) and run directly:
```bash
java -jar archgate-cli-0.39.0.jar check
```
Requires Java 11+. The shim downloads the platform binary on first run.
## Platform support
Archgate ships pre-built binaries for the following platforms:
| Platform | Architecture | Artifact |
| -------- | ------------ | ----------------------- |
| macOS | arm64 | `archgate-darwin-arm64` |
| Linux | x86_64 | `archgate-linux-x64` |
| Windows | x86_64 | `archgate-win32-x64` |
The correct binary is downloaded automatically from GitHub Releases on first run and cached to `~/.archgate/bin/`.
## Verify installation
```bash
archgate --version
```
You should see the installed version printed to stdout.
## Install via proto
If you use [proto](https://moonrepo.dev/proto) (moonrepo's toolchain manager), you can install Archgate directly as a proto plugin — no Node.js or npm required.
Add the plugin to your `.prototools`:
```toml
[plugins.tools]
archgate = "github://archgate/proto-plugin"
```
Then install and use it like any other proto tool:
```bash
proto install archgate
archgate check
```
Proto manages the binary for you, including version pinning and auto-installation. To pin a specific version, add it at the root of `.prototools`:
```toml
archgate = "0.15.0"
[plugins.tools]
archgate = "github://archgate/proto-plugin"
```
You can also list available versions and manage installations with proto commands:
```bash
proto list-remote archgate # list available versions
proto install archgate 0.15.0 # install a specific version
proto pin archgate 0.15.0 # pin version in .prototools
```
If you prefer `npm install -g archgate` instead of the proto plugin, you need to configure proto to expose global npm binaries. Add `shared-globals-dir = true` under `[tools.npm]` in `~/.proto/config.toml`, then add `$HOME/.proto/tools/node/globals/bin` to your shell PATH.
## Next steps
Once installed, run `archgate init` in your project to set up linting and guardrails. See the [Quick Start](/getting-started/quick-start/) guide for a walkthrough.
Want your AI agent to read ADRs before coding and validate after? The editor plugins for [Claude Code](/guides/claude-code-plugin/) and [Cursor](/guides/cursor-integration/) add a full guardrails workflow on top of the CLI. Run `archgate login` to sign up and get started.
---
## Getting Started: Quick Start
Source: https://cli.archgate.dev/getting-started/quick-start/
## 1. Install Archgate
If you have not installed the CLI yet:
```bash
# Standalone (no Node.js required)
curl -fsSL https://cli.archgate.dev/install-unix | sh
# Or via npm
npm install -g archgate
```
See the [Installation](/getting-started/installation/) page for all options, including Windows and custom install directories.
## 2. Initialize your project
Navigate to your project root and run the `init` command:
```bash
cd my-project
archgate init
```
This creates the `.archgate/` directory with the following structure:
```
.archgate/
adrs/
ARCH-001-example.md # Example ADR
ARCH-001-example.rules.ts # Example rules file
lint/
archgate.config.ts # Archgate configuration
```
The generated files give you a working example to build on.
## 3. Edit the example ADR
Open `.archgate/adrs/ARCH-001-example.md`. Every ADR starts with YAML frontmatter that defines its identity:
```yaml
---
id: ARCH-001
title: Example Decision
domain: architecture
rules: true
files: ["src/**/*.ts"]
---
```
- **id** — Unique identifier. Convention is `ARCH-NNN` but any string works.
- **title** — Human-readable name for the decision.
- **domain** — Groups related ADRs together (`architecture`, `backend`, `frontend`, `data`, or `general`).
- **rules** — Set to `true` if this ADR has a companion `.rules.ts` file with automated checks.
- **files** — Optional glob patterns that scope which files the rules apply to.
Below the frontmatter, write the decision in markdown. Archgate does not enforce a specific section structure, but the recommended sections are: Context, Decision, Do's and Don'ts, Consequences, Compliance, and References.
## 4. Add a companion rules file
Create a `.rules.ts` file next to your ADR with the same name prefix. Rules are written in TypeScript using the `RuleSet` type:
```typescript
/// <reference path="../rules.d.ts" />
export default {
rules: {
"no-console-error": {
description: "Use logError() instead of console.error()",
async check(ctx) {
for (const file of ctx.scopedFiles) {
const matches = await ctx.grep(file, /console\.error\(/);
for (const match of matches) {
ctx.report.violation({
message: "Use logError() instead of console.error()",
file: match.file,
line: match.line,
fix: "Import logError from your helpers and use it instead",
});
}
}
},
},
},
} satisfies RuleSet;
```
Each rule has a unique key, a description, and an async `check` function. Inside `check`, you have access to:
- **`ctx.scopedFiles`** — Files matching the ADR's `files` glob patterns.
- **`ctx.grep(file, pattern)`** — Search a file for regex matches, returning file paths and line numbers.
- **`ctx.report.violation()`** — Report a violation with a message, file path, line number, and optional fix suggestion.
## 5. Run checks
Run the compliance checker against your codebase:
```bash
archgate check
```
Archgate loads every ADR with `rules: true`, executes its companion rules file, and prints results. The exit code tells you the outcome:
| Exit code | Meaning |
| --------- | --------------------------------------------- |
| 0 | All rules pass. No violations found. |
| 1 | One or more violations detected. |
| 2 | Internal error (e.g., malformed ADR or rule). |
To check only staged files (useful in pre-commit hooks or CI):
```bash
archgate check --staged
```
## What's next?
Now that you have a working setup, dive deeper:
**Understand the concepts:**
- [ADRs](/concepts/adrs/) — What Architecture Decision Records are and how Archgate uses them.
- [Rules](/concepts/rules/) — How companion `.rules.ts` files turn decisions into automated checks.
- [Domains](/concepts/domains/) — How domains group related ADRs and scope file matching.
**Write your own:**
- [Writing ADRs](/guides/writing-adrs/) — Learn the full ADR format and best practices for writing effective decisions.
- [Writing Rules](/guides/writing-rules/) — Explore the rule API, advanced patterns, and how to test your rules.
- [Common Rule Patterns](/examples/common-rule-patterns/) — Copy-pasteable patterns for dependency checks, naming conventions, and more.
**Integrate into your workflow:**
- [CI Integration](/guides/ci-integration/) — Wire `archgate check` into GitHub Actions, GitLab CI, or any pipeline.
- [Pre-commit Hooks](/guides/pre-commit-hooks/) — Run checks locally before every commit.
- [Claude Code Plugin](/guides/claude-code-plugin/) — Give AI agents architecture-aware guardrails with role-based skills.
- [Cursor Integration](/guides/cursor-integration/) — Use Archgate with Cursor IDE for AI-assisted development.
Want AI agents that automatically read your ADRs before coding? Run `archgate login` to sign up and authenticate, then run `archgate init --install-plugin` to set up the plugin.
---
## Core Concepts: Architecture Decision Records
Source: https://cli.archgate.dev/concepts/adrs/
An Architecture Decision Record (ADR) is a short document that captures a single architectural decision along with its context and consequences. ADRs answer the question: _why_ was this decision made, and _what_ are its trade-offs?
Archgate builds on the ADR concept by giving each decision two expressions: a **document** that humans and AI agents read, and an optional **rules file** that machines execute.
## Two Expressions of an ADR
### ADR as Document
The document is a Markdown file with YAML frontmatter stored in `.archgate/adrs/`. It describes the decision in plain language: what problem it solves, what alternatives were considered, what the team decided, and what consequences follow.
Both humans and AI agents consume this document. When an AI coding agent is about to write code, it reads the relevant ADRs to understand the constraints before generating anything.
With the [Claude Code](/guides/claude-code-plugin/) or [Cursor](/guides/cursor-integration/) plugin, your AI agent reads the applicable ADRs automatically before every coding task -- no manual copy-pasting into prompts. [Sign up for beta access](https://plugins.archgate.dev).
### ADR as Rules
The rules file is a companion `.rules.ts` file that exports a plain object typed with `satisfies RuleSet`. When you run `archgate check`, the CLI loads every ADR that has `rules: true` in its frontmatter, executes the companion rules file against your codebase, and reports any violations with file paths and line numbers.
Not every ADR needs rules. Some decisions are best enforced through code review alone. Set `rules: false` when no automated check is practical.
## File Naming Convention
ADR files follow a strict naming convention that encodes the domain prefix, sequence number, and a human-readable slug:
```
{PREFIX}-{NNN}-{slug}.md # The document
{PREFIX}-{NNN}-{slug}.rules.ts # The companion rules file (optional)
```
For example, an architecture-domain ADR about command structure would produce:
```
ARCH-001-command-structure.md
ARCH-001-command-structure.rules.ts
```
The prefix comes from the ADR's domain (see [Domains](/concepts/domains/)). The sequence number is zero-padded to three digits and auto-incremented by `archgate adr create`.
## YAML Frontmatter
Every ADR document starts with a YAML frontmatter block between `---` delimiters. The frontmatter is the machine-readable metadata that Archgate uses to load, filter, and scope rules.
| Field | Type | Required | Description |
| ------------------ | ------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id` | string | Yes | Unique identifier like `ARCH-001` or `BE-003` |
| `title` | string | Yes | Human-readable title of the decision |
| `domain` | string | Yes | Registered domain name. Built-ins: `backend`, `frontend`, `data`, `architecture`, `general`. [Custom domains](/concepts/domains/#custom-domains) can be added via `archgate adr domain add`. |
| `rules` | boolean | Yes | Whether this ADR has a companion `.rules.ts` file |
| `files` | string array | No | Glob patterns that scope which files the rules check |
| `respectGitignore` | boolean | No | Whether to filter out `.gitignore`d files. Defaults to `true`. |
The `files` field is optional. When present, it restricts rule execution to only the files matching the given globs. When absent, rules run against all project files. For example, `files: ["src/commands/**/*.ts"]` limits checks to command files only.
The `respectGitignore` field is also optional. By default, files listed in `.gitignore` are excluded from all file-scanning operations (`ctx.scopedFiles`, `ctx.glob()`, `ctx.grepFiles()`). Set `respectGitignore: false` to include gitignored files -- useful for rules that need to inspect build output or generated files.
## ADR Body Sections
After the frontmatter, the ADR body follows a standard section structure:
### Context
Describes the problem or situation that prompted the decision. Include alternatives that were considered and why they were rejected.
### Decision
States the decision itself and its key constraints. This is the section AI agents pay the most attention to when deciding how to write code.
### Do's and Don'ts
Concrete, actionable guidance split into two sub-sections. These act as a quick-reference checklist for developers and AI agents.
### Consequences
Split into three sub-sections:
- **Positive** -- benefits the decision provides
- **Negative** -- trade-offs accepted
- **Risks** -- things that could go wrong and how to mitigate them
### Compliance and Enforcement
Describes how the decision is enforced, both through automated rules (with rule IDs and severities) and manual review checklists.
### References
Links to related ADRs, external documentation, or design documents.
## Complete Example
Below is a full ADR with frontmatter and all sections filled in.
```markdown
---
id: BE-001
title: API Response Envelope
domain: backend
rules: true
files: ["src/api/**/*.ts"]
---
## Context
The API returns data in inconsistent shapes across endpoints. Some endpoints
wrap responses in `{ data, error }`, others return raw arrays, and error
responses vary between plain strings and structured objects.
**Alternatives considered:**
- **No envelope** -- Return raw data and rely on HTTP status codes alone.
Simple, but clients cannot distinguish between "the endpoint returned an
empty array" and "the endpoint errored."
- **GraphQL-style errors array** -- Use `{ data, errors: [] }`. Flexible
but adds complexity for simple REST endpoints.
The chosen envelope balances consistency with simplicity.
## Decision
All API endpoints MUST return responses in a standard envelope:
- Success: `{ data: T }`
- Error: `{ error: { code: string, message: string } }`
HTTP status codes remain the primary success/failure signal. The envelope
provides a predictable structure for clients to parse.
## Do's and Don'ts
### Do
- Wrap all API responses in the `{ data }` or `{ error }` envelope
- Use specific error codes (e.g., `VALIDATION_FAILED`, `NOT_FOUND`)
- Include the HTTP status code that matches the error semantics
### Don't
- Don't return raw arrays or primitives from API endpoints
- Don't nest envelopes (no `{ data: { data: ... } }`)
- Don't put stack traces in the error message field
## Consequences
### Positive
- Clients can parse every response with the same logic
- Error responses always have a machine-readable code for programmatic handling
### Negative
- Adds a small amount of boilerplate to every endpoint handler
- Slightly larger payloads due to the wrapper object
### Risks
- Developers may forget the envelope on new endpoints. Mitigated by
the automated rule that scans for non-conforming return statements.
## Compliance and Enforcement
### Automated Enforcement
- **Archgate rule** BE-001/response-envelope: Scans API handler files for
return statements and verifies they use the envelope helper. Severity: error.
### Manual Enforcement
Code reviewers MUST verify:
1. New API endpoints use the response envelope
2. Error responses include a specific error code, not a generic message
## References
- [Microsoft REST API Guidelines](https://github.com/microsoft/api-guidelines)
- [ARCH-002 -- Error Handling](./ARCH-002-error-handling.md)
```
---
## Core Concepts: Domains
Source: https://cli.archgate.dev/concepts/domains/
Domains are categories that group related ADRs together. Every ADR belongs to exactly one domain, and the domain determines the prefix used in the ADR's identifier.
## Built-in Domains
Archgate ships with five built-in domains. Each has a short prefix that appears at the start of every ADR ID in that domain.
| Domain | Prefix | Use for |
| -------------- | ------ | --------------------------------------------------- |
| `backend` | `BE` | Server-side logic, APIs, databases, services |
| `frontend` | `FE` | UI components, client-side logic, styling patterns |
| `data` | `DATA` | Data models, schemas, pipelines, storage strategies |
| `architecture` | `ARCH` | Cross-cutting architectural decisions |
| `general` | `GEN` | General project conventions and workflows |
For example, the third backend ADR would have the ID `BE-003`, and a first frontend ADR would be `FE-001`.
## How Domains Are Used
### ADR Identification
The domain prefix is baked into every ADR's `id` field. When you run `archgate adr create` and select a domain, the CLI automatically determines the next available sequence number for that domain's prefix. An architecture domain with two existing ADRs (`ARCH-001`, `ARCH-002`) would assign `ARCH-003` to the next one.
The file name mirrors the ID:
```
ARCH-003-dependency-policy.md
ARCH-003-dependency-policy.rules.ts
```
### Filtering
The `archgate adr list` command supports a `--domain` flag to show only ADRs from a specific domain:
```bash
archgate adr list --domain backend
archgate adr list --domain architecture
```
This is useful in large projects where dozens of ADRs span multiple concerns. Filtering by domain lets you focus on the decisions relevant to your current work.
### AI Agent Context
The `archgate review-context` command groups changed files by domain when providing context to AI agents. When an agent is about to write code, it receives only the ADR briefings relevant to the domains its changes touch, rather than the full set of all ADRs. This scoping reduces noise and helps agents focus on the constraints that actually apply.
### Scoped Validation
While domains themselves do not restrict which files a rule can check (that is the job of the `files` glob in the ADR frontmatter), domains provide a logical grouping that helps teams organize their governance. A backend team can review all `BE-*` ADRs to understand their constraints, while the frontend team focuses on `FE-*`.
## When to Use Which Domain
### backend
Use for decisions about server-side code: API design patterns, database access conventions, authentication flows, service-to-service communication, queue handling, and background job patterns.
**Example ADRs:** API response envelope format, database migration strategy, error code taxonomy.
### frontend
Use for decisions about client-side code: component structure, state management patterns, styling approaches, accessibility requirements, and build tooling choices.
**Example ADRs:** Component file structure, CSS methodology, form validation pattern.
### data
Use for decisions about data: schema design, data pipeline conventions, storage engine choices, serialization formats, and data validation strategies.
**Example ADRs:** Event schema versioning, database naming conventions, data retention policy.
### architecture
Use for cross-cutting decisions that span multiple domains or affect the project's overall structure. These are decisions that backend, frontend, and data teams all need to follow.
**Example ADRs:** Command structure, error handling conventions, dependency management policy, testing standards.
### general
Use for project-wide conventions that do not fit neatly into a technical domain: code review processes, commit message formats, documentation standards, and onboarding practices.
**Example ADRs:** Commit message format, PR description template, documentation requirements.
## Choosing the Right Domain
When deciding which domain an ADR belongs to, consider who needs to follow it:
- If only backend developers need to follow it, use `backend`.
- If only frontend developers need to follow it, use `frontend`.
- If it concerns data modeling or pipelines specifically, use `data`.
- If it applies across multiple technical domains, use `architecture`.
- If it is a process or convention rather than a technical decision, use `general`.
When in doubt between `architecture` and a specific domain, prefer the more specific domain. Reserve `architecture` for decisions that genuinely cut across boundaries.
## Custom Domains
When the built-in five are a genuine mismatch for a category of decisions — for example, `security`, `ml-ops`, or `compliance` — you can register a custom domain via the CLI:
```bash
# See what's currently recognised in this project
archgate adr domain list
# Register a new domain with its ID prefix
archgate adr domain add security SEC
# Remove a custom domain (built-ins cannot be removed)
archgate adr domain remove security
```
Custom domain-to-prefix mappings persist in [`.archgate/config.json`](/reference/configuration/) and are merged with the built-ins at read time. A registered custom domain behaves exactly like a built-in: `archgate adr create --domain security` auto-generates IDs like `SEC-001`, and `archgate adr list --domain security` filters to those ADRs.
### Naming rules
- **Name** — lowercase kebab-case, 2–32 characters (e.g., `security`, `ml-ops`, `compliance`).
- **Prefix** — uppercase letters, digits, or underscores, 2–10 characters (e.g., `SEC`, `MLOPS`, `COMP`).
- Custom names and prefixes cannot collide with built-ins or any other custom entry.
### When to prefer a built-in
The built-in five are deliberately opinionated. Before registering a custom domain, check whether the decision can be folded under an existing one:
- A decision about auth middleware usually fits under `backend`, even if the motivation is security.
- A decision about schema versioning usually fits under `data`, even if the motivation is compliance.
- A decision that spans multiple technical areas usually fits under `architecture`.
Reach for a custom domain only when none of the built-ins is a genuine fit — for example, when you have a dedicated team or compliance regime that needs its own governance surface.
### AI agent guidance
When using the Archgate editor plugin to author ADRs, agents are instructed to default to the built-in domains and to ask before introducing a custom one. They'll surface the merged list via `archgate adr domain list` and only register a new domain after confirming with you that no built-in fits.
---
## Core Concepts: Rules
Source: https://cli.archgate.dev/concepts/rules/
Rules are the executable side of an ADR. They live in companion `.rules.ts` files alongside the ADR document and export a plain object typed with `satisfies RuleSet`. When you run `archgate check`, the CLI loads each ADR that has `rules: true`, imports its companion rules file, and executes every check against your codebase.
## Defining Rules
A rules file is a TypeScript module that default-exports a plain object conforming to the `RuleSet` type. The type is provided by the local shim auto-generated by `archgate init` (no npm install needed):
```typescript
/// <reference path="../rules.d.ts" />
export default {
rules: {
"rule-key": {
description: "What this rule checks",
severity: "error",
async check(ctx) {
// Inspect files and report violations
},
},
},
} satisfies RuleSet;
```
Each key in the `rules` object becomes the rule ID. The full rule identifier shown in check output combines the ADR ID and the rule key, for example `ARCH-004/no-barrel-files`.
## Rule Structure
Every rule has three parts:
| Property | Type | Required | Description |
| ------------- | -------- | -------- | --------------------------------------------- |
| `description` | string | Yes | A short summary of what the rule checks |
| `severity` | string | No | `"error"` (default), `"warning"`, or `"info"` |
| `check` | function | Yes | Async function receiving a `RuleContext` |
### Severity Levels
Severity determines what happens when a rule finds a problem:
| Severity | Exit Code | Effect |
| --------- | --------- | ----------------------------------------- |
| `error` | 1 | Violation is reported and the check fails |
| `warning` | 0 | Warning is logged but the check passes |
| `info` | 0 | Informational message, check passes |
When `archgate check` runs, exit code 1 means at least one `error`-severity violation was found. Exit code 0 means no errors (warnings and info messages are logged but do not block).
## The RuleContext
The `check` function receives a `RuleContext` object that provides everything a rule needs to inspect the codebase and report findings.
### Project Information
| Property | Type | Description |
| ------------------ | ---------- | ----------------------------------------------------------------------------------- |
| `ctx.projectRoot` | `string` | Absolute path to the project root directory |
| `ctx.scopedFiles` | `string[]` | Files matching the ADR's `files` globs, or all project files if no globs are set |
| `ctx.changedFiles` | `string[]` | Files changed in git (branch diff plus uncommitted changes, or `--staged`/`--base`) |
### File Operations
| Method | Returns | Description |
| -------------------- | ------------------- | ---------------------------------- |
| `ctx.glob(pattern)` | `Promise<string[]>` | Find files matching a glob pattern |
| `ctx.readFile(path)` | `Promise<string>` | Read a file's content as a string |
| `ctx.readJSON(path)` | `Promise<unknown>` | Read and parse a JSON file |
### Search Operations
| Method | Returns | Description |
| ---------------------------------- | ---------------------- | -------------------------------------------- |
| `ctx.grep(file, pattern)` | `Promise` | Search a single file with a regex pattern |
| `ctx.grepFiles(pattern, fileGlob)` | `Promise` | Search across multiple files matching a glob |
Both `grep` and `grepFiles` return an array of `GrepMatch` objects:
```typescript
interface GrepMatch {
file: string; // Relative path from project root
line: number; // 1-based line number
column: number; // 1-based column number
content: string; // The full line content
}
```
### Reporting
The `ctx.report` object provides three methods for reporting findings:
```typescript
ctx.report.violation({ message, file?, line?, fix? });
ctx.report.warning({ message, file?, line?, fix? });
ctx.report.info({ message, file?, line?, fix? });
```
Each method accepts an object with:
| Property | Type | Required | Description |
| --------- | ------ | -------- | ------------------------------------ |
| `message` | string | Yes | What the problem is |
| `file` | string | No | Relative path to the offending file |
| `line` | number | No | Line number where the problem occurs |
| `fix` | string | No | Suggested fix for the violation |
Use `ctx.report.violation()` for problems that must block merges. Use `ctx.report.warning()` for issues worth flagging but not blocking. Use `ctx.report.info()` for purely informational output.
## Rule Timeout
Each rule has a 30-second execution timeout. If a rule's `check` function does not complete within 30 seconds, it is terminated and reported as an error. This prevents runaway rules from blocking the pipeline indefinitely.
## Complete Example
Here is a complete rules file that checks for a banned import pattern. It enforces that no source file imports directly from `node:fs` (the project requires using a wrapper instead).
```typescript
/// <reference path="../rules.d.ts" />
export default {
rules: {
"no-direct-fs-import": {
description:
"Source files must not import directly from node:fs; use the fs wrapper",
severity: "error",
async check(ctx) {
const sourceFiles = ctx.scopedFiles.filter(
(f) => f.endsWith(".ts") && !f.endsWith(".test.ts")
);
for (const file of sourceFiles) {
const matches = await ctx.grep(file, /from ["']node:fs["']/);
for (const match of matches) {
ctx.report.violation({
message: `Direct import from "node:fs" is not allowed. Use the fs wrapper from "src/helpers/fs" instead.`,
file: match.file,
line: match.line,
fix: 'Replace the import with: import { readFile, writeFile } from "../helpers/fs"',
});
}
}
},
},
},
} satisfies RuleSet;
```
When this rule runs against a file containing `import { readFileSync } from "node:fs"`, the output looks like:
```
ARCH-007/no-direct-fs-import ERROR
src/services/config.ts:3 — Direct import from "node:fs" is not allowed. Use the fs wrapper from "src/helpers/fs" instead.
Fix: Replace the import with: import { readFile, writeFile } from "../helpers/fs"
```
## Execution Model
Rules execute with the following guarantees:
- **Parallel across ADRs** -- Rules from different ADRs run concurrently for faster execution.
- **Sequential within an ADR** -- Rules belonging to the same ADR run one after another, so earlier rules can establish context for later ones.
- **Scoped files are pre-resolved** -- The `ctx.scopedFiles` array is populated before your `check` function is called, based on the ADR's `files` globs.
- **Changed files auto-detected** -- `ctx.changedFiles` is automatically populated with the branch diff against the base branch (e.g., `main`) plus uncommitted working-tree changes (staged, unstaged, and untracked non-ignored files). Use `--staged` for pre-commit hooks (staged files only) or `--base <ref>` for an explicit base. This enables cross-file dependency rules to work locally, not just in CI.
The editor plugins for [Claude Code](/guides/claude-code-plugin/) and [Cursor](/guides/cursor-integration/) run `archgate check` automatically after every code change. The agent reads the applicable ADRs, writes compliant code, and validates -- no manual check commands needed. [Sign up for beta access](https://plugins.archgate.dev).
---
## Guides: CI Integration
Source: https://cli.archgate.dev/guides/ci-integration/
Archgate checks fit into any CI system that respects exit codes. Add a single step to your pipeline and violations will block merges automatically.
## GitHub Actions
The fastest way to add Archgate to GitHub Actions is with the official [`archgate/check-action`](https://github.com/archgate/check-action). It installs the CLI, runs `archgate check --ci`, and outputs violations as inline annotations on the pull request's "Files changed" tab:
```yaml
name: Archgate
on:
pull_request:
push:
branches: [main]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: archgate/check-action@v1
```
That's it — no Node.js setup, no install step. If any rule reports a violation with `error` severity, the job fails with exit code 1.
### Pin a version
```yaml
- uses: archgate/check-action@v1
with:
version: v0.15.0
```