Skip to main content

CLI Overview

The Stratix CLI (@stratix/cli) is a powerful command-line tool for creating projects, generating code, and managing extensions.

Installation​

# Global installation
npm install -g @stratix/cli

# Or use with npx
npx @stratix/cli new my-app

Available Commands​

CommandDescription
newCreate a new Stratix project
generate (or g)Generate code (entities, commands, queries, etc.)
addAdd extensions to your project
infoDisplay project information

Quick Start​

# Create a new project
stratix new my-app

# Navigate to project
cd my-app

# Generate an entity
stratix generate entity Product

# Add an extension
stratix add @stratix/http-fastify

# Display project info
stratix info

Command Structure​

stratix <command> [options] [arguments]

Global Options​

--help, -h      Show help
--version, -v Show version

Interactive Mode​

Most commands support interactive mode when arguments are omitted:

# Interactive project creation
stratix new

# Interactive code generation
stratix generate

# Interactive extension installation
stratix add

Non-Interactive Mode​

Provide all arguments for CI/CD pipelines:

stratix new my-app --template ddd --skip-install
stratix generate entity Product --path src/domain/entities
stratix add @stratix/http-fastify --skip-install

Project Templates​

The CLI supports multiple project templates:

  • DDD (Default) - Domain-Driven Design structure
  • Modular - Bounded contexts for microservices
  • Minimal - Bare-bones setup
stratix new my-app --template modular

Code Generators​

Generate boilerplate code:

  • Entity - Domain entities
  • Value Object - Value objects
  • Command - CQRS commands
  • Query - CQRS queries
  • Repository - Repository interfaces
  • Quality - Quality checks (tests, linting)
stratix generate entity User
stratix generate command CreateUser
stratix generate query GetUserById

Extension Management​

Add official and third-party extensions:

# HTTP server
stratix add @stratix/http-fastify

# Database
stratix add @stratix/postgres

# AI providers
stratix add @stratix/ai-openai
stratix add @stratix/ai-anthropic

Configuration​

The CLI reads configuration from:

  1. Command-line flags (highest priority)
  2. stratix.config.js in project root
  3. package.json stratix field
  4. Default values (lowest priority)

stratix.config.js​

module.exports = {
template: 'ddd',
generators: {
entity: {
path: 'src/domain/entities',
suffix: '.entity.ts'
},
command: {
path: 'src/application/commands',
suffix: '.command.ts'
}
}
};

Best Practices​

1. Use Interactive Mode for Learning​

stratix new  # Learn available options

2. Use Non-Interactive for Automation​

stratix new my-app --template ddd --skip-install

3. Customize Generators​

// stratix.config.js
module.exports = {
generators: {
entity: {
path: 'src/domain',
template: 'custom-entity.hbs'
}
}
};

4. Version Lock in CI/CD​

npx @stratix/cli@0.1.3 new my-app

Next Steps​