Introducing a new way to review your PRs.

Read the announcement

solana-foundation / create-solana-dapp

The fastest way to create Solana apps 🚀 Templates 👉 https://github.com/solana-foundation/templates

View on GitHub

18 documents · Updated Nov 6, 2026

docs / cli-and-public-api

CLI and public API surface

create-solana-dapp offers one project-creation capability through two entrypoints. The CLI connects a shell command to the creation flow, while the package API lets another Node.js program supply the same creation choices directly.

System boundary

The package is a project generator rather than a long-running service. It accepts project choices, obtains the selected starter, and produces a ready project with completion guidance. The CLI owns prompts and terminal output; library callers own input collection when they use the lower-level API.

The published package supports both ESM imports and CommonJS requires. Its package metadata exposes the built library entrypoint and maps the create-solana-dapp command to the built executable.

Executable entrypoint

The executable entrypoint is src/…/index.ts. When a user runs create-solana-dapp, the package manager starts the built form of this file and passes the process argument vector to main. The entrypoint also reports an uncaught startup error through the CLI logger.

The executable is a thin process boundary. It does not select templates or create files itself. Instead, it connects operating-system input to the shared program entrypoint so shell use and programmatic use can reach the same creation path.

References: src/…/index.ts• L1-10 package.json• L23-35

Library entrypoint

The library entrypoint is src/index.ts. It exposes main for a complete CLI-style run and exposes lower-level contracts for callers that need to inspect data, validate input, or start creation themselves.

The main creation boundary is createApp. It accepts a resolved CreateAppArgs value and returns a CreateAppResult value with instructions produced during setup. The caller must resolve the project name, destination, package manager, template, and creation choices before calling it.

The root package exports capabilities by consumer need:

Consumer needPublic capability
Run the complete command flowmain
Create a project from resolved choicescreateApp, CreateAppArgs, and CreateAppResult
Resolve command inputgetArgs and GetArgsResult
Inspect template and version datagetAppInfo, fetchTemplateData, listTemplates, listTemplateIds, and listVersions
Use template and setup contractsTemplate types, catalog schemas, and init-script schemas
Validate input or detect a package managervalidateProjectName and detectInvokedPackageManager
Build completion guidancefinalNote and its argument type

Runtime schemas and their inferred TypeScript types are exported from the same root boundary used by the application. Consumers should use that root boundary rather than internal utility paths so imports and contracts remain supported together.

References: src/index.ts• L9-59 src/…/create-app.ts• L19-22 src/…/get-args-result.ts• L5-19 test/root-exports-schemas.test.ts• L47-182 package.json• L23-32

Command argument handoff

The command argument handoff turns the process argument vector into one resolved creation request. main identifies the invoked package manager and asks getArgs to combine supplied options, template data, and prompts before it starts app creation.

The handoff keeps input resolution separate from project generation:

  1. The executable supplies process.argv to main.
  2. getArgs resolves built-in options and the positional project name.
  3. Template-defined boolean flags remain template choices rather than built-in options.
  4. Prompts collect choices that the command did not supply.
  5. The resolved GetArgsResult becomes the input to createApp.
  6. main presents dry-run output, progress output, or completion guidance.

The CLI invocation and argument handling page covers the parsing boundary in detail. It explains supported inputs, validation, and the point where interactive input ends.

This diagram shows how shell input and library input meet at project creation.

flowchart LR
    A[Package command] --> B[Executable entrypoint]
    B --> C[main]
    C --> D[Resolved creation input]
    D --> E[createApp]
    F[Library consumer] --> G[Public API]
    G --> E
    E --> H[Generated project and completion result]

References: src/…/index.ts• L3-10 src/index.ts• L61-95 src/…/get-args.ts• L21-157 src/…/extract-template-option-flags.ts• L5-57

App creation initiation

App creation starts only after the system has a complete creation request. createApp is the reusable boundary that accepts the resolved request and returns the instructions that the outer program presents to the user.

Programmatic callers can bypass the CLI presentation layer and call createApp directly. They must provide the resolved CreateAppArgs contract rather than raw command-line tokens. Callers that need the executable's parsing and prompt behavior should call getArgs first and pass its result to createApp.

The app creation orchestration page follows this request through template selection, setup work, and the final completion result.

References: src/index.ts• L61-95 src/…/create-app.ts• L19-79

Consumer journeys

The CLI journey suits a person or script at a shell. The library journey suits an application that already owns input collection and controls when project creation begins.

JourneyEntryInput shapeOutput or effect
Interactive or scripted CLI usecreate-solana-dapp commandProcess arguments with prompts for missing choicesGenerated project, status messages, and completion guidance
Full programmatic command flowmain(argv)Argument vectorThe complete command flow and its user-facing behavior
Resolved programmatic creationcreateApp(args)Typed creation requestProject setup and returned instructions
Template or input inspectionRoot utility and schema exportsTyped arguments or data to validateTemplate data, validation results, or version information

main owns process-level behavior such as terminal output and exit handling. createApp is the reusable creation boundary and does not require a shell invocation.

References: src/index.ts• L61-95 src/…/create-app.ts• L19-79 src/…/fetch-template-data.ts• L6-26 src/…/validate-project-name.ts• L5-21

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the package bin mapping aligned with the built executable. Keep the root exports, main, module, and types entries aligned with the built library.
  • Preserve the distinction between raw CLI arguments handled by getArgs and the resolved CreateAppArgs contract consumed by createApp.
  • When adding a built-in CLI option, ensure it is not captured as a template-defined flag during argument handoff.
  • When changing GetArgsResult, review both main and programmatic callers because it is the shared boundary between input resolution and project creation.
  • When changing package-manager detection, check both command defaults and the package-manager choice stored in the resolved creation request.
  • When adding or changing a root schema export, keep its runtime object and inferred public type aligned with the schema used by the application.

Important failure modes

TriggerConsequenceGuard
The executable or package metadata points to a missing built entrypointPackage invocation or consumer import cannot startKeep the bin and root export targets aligned with build output
A caller passes incomplete or unresolved data to createAppCreation can fail after it starts because its contract is not satisfiedResolve input with getArgs or construct the full CreateAppArgs contract
More than one explicit package manager flag is suppliedArgument resolution stops before project creationSelect one package manager source
CLI parsing receives an unsupported option shapeThe command rejects the invocation before template selectionUse built-in options or supported boolean template flags
A root consumer uses a schema or type that is not exported from the package boundaryConsumer validation or type checking failsKeep schema objects and related types exported from src/index.ts
The main flow catches a creation errorThe CLI reports cancellation and exits with status 1Treat a non-zero CLI exit as a failed creation attempt

Key files

FileWhy to read it
package.jsonDefines the package identity, published library targets, and executable command mapping.
src/…/index.tsShows the process bridge from the shell to the shared program entrypoint.
src/index.tsDefines the root exports and connects argument resolution to app creation.
src/…/get-args.tsShows where command input becomes a resolved creation request.
src/…/get-args-result.tsDefines the shared contract between input resolution and creation.
src/…/create-app.tsDefines the app-creation initiation point and returned result.
test/root-exports-schemas.test.tsConfirms that the package root exposes the runtime schemas and inferred types used by consumers.