# The one-dependency rule, explained

> Deployable Ferrite apps declare a single Cargo dependency, ferrite-app, so every other line in the build passes through the source gate. Shared code installs as source packages.

Every deployable Ferrite app declares one runtime dependency. Templates created by `ferrite new` write that entry into `Cargo.toml` and vendor the SDK alongside your project:

```toml
[dependencies]
ferrite-app = { path = "vendor/ferrite-app" }
```

The vendored copy exists for local builds and tests. During a remote build, the platform substitutes its own `ferrite-app`, so any edit you make under `vendor/ferrite-app` works locally and never deploys.

The platform's source gate enforces four Cargo restrictions before compilation starts:

- Any other `[dependencies]` entry is rejected with `CODE_DEP_UNLISTED`. Matching runs on the dependency name, so local path dependencies are refused the same way as registry entries.
- Any dependency entry carrying a `git`, `registry`, `branch`, `rev`, or `tag` key is rejected with `CODE_DEP_UNLISTED`.
- Any `build.rs` file, any `package.build` value other than `false`, or any non-empty `[build-dependencies]` table is rejected with `CODE_BUILD_SCRIPT`.
- Any target setting `proc-macro` is rejected with `CODE_PROC_MACRO`.

Each of those mechanisms would either import uninspected code or execute arbitrary code during compilation.

## Why the rule exists

A running Ferrite app receives handles solely for the services, routes, and outbound destinations listed in `ferrite.json`. Allowing extra crates would let third-party code reach for raw sockets, host files, or the build environment outside your manifest and outside the source gate's visibility. Restricting `[dependencies]` to `ferrite-app` guarantees that every line compiled into the deployed binary comes either from your own project tree (checked by the source gate before compilation) or from the platform's own SDK.

Static checks are the pre-build filter; OS containment enforces the runtime boundary. See [What bounds your app](/docs/why-it-is-safe) for how each layer works.

Deployment builds ignore `[dev-dependencies]` because test crates never enter the deployed binary. When the platform runs your tests remotely, its test gate admits only `ferrite-app-test` and `tokio` under `[dev-dependencies]`.

## Sharing code through source packages

Reusable subsystems distribute as source packages instead of Cargo crates. Running `ferrite add` copies a published package and its transitive dependencies into your app's `src/` tree and records the mount in `ferrite-packages.json`:

```bash
ferrite add agent-ready
```

Each copied file starts with a `@generated by ferrite-pkg` header identifying its source package and version. Update an installed package by running `ferrite add --force <name>` instead of editing the generated copies by hand. Because the package compiles as part of your crate, it runs strictly under your app's own handles and passes through the same source gate as code you wrote.

Ferrite's web frameworks follow the same model. Alloy and Rsx install as source packages built exclusively on what `ferrite-app` re-exports, so a full web application still compiles with a single runtime dependency.

## Porting an existing Rust project

An existing Rust codebase that pulls crates from crates.io will not deploy unchanged. Each external crate has to be replaced by a re-export from `ferrite-app` (`serde`, `serde_json`, and `tracing`, among others), by a published source package, or by code inside your own `src/` tree. For a new backend written with your coding agent, that constraint fits naturally; for a large existing Rust codebase, expect real porting work.

See [Packages](/docs/packages) for the published package catalog, verification model, and mounting rules.
