arch-drift 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +186 -0
- package/dist/index.js +14630 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Omar Mendivil
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# arch-drift
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
Prevent architecture drift in your codebase. Define layer boundaries, detect violations, enforce on every commit.
|
|
7
|
+
|
|
8
|
+
## What it does
|
|
9
|
+
|
|
10
|
+
arch-drift reads an `architecture.yml` config that describes your project's layer boundaries (which modules can import from which), then checks your codebase for violations. It auto-detects your current architecture via `init`, then enforces it via `check` on every commit or PR.
|
|
11
|
+
|
|
12
|
+
### Design principles
|
|
13
|
+
|
|
14
|
+
- **Describes reality, doesn't prescribe ideals.** `init` captures what the codebase IS, not what you wish it was.
|
|
15
|
+
- **Advisor, not cop.** Violations explain the current pattern, what changed, and implications.
|
|
16
|
+
- **Everything starts as warnings.** Promote to errors deliberately when you're ready.
|
|
17
|
+
- **Self-validating.** Checks its own config for dead paths and missing coverage.
|
|
18
|
+
- **Zero token cost.** Runs as a CLI outside your AI context window.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
# With bun (recommended)
|
|
24
|
+
bun add -d arch-drift
|
|
25
|
+
|
|
26
|
+
# With npm
|
|
27
|
+
npm install --save-dev arch-drift
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 1. Auto-detect your architecture
|
|
34
|
+
arch-drift init
|
|
35
|
+
|
|
36
|
+
# 2. Review the generated config
|
|
37
|
+
cat architecture.yml
|
|
38
|
+
|
|
39
|
+
# 3. Check for violations
|
|
40
|
+
arch-drift check
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Commands
|
|
44
|
+
|
|
45
|
+
### `arch-drift init`
|
|
46
|
+
|
|
47
|
+
Scans your project, detects the tech stack, analyzes import patterns between directories, and generates `architecture.yml`. Run this once to capture your baseline.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
arch-drift init
|
|
51
|
+
arch-drift init --non-interactive # Skip prompts, use defaults
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### `arch-drift check`
|
|
55
|
+
|
|
56
|
+
Runs all architecture checks: boundary violations, banned imports, file size thresholds, and custom rules.
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
arch-drift check # Pretty output for humans
|
|
60
|
+
arch-drift check --format json # JSON output for CI
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Exit codes:
|
|
64
|
+
- `0` — No errors (warnings are OK)
|
|
65
|
+
- `1` — Errors found
|
|
66
|
+
|
|
67
|
+
### `arch-drift validate`
|
|
68
|
+
|
|
69
|
+
Validates your `architecture.yml` config without scanning the project. Finds dead paths, unclaimed directories, and config errors.
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
arch-drift validate
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `arch-drift allow`
|
|
76
|
+
|
|
77
|
+
Whitelist a specific import relationship between layers.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
arch-drift allow components:lib
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
`architecture.yml` in your project root:
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
version: 1
|
|
89
|
+
project:
|
|
90
|
+
name: my-app
|
|
91
|
+
src: src
|
|
92
|
+
|
|
93
|
+
shared_layers:
|
|
94
|
+
- types
|
|
95
|
+
- utils
|
|
96
|
+
|
|
97
|
+
layers:
|
|
98
|
+
- name: components
|
|
99
|
+
paths:
|
|
100
|
+
- 'src/components/**'
|
|
101
|
+
can_import:
|
|
102
|
+
- hooks
|
|
103
|
+
- lib
|
|
104
|
+
why: 'UI components layer'
|
|
105
|
+
|
|
106
|
+
- name: hooks
|
|
107
|
+
paths:
|
|
108
|
+
- 'src/hooks/**'
|
|
109
|
+
can_import:
|
|
110
|
+
- lib
|
|
111
|
+
why: 'React hooks and state management'
|
|
112
|
+
|
|
113
|
+
- name: lib
|
|
114
|
+
paths:
|
|
115
|
+
- 'src/lib/**'
|
|
116
|
+
can_import: []
|
|
117
|
+
why: 'Core utilities and helpers'
|
|
118
|
+
|
|
119
|
+
thresholds:
|
|
120
|
+
max_file_lines: 500
|
|
121
|
+
|
|
122
|
+
banned:
|
|
123
|
+
- pattern: 'lodash'
|
|
124
|
+
why: 'Use native JS instead'
|
|
125
|
+
|
|
126
|
+
rules:
|
|
127
|
+
no_any: 'warn'
|
|
128
|
+
max_file_lines: 'warn'
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Layers
|
|
132
|
+
|
|
133
|
+
Each layer defines:
|
|
134
|
+
- **`paths`** — Glob patterns for files in this layer
|
|
135
|
+
- **`can_import`** — Which other layers this one is allowed to import from
|
|
136
|
+
- **`why`** — Description shown in violation messages
|
|
137
|
+
|
|
138
|
+
Imports from `shared_layers` are always allowed (don't need to be listed in `can_import`).
|
|
139
|
+
|
|
140
|
+
### Violations
|
|
141
|
+
|
|
142
|
+
arch-drift reports four types of violations:
|
|
143
|
+
|
|
144
|
+
| Type | What it catches |
|
|
145
|
+
|------|----------------|
|
|
146
|
+
| **boundary** | Layer A imports from Layer B, but B isn't in A's `can_import` list |
|
|
147
|
+
| **banned** | Import matches a banned regex pattern |
|
|
148
|
+
| **threshold** | File exceeds `max_file_lines` |
|
|
149
|
+
| **self-validation** | Config errors: dead paths, unclaimed directories |
|
|
150
|
+
|
|
151
|
+
### Rules
|
|
152
|
+
|
|
153
|
+
Custom rules that can be set to `warn`, `error`, or `off`:
|
|
154
|
+
|
|
155
|
+
- **`no_any`** — Flags TypeScript `any` type usage
|
|
156
|
+
- **`max_file_lines`** — Flags files exceeding the threshold
|
|
157
|
+
|
|
158
|
+
## CI Integration
|
|
159
|
+
|
|
160
|
+
### GitHub Actions
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
- name: Architecture check
|
|
164
|
+
run: npx arch-drift check --format json
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Pre-commit hook
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
#!/bin/sh
|
|
171
|
+
npx arch-drift check
|
|
172
|
+
if [ $? -ne 0 ]; then
|
|
173
|
+
echo "Architecture violations found. Fix them or run: arch-drift allow <source>:<target>"
|
|
174
|
+
exit 1
|
|
175
|
+
fi
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Why this exists
|
|
179
|
+
|
|
180
|
+
AI coding agents (Claude Code, Cursor, Copilot) write code fast but don't know your architecture boundaries. arch-drift catches violations at commit time, whether the code was written by a human or an AI.
|
|
181
|
+
|
|
182
|
+
Traditional linters check syntax. arch-drift checks structure: "should this file be importing from that module?"
|
|
183
|
+
|
|
184
|
+
## License
|
|
185
|
+
|
|
186
|
+
MIT
|