CLI Reference

The ninjadog CLI is distributed as a .NET global tool for project scaffolding and code generation.

Table of contents
  1. Installation
  2. Typical Workflow
  3. Commands
    1. ninjadog init
      1. Template and use case selection
      2. Interactive prompts (Custom use case)
      3. Example session
    2. ninjadog validate
    3. ninjadog add-entity
    4. ninjadog update
    5. ninjadog build
    6. ninjadog ui
  4. Next Steps

Installation

dotnet tool install -g Ninjadog

After installation, run ninjadog --help to verify the tool is available.

Typical Workflow

ninjadog init              Create a new project (interactive)
       |
  edit config              Define your entities in ninjadog.json
       |                       --- or ---
ninjadog add-entity        (Optional) Add more      ninjadog ui
       |                   entities from the CLI    Launch the visual
ninjadog validate          Check your config         config builder
       |                   for errors                    |
ninjadog build             Run the generators        ninjadog build
       |
  dotnet run               Launch your API

ninjadog update            Refresh schema after upgrading the CLI

Commands

ninjadog init

Initializes a new Ninjadog project in the current directory. By default, init runs in interactive mode, prompting you for project details, then writes the configuration with a sample Person entity to get you started.

ninjadog init

Options:

Option Description
--default Skip prompts and use default values.
--name <name> Set the project name (skips the name prompt).
--namespace <ns> Set the root namespace (skips the namespace prompt).
--template <name> Template to use (e.g. CrudWebAPI). Skips the template prompt.
--use-case <name> Use case to scaffold (TodoApp, RestaurantBooking, or Custom). Skips the use case prompt.
--from-prompt <text> Generate config from a natural language description using AI. Requires ANTHROPIC_API_KEY environment variable.

Template and use case selection

When you run ninjadog init interactively, the CLI first asks you to choose a template and a use case:

Prompt Choices Description
Template CrudWebAPI The code generation template to use. Currently only CrudWebAPI is available.
Use case TodoApp, RestaurantBooking, Custom A pre-built use case with entities already defined, or Custom to define your own entities interactively.

Selecting TodoApp or RestaurantBooking creates a fully configured ninjadog.json with pre-defined entities, relationships, and seed data. Selecting Custom continues with the interactive prompts below.

Interactive prompts (Custom use case)

When you select the Custom use case, the CLI asks for the following project settings:

Prompt Default Description
Project name NinjadogApp The display name for your API project.
Version 1.0.0 The initial semantic version.
Description Welcome to Ninjadog! A short description of the project.
Root namespace NinjadogApp The C# root namespace for generated code.
Output path . Directory where generated files are written (relative to the config file).

Press Enter at any prompt to accept the default value.

Example session

$ ninjadog init
? Project name: MyApi
? Version: 1.0.0
? Description: My REST API
? Root namespace: MyApi
? Output path: src/applications/MyApi
Ninjadog settings file created successfully.

This creates a ninjadog.json in the current directory:

{
  "config": {
    "name": "MyApi",
    "version": "1.0.0",
    "description": "My REST API",
    "rootNamespace": "MyApi",
    "outputPath": "src/applications/MyApi",
    "saveGeneratedFiles": true
  },
  "entities": {
    "Person": {
      "properties": {
        "Id": { "type": "Guid", "isKey": true },
        "FirstName": { "type": "string" },
        "LastName": { "type": "string" },
        "BirthDate": { "type": "DateTime" }
      }
    }
  }
}

Examples:

# Interactive mode (prompts for template and use case)
ninjadog init

# Scaffold TodoApp use case directly
ninjadog init --use-case TodoApp

# Scaffold RestaurantBooking use case
ninjadog init -u RestaurantBooking

# Non-interactive with defaults
ninjadog init --default

# Non-interactive with custom values
ninjadog init --name MyApi --namespace MyApi.Web

# Generate from natural language (requires ANTHROPIC_API_KEY)
ninjadog init --from-prompt "A blog platform with users, posts, tags, and comments"

The generated Person entity is a starter template. Replace or extend it with your own domain entities before running ninjadog build.

A ninjadog.json file must not already exist in the current directory. If one is found, the command exits with an error to avoid overwriting your configuration.

ninjadog validate

Validates your ninjadog.json configuration file against the schema and checks for common errors.

ninjadog validate [OPTIONS]

Options:

Option Description
--file <path> Path to the configuration file. Default: ninjadog.json
--strict Treat warnings as errors (exit code 1).

Exit codes:

Code Meaning
0 Configuration is valid.
1 Validation errors found.
2 File not found or JSON parse error.

Example output:

$ ninjadog validate

Validating ninjadog.json...

  ERROR  NINJ001  Entity "Product" has no properties defined.
  ERROR  NINJ003  Property "Product.Id" is marked as key but type "string" has no maxLength.
  WARN   NINJ007  Entity "Order" has no key property. A Guid key named "Id" will be added.

Result: 2 errors, 1 warning

Validation rules:

Code Severity Description
NINJ001 Error Entity has no properties defined.
NINJ002 Error Entity has multiple key properties.
NINJ003 Error String key property has no maxLength.
NINJ004 Error Property type is not recognized.
NINJ005 Error Relationship references a non-existent entity.
NINJ006 Error Enum name conflicts with an entity name.
NINJ007 Warning Entity has no key property (a default will be added).
NINJ008 Warning Seed data property does not match any entity property.
NINJ009 Warning outputPath directory does not exist.
NINJ010 Warning Config file does not include $schema property.

Run ninjadog validate before ninjadog build to catch configuration mistakes early. In CI pipelines, use --strict to ensure warnings are not ignored.

ninjadog add-entity

Adds a new entity to your existing ninjadog.json configuration file. The entity is created with a default Guid primary key.

ninjadog add-entity <EntityName>

The entity name should be in PascalCase (e.g., Product, OrderItem). A ninjadog.json file must already exist in the current directory – run ninjadog init first if you haven’t already.

Example:

ninjadog add-entity Product

This appends a Product entity to the entities section of your ninjadog.json:

{
  "entities": {
    "Person": { ... },
    "Product": {
      "properties": {
        "Id": {
          "type": "Guid",
          "isKey": true
        }
      }
    }
  }
}

After adding an entity, open ninjadog.json to define additional properties before running ninjadog build.

ninjadog update

Updates the ninjadog.schema.json file in the current directory to the version embedded in the installed CLI tool. This is useful after upgrading Ninjadog to get IDE autocompletion and validation for newly added configuration options.

ninjadog update

Example:

$ ninjadog update
Schema file updated successfully.
  -> ninjadog.schema.json

Run ninjadog update after upgrading the CLI tool to ensure your local schema stays in sync with the installed version.

ninjadog build

Builds and runs the generator engine against your project configuration. This reads the ninjadog.json file in the current directory and produces the generated source files.

ninjadog build

ninjadog ui

Launches a local web server that hosts a visual configuration builder for your ninjadog.json file. The UI lets you create and edit entities, enums, and seed data through a browser-based interface instead of editing JSON by hand.

ninjadog ui [OPTIONS]

Options:

Option Description Default
--port <number> Port number for the local web server 5111
--path <path> Path to the ninjadog.json file to edit ./ninjadog.json
--no-open Do not open the browser automatically false

Visual builder features:

By default, ninjadog ui opens your browser automatically. Use --no-open if you are running on a headless server or want to open the URL manually.

A ninjadog.json file must already exist in the target directory. Run ninjadog init first if you haven’t already.

Example:

# Start on the default port and open the browser
ninjadog ui

# Start on a custom port without opening a browser
ninjadog ui --port 8080 --no-open

Next Steps