The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Guard listing page.
@codapult/guard is a local-first, model-agnostic architecture guard for JavaScript and
TypeScript projects.
It learns what already exists, records the project’s architectural memory, and can protect future changes from introducing regressions covered by the project’s approved policy.
Suppose a SaaS project has an established boundary:
An AI agent can still produce code that is valid TypeScript but crosses that boundary:
After the project has explicitly approved a matching import rule or deterministic contract, Guard checks the changed files and reports matching violations deterministically:
The file path, rule ID, message, and counts depend on the project. This is the actual CLI output
shape: Guard does not infer that every Client → Database edge is forbidden, and it does not
activate proposals silently. The team approves the relevant policy first; then existing findings
can be baselined while newly matching violations fail the gate and give the agent bounded evidence
to repair.
Guard does not tell every project to use the same architecture. It discovers the architecture that is already there, then lets the team decide what becomes policy.
The core is universal. The strongest first-class scenarios are Next.js SaaS and AI-assisted development, including server/client boundaries, routes, persistence, authentication, billing, background jobs, environment configuration, and AI integrations.
Guard is an independent open-source project from Codapult. It does not require Codapult and can be installed in any JavaScript or TypeScript repository.
The relationship is complementary:
| Project | Role |
|---|---|
@codapult/guard | Universal architecture guardrails, project memory, contracts, MCP, and AI-agent context. |
@codapult/cli | Codapult SaaS project CLI that includes Guard through a thin adapter. |
| Codapult | Full-source Next.js SaaS foundation with conventions Guard can discover and protect. |
Use standalone Guard for any compatible project. Use the Codapult CLI when working on a Codapult SaaS project and you want project management, database, plugins, deployment, MCP, and Guard in one CLI.
AI agents can produce syntactically valid code that still violates the architecture of a real project: a client component imports server-only code, a new action bypasses the established auth boundary, a route writes to the database directly, or a change duplicates a service that already exists.
Existing tools remain essential, but they solve different problems:
| Tool category | Primary question | Guard’s relationship |
|---|---|---|
| TypeScript | Is the code type-correct? | Uses the project’s typecheck as an optional gate. |
| ESLint / Biome | Does code follow language and style rules? | Does not duplicate their lint rules. |
| Tests | Does behavior match executable expectations? | Runs configured checks when enabled; does not replace tests. |
| SAST / dependency scanners | Is there a known security or dependency risk? | Can connect adapters; focuses on architecture and change impact. |
| PR review services | What semantic concerns should a reviewer consider? | Produces a bounded, redacted review packet for the selected AI host. |
| Guard | Is the project becoming architecturally worse? | Maintains project-specific architectural memory and regression gates. |
Requirements: Node.js >=20.19 and a JavaScript or TypeScript project.
The package exposes the codapult-guard binary:
The npm package is scoped as @codapult/guard; the executable intentionally remains
codapult-guard for discoverability and consistency with the standalone product name.
Run from the project root:
init is protected and refuses to overwrite an existing baseline. Use init --force only when
deliberately replacing the project memory. Use analyze to refresh discovered facts without
resetting the baseline.
Guard separates facts, policy, verification, and decision:
| Layer | Contains | How it is produced |
|---|---|---|
| Facts | AST, files, imports, dependencies, routes, calls, capabilities, graph, Git history | Deterministic local discovery |
| Policy | Rules, contracts, conventions, baseline | Observed proposals plus explicit team approval |
| Verification | Changed-file checks, impact analysis, contracts, project checks, review packet | Local CLI, MCP, CI, and existing project tools |
| Decision | Pass, fail, warning, needs-review, not-configured | Developer or AI host using Guard evidence |
Guard does not assume a fixed UI → actions → services → repositories → database architecture.
It can discover that shape when the project exhibits it, but observed patterns become enforceable
only after explicit approval.
Policy paths are validated as project-relative paths. Guard rejects traversal, absolute paths, and symlinks escaping the project root; import-boundary checks include imports, re-exports, and literal dynamic imports.
The model is framework-aware without being framework-dependent:
| Area | Examples of discovered evidence |
|---|---|
| JavaScript / TypeScript | AST modules, declarations, calls, directives, aliases, re-exports, dynamic imports |
| Next.js / React | App Router routes, route methods, Server Actions, client/server boundaries |
| API boundaries | Route handlers, API modules, entrypoints, impact paths |
| Data | ORM packages, schemas, migrations, repositories, persistence boundaries |
| Capabilities | Auth, payments, email, AI/RAG, queues, storage, cache, search, analytics, content |
| Operations | Environment references, configs, deployment, observability, webhooks |
| Repository shape | Workspaces, package scripts, dependencies, cycles, import hotspots, Git history |
| Testing | Test files, test scripts, workspace checks, changed files |
Capabilities are evidence, not requirements. A Vite app, Express service, Hono project, Node package, monorepo, or Next.js SaaS can all use the same Guard core.
Guard is an architecture control plane for AI-assisted development. It protects project-specific boundaries and change impact using local facts, approved policy, and deterministic verification.
Guard is not a replacement for ESLint, TypeScript, tests, SAST, or a general-purpose PR bot. Those tools answer different questions; Guard connects their results with the architectural memory that an AI coding agent needs before and after changing a repository.
init builds project memory and establishes the initial baseline.check --changed is the fast deterministic architecture gate.review prepares a bounded and redacted diff packet for an AI host; it does not call an LLM.verify runs Guard policy, configured project checks, adapters, runtime diagnostics, and
contract validation.audit inspects the complete current state, including findings accepted by the baseline.For a focused change explanation, use codapult-guard impact <file...> or the equivalent
codapult_guard_impact MCP tool. It reports both directions of the dependency graph: what the
changed module uses and which transitive callers may be affected. review includes the same
impact packet plus typed Git changes (added, modified, deleted, and renamed) for the AI
host.
Guard state is stored in .codapult/guard/:
Commit policy and baseline files when the team wants shared guardrails. Treat cache artifacts as disposable according to the project’s policy, and never commit secrets.
Budgets are policy, not a universal style rule. Add them only for a named risk boundary such as a service, route handler, or dependency-heavy module:
Place budgets in the budgets array in .codapult/guard/rules.json. Supported metrics are
lines, bytes, and imports. Generated files, schemas, migrations, and other paths are not
checked unless they are explicitly included in scope; a wildcard such as * can intentionally
cover the project root. Invalid, absolute, parent-directory, or nonexistent scopes fail the Guard
gate. Changing a budget is a policy decision:
review the diff and update its written reason rather than silently increasing the limit.
Guard is deliberately model-agnostic. It does not send source code to a remote LLM and does not edit source files by itself. The AI host owns the model call, permissions, repair loop, and final decision.
Start the standalone MCP server over stdio:
Register that command in the MCP client from the project root. For example, Cursor can use
.cursor/mcp.json:
For clients that accept a generic stdio server, use the same command and set its working
directory to the project root. Guard reads local files only; no API key or model provider is
required. Host-specific examples are in docs/integrations/.
Recommended agent loop:
For Cursor, Claude Code, Codex, Gemini CLI, GitHub Copilot, and generic hosts, see
docs/integrations/.
Guard is also prepared for discovery through the official MCP Registry.
The Registry entry points to the published @codapult/guard npm package and its stdio MCP server;
it does not replace npm installation or the host-specific configuration above. Registry metadata is
validated during CI and published after npm in the release workflow. The Registry is currently in
preview, so the canonical installation path remains npm.
For workflows where the authoring agent must not approve its own policy proposals, set Guard to
protected mode in rules.json:
MCP can then read and propose policy, while approval happens through the CLI or a protected CI/PR
process. With requireDistinctActor, CLI and permitted MCP approvals require GUARD_APPROVER,
and Guard rejects the same declared actor when a proposal was generated with GUARD_PROPOSER.
These variables provide declared provenance only; external branch protection or signed identity
remains responsible for proving who approved the change.
See the extension map for the supported AI-host, CI/PR, policy-pack, tool adapter, approval-governance, and observability integrations.
Copy the consumer workflow into a project that has installed and initialized Guard:
Or copy it from docs/guard-ci.yml. It runs project verification and exports
Guard findings as SARIF for GitHub code scanning.
The package repository separately runs its own unit, typecheck, build, and packaging checks in
.github/workflows/ci.yml, while the fixture workflow tests Guard on
real project shapes.
| Command | Purpose |
|---|---|
init | Create project memory and the initial baseline. |
analyze | Refresh facts without changing policy or baseline. |
propose | Generate evidence-based rule and contract proposals. |
check --changed | Enforce active policy on changed and untracked files. |
audit | Scan the complete current project, including baseline findings. |
review | Create a bounded semantic-review packet for an AI host. |
verify | Run the configured completion gate. |
doctor | Diagnose invalid or missing Guard artifacts. |
history / history-diff | Inspect project model, module graph, and architecture-edge evolution. |
impact <files...> | Explain dependencies, transitive dependents, capabilities, and contracts affected by files. |
policy explain <id> | Explain a policy item, its evidence, and approval history. |
rules / contracts | Approve or reject proposed policy. |
baseline | Review or intentionally accept existing findings. |
Use analyze --refresh after a structural change. doctor --fix-cache removes only the disposable
discovery cache; it does not change rules, contracts, baseline, or source files.
Guard state is safe for concurrent CLI/MCP readers and writers: derived facts are published as an
atomic generation, policy updates use revisions, and short write contention is waited out. A
process that dies while holding the state lock is detected by its local PID and the lock is
recovered; use --no-wait when an integration needs immediate contention feedback.
Run pnpm exec codapult-guard <command> --help for command-specific options.
Every verify run also writes a local manifest under
.codapult/guard/history/runs/<run-id>.json. It records stage durations, the outcome, and the
policy gate that decided the result. It contains no source code or external telemetry. These
manifests make a failed run explainable without turning Guard into a production tracing system.
The repository validates the product through multiple layers:
Run the maintainer checks locally:
@codapult/guard starts at 0.1.0 as a public alpha. The deterministic core is usable, tested,
and intended for real projects, while policy schema and integration surfaces may still evolve
before 1.0.0.
MIT. See LICENSE.