archstrict
archstrictv0.4.0MIT
TypeScript module boundary checker: default-private module surfaces, layers, cycles, and a todo freeze that can only shrink.
インストール
npm install archstrict- GitHub のソースコード
- 使っているツール: depug, nukadoko, stryker-agent-reporter
- このツールを使っているツール: autospawn, depug, finderscope, firstlight, nukadoko, polylinedb, solarsql, spacequery, stryker-agent-reporter
archstrict は、ArchUnit と同じ考え方で、TypeScript のモジュール境界を検査します。 tsc や型検査ツールは型を、ESLint はスタイルを調べます。 archstrict が調べるのは、モジュールの間の境界です。 モジュールは、コードベースのほかの部分に公開用のファイル (public surface) を 1 つだけ見せます。 そのファイルを経由せずに内部を直接 import すると、違反になります。 違反の報告には、規則の ID、場所、理由、直すためのコマンドが付くので、エージェントが自分の誤りを自分で直せます。
- 宣言したモジュール。
archstrict.config.tsは 1 つの TypeScript の値です。declaredModulesで各モジュールをディレクトリか単一のファイルとして指定し、surfaceでその公開用のファイルを指定します。 どのモジュールにもexcludeのパターンにも当てはまらないファイルは、uncovered-moduleの違反になります。 設定に未知のキーがあるとエラーになり、受け付けるキーが示されます。 - エージェントがそのまま対応できる報告。
archstrict checkは、各違反を規則の ID、path:line:col、証拠、becauseの理由、do:のコマンドつきで表示します。--jsonは同じ内容を出力し、--ruleと--moduleで絞り込めます。 - レイヤーとドメインの規則。
classifyでファイルにタグを付け、edgesがallowDeny、order、pointの規則でタグ間の import を検査します。allowDenyかpointの規則にguard: trueを付けると、まだどのファイルにもない import を禁止できます。archstrict diagramは、設定を Mermaid のフローチャートとして描きます。 - 減る一方の todo ファイル。
最初の
archstrict todoは、現在の違反をarchstrict.todo.jsonに凍結し、その後の実行はエントリを取り除くだけです。strictに挙げたモジュールは、エントリを 1 つも持てません。 - 編集前の問い合わせ。
archstrict rules <path>は、まだ存在しないパスでも、そのパスが属するモジュールと、適用されるタグと制約を答えます。archstrict simulateは、ソースや設定の変更を、書き込まずにプレビューします。 - モジュール構成の次の一手。
archstrict recommendは、実際の import のグラフから、edgesの規則と公開用のファイルを提案します。archstrict hotspotsは、コミット数とファンインでモジュールにスコアを付け、一緒に変更されるモジュールの組を一覧表示します。
エージェントでの使い方
Section titled “エージェントでの使い方”- ファイルを作る前や import を追加する前に、エージェントは
npx archstrict rules <path>を実行します。 - 編集の後で
npx archstrict checkを実行し、各do:の行のとおりに直します。 - Claude Code では、archstrict プラグインの PostToolUse フックが、編集のたびに
archstrict check <file>を実行し、違反があればエージェントのコンテキストに返します。 このプラグインの MCP サーバーは、check、rules、search、simulateをツールとして提供します。 - ほかのエージェントのホストでは、
npx archstrict agentsがAGENTS.mdに編集前の指示を加え、CI が変更のたびにarchstrict checkを実行します。
archstrict には Node.js 22 以降が必要です。
npm install -D archstrictnpx archstrict initnpx archstrict checkinit は、最上位にあるソースのディレクトリと、最上位に単独で置かれたソースファイルのそれぞれに、モジュールを 1 つずつ宣言します。
そのため、最初の検査から、解析するすべてのファイルがどれかのモジュールに含まれます。
この最初のモジュール構成は、ファイルの目録にすぎません。
続けて npx archstrict recommend を実行し、検査を完成したアーキテクチャとして扱う前に edges の規則を加えてください。
フィクスチャで試す
Section titled “フィクスチャで試す”このリポジトリの fixtures/ に、小さなプロジェクトが 2 つあります。
1 つ目では、あるファイルが billing/rounding.ts を直接 import していて、billing モジュールの公開用のファイルを経由していません。
public-surface-bypass として、ファイル、行、列つきで報告します。 archstrict 0.3.0 で確認済み
$ archstrict check[public-surface-bypass] ./fixtures/archstrict-bypass/src/app/main.ts:1:28
'../billing/rounding.ts' resolved to a file inside module 'billing' other than its index.ts, index.tsx, index.mts, index.cts
because: a module's public surface is its only public surface; everything else is private
config: ./fixtures/archstrict-bypass/archstrict.config.ts:33:5 declaredModules[1] (governs)
do: import from src/billing/index.ts instead of src/billing/rounding.ts, adding the export there first if it is missing
modules: 2
modules without a public surface: 1
edges: 1
not covered by any declared module: 0
unresolved specifiers: 0
unsupported syntax: 0
type leaks: 0
todo: 0
summary: this config freezes today's import graph, not a target architecture; no edges rule is configured yet
do: archstrict recommend
do: archstrict hotspots
do: read node_modules/archstrict/skills/archstrict/references/rearchitect.md
do: archstrict todo2 つ目のプロジェクトでは、同じコードが billing/index.ts 経由で import しています。
ファイルを作る前に、そのパスがどのモジュールに属するかを確かめてください。
archstrict rules <path> は、そのパスが属するモジュールと、そのファイルが公開用のファイルかどうかを答えます。 archstrict 0.3.0 で確認済み
$ archstrict rules src/billing/rounding.tspath: ./fixtures/archstrict-bypass/src/billing/rounding.ts
exists: true
excluded: no
module: billing
tags: (none)
surface file: no
must-be-empty: ok
importable from: (none)
friend access: (none)
allowDeny constraints: (none)
order constraints: (none)
point constraints: (none)