CLI Commands
The Backcap CLI is invoked with npx @backcap/cli (or backcap if installed globally). It is built with citty and clack.
backcap init
Section titled “backcap init”Initialize a Backcap project in the current directory.
npx @backcap/cli initOptions:
| Option | Alias | Description |
|---|---|---|
--yes | -y | Skip all prompts (non-interactive mode) |
What it does:
- Detects your framework by inspecting
package.jsondependencies - Detects your package manager by looking for lockfiles
- If detection succeeds, logs the detected values; otherwise prompts you to select them
- Checks whether a
backcap.jsonalready exists- If it exists, shows the current config and asks whether to overwrite
- If you decline, the command exits without making changes
- Writes a
backcap.jsonto the current directory
Generated backcap.json:
{ "framework": "express", "packageManager": "pnpm", "paths": { "domains": "src/domains", "skills": ".claude/skills", "shared": "src/shared" }, "installed": { "domains": [] }}Detected frameworks:
package.json dependency | Detected framework |
|---|---|
next | nextjs |
@nestjs/core | nestjs |
fastify | fastify |
hono | hono |
express | express |
Detected package managers (by lockfile presence):
| Lockfile | Package manager |
|---|---|
bun.lockb | bun |
pnpm-lock.yaml | pnpm |
yarn.lock | yarn |
package-lock.json | npm |
backcap add
Section titled “backcap add”Install a domain from the registry.
npx @backcap/cli add <name>Arguments:
| Argument | Required | Description |
|---|---|---|
name | Yes | The name of the domain to install (e.g., auth, blog) |
Options:
| Option | Alias | Description |
|---|---|---|
--yes | -y | Skip all prompts (non-interactive mode) |
What it does:
- Verifies that
backcap.jsonexists (exits with an error if not) - Loads the configuration from
backcap.json - Fetches the JSON bundle from
https://faroke.github.io/backcap/dist/<name>.json - Runs conflict detection against your existing files:
- If all incoming files are identical to existing files, exits early (nothing to do)
- If there are no conflicts, proceeds directly to the install prompt
- If there are conflicts, shows a summary and offers resolution options:
- Compare and continue — shows detailed diffs, then overwrites all conflicting files
- Select files individually — pick which files to write
- Choose a different path — prompts for a new base path
- Abort installation — cancel, no files written
- Prompts for final confirmation before writing files
- Writes source files to the domains directory
- Installs npm dependencies listed in the bundle
- Installs
peerDependenciesas devDependencies in a second install pass - Updates
backcap.jsonto record the installed domain
Example:
npx @backcap/cli add auth# Fetching auth...# No conflicts detected.# Install auth? › Yes# Installing dependencies: zod# Installing dev dependencies: @types/bcrypt## auth v1.0.0 installed successfully!## Domain: src/domains/auth## Next steps:# 1. Review the installed files in src/domains/auth/# 2. Implement the port interfaces (IUserRepository, IPasswordHasher, ITokenService)# 3. Run the test suite to verify: npx vitest runConflict resolution options:
When the CLI detects files that differ from what is already on disk:
Conflicts detected: ~ src/domains/auth/domain/entities/user.entity.ts (modified)
How would you like to proceed? › Compare and continue (overwrite all) Select files individually Choose a different path Abort installationbackcap list
Section titled “backcap list”Browse available domains from the registry.
npx @backcap/cli listWhat it does:
- Loads
backcap.jsonif it exists (to know which domains are already installed) - Fetches the registry catalog from
https://faroke.github.io/backcap/dist/registry.json - Renders a table of available domains with their name, description, type, and installation status
Example output:
Name Description Type Statusauth User registration and login domain installedblog Blog post management domain availablesearch Full-text search domain availablenotifications Email and push notifications domain availableGlobal Options
Section titled “Global Options”All commands support this option:
| Option | Description |
|---|---|
--help, -h | Show help text for the command |
The --version / -v flag is available on the root backcap command only (not on subcommands).
Error Handling
Section titled “Error Handling”The CLI uses a consistent error format. Errors are displayed with a red cross prefix and a descriptive message:
✖ No backcap.json found. Run `backcap init` first.✖ Could not fetch "auth" from registry.✖ Invalid data received from registry.Common errors and their solutions:
| Error | Solution |
|---|---|
No backcap.json found | Run npx @backcap/cli init first |
Could not fetch "<name>" from registry | Check your internet connection; verify the name with backcap list |
Invalid data received from registry | The registry may be temporarily unavailable; try again |
Registry URL
Section titled “Registry URL”By default, the CLI fetches from https://faroke.github.io/backcap. This is not currently configurable via flags but can be customized by editing the source (if you have the registry source locally for development purposes).