DocsReferenceCLI

CLI Reference

The TopGun CLI provides a unified interface for development, testing, and cluster management. It drastically simplifies the developer experience by reducing onboarding from 30-60 minutes to under 5 minutes.

Zero Docker Required

The CLI defaults to SQLite storage, allowing you to start developing immediately without Docker or PostgreSQL setup.

Quick Start

terminal
# Clone and setup (2 minutes)
git clone https://github.com/topgunbuild/topgun.git
cd topgun
npx topgun setup --yes
npx topgun dev

# Server running at http://localhost:8080

Commands

topgun doctor

Check your environment for required dependencies and configuration.
terminal
npx topgun doctor

Checks performed:

CheckRequiredDescription
Node.jsYesVersion 18 or higher
pnpmYesVersion 10.13.1 or higher
DockerNoOptional (required for PostgreSQL mode)
Port 8080YesDefault server port must be available
DependenciesYesnode_modules must be installed
BuildYespackages/server/dist must exist
.env fileYesEnvironment configuration

Example output:

output
TopGun Environment Check

 Node.js: v20.10.0 (OK)
 pnpm: 10.13.1 (OK)
 Docker: Not installed (optional for SQLite mode)
 Port 8080: Available
 Dependencies: Installed
 Build: Built
 .env file: Present

All checks passed! Ready to run.

topgun setup

Interactive project setup wizard.
terminal
# Interactive mode
npx topgun setup

# Non-interactive with defaults (SQLite)
npx topgun setup --yes

# Specify storage backend
npx topgun setup --storage postgres
npx topgun setup --storage sqlite
npx topgun setup --storage memory

Options:

OptionDescriptionDefault
-y, --yesSkip prompts, use defaultsfalse
--storage <type>Storage backend: sqlite, postgres, memorysqlite

Interactive mode prompts:

  1. Storage backend - Choose between SQLite (no Docker), PostgreSQL (production), or Memory (testing)
  2. k6 installation - Optional load testing tools
  3. Dev Container - VS Code/Codespaces configuration

Example output:

output
TopGun Setup Wizard

[1/4] Creating .env file...
 .env created

[2/4] Installing dependencies...
 Dependencies installed

[3/4] Building packages...
 Build complete

[4/4] Skipping database (SQLite mode)
 SQLite will be used

Setup complete!

  Run:
    npx topgun dev

  Server will start at http://localhost:8080

topgun dev

Start the development server with live reload.
terminal
# Start with defaults
npx topgun dev

# Custom port
npx topgun dev --port 3000

# Skip database startup (PostgreSQL mode)
npx topgun dev --no-db

Options:

OptionDescriptionDefault
-p, --port <port>Server port8080
--no-dbSkip database startupfalse

The dev server uses tsx watch for automatic reloading when source files change.

topgun test

Run tests for specific packages or the entire project.
terminal
# Run all tests
npx topgun test

# Package-specific tests
npx topgun test core
npx topgun test client
npx topgun test server
npx topgun test react
npx topgun test adapters

# E2E tests
npx topgun test e2e

# k6 load tests
npx topgun test k6:smoke
npx topgun test k6:throughput

# With coverage
npx topgun test core --coverage

Available scopes:

ScopePackageDescription
core@topgunbuild/coreCRDT, HLC, MerkleTree
client@topgunbuild/clientBrowser/Node SDK
server@topgunbuild/serverWebSocket server
react@topgunbuild/reactReact hooks
adapters@topgunbuild/adaptersStorage adapters
e2e-End-to-end tests
k6:smoke-Quick load test
k6:throughput-Full throughput test

topgun config

Manage project configuration.
terminal
# Show current configuration
npx topgun config --show

# Set transport mode
npx topgun config --transport ws
npx topgun config --transport http

# Set storage backend
npx topgun config --storage sqlite
npx topgun config --storage postgres

Options:

OptionDescription
--showDisplay current configuration
--transport <type>Set transport: ws, http
--storage <type>Set storage: sqlite, postgres, memory

Cluster Commands

topgun cluster:start

Start a local multi-node cluster for testing.
terminal
# Start 3-node cluster (default)
npx topgun cluster:start

# Custom node count
npx topgun cluster:start --nodes 5

Options:

OptionDescriptionDefault
-n, --nodes <count>Number of cluster nodes3

topgun cluster:stop

Stop all running cluster nodes.

terminal
npx topgun cluster:stop

topgun cluster:status

Display the status of running cluster nodes.

terminal
npx topgun cluster:status

Debug Commands

topgun debug:crdt

CRDT debugging and inspection tools.
terminal
# Export CRDT state
npx topgun debug:crdt export --map users --output users.json

# Replay operations
npx topgun debug:crdt replay --map users

# Compare states
npx topgun debug:crdt diff --map users

Actions:

ActionDescription
exportExport map state to JSON
replayReplay operations for debugging
diffCompare states between nodes

Options:

OptionDescription
--map <name>Target map name
--output <file>Output file path

topgun search:explain

Explain search query scoring (BM25/RRF breakdown).
terminal
npx topgun search:explain --query "example search" --map documents

Options:

OptionDescription
--query <query>Search query to explain
--map <name>Target map name

Environment Variables

The CLI respects the following environment variables (set in .env):

VariableDescriptionDefault
STORAGE_MODEStorage backendsqlite
DB_PATHSQLite file path./topgun.db
SERVER_PORTServer port8080
DATABASE_URLPostgreSQL connection string-
DB_HOSTPostgreSQL hostlocalhost
DB_PORTPostgreSQL port5432
DB_USERPostgreSQL usertopgun
DB_PASSWORDPostgreSQL password-
DB_NAMEPostgreSQL databasetopgun

Storage Modes

SQLite (Default)

Recommended for Development

SQLite requires no external dependencies and is perfect for local development, prototyping, and CI/CD testing.

Limitations:

  • Single-node only (no clustering)
  • Lower performance than PostgreSQL
  • Max ~500K records recommended

PostgreSQL

Recommended for production. Requires Docker or external PostgreSQL instance.

terminal
# Setup with PostgreSQL
npx topgun setup --storage postgres

# Requires Docker running
docker compose up -d postgres

Memory

For testing only. Data is lost on restart.

terminal
npx topgun setup --storage memory