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 need | Public capability |
|---|---|
| Run the complete command flow | main |
| Create a project from resolved choices | createApp, CreateAppArgs, and CreateAppResult |
| Resolve command input | getArgs and GetArgsResult |
| Inspect template and version data | getAppInfo, fetchTemplateData, listTemplates, listTemplateIds, and listVersions |
| Use template and setup contracts | Template types, catalog schemas, and init-script schemas |
| Validate input or detect a package manager | validateProjectName and detectInvokedPackageManager |
| Build completion guidance | finalNote 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:
- The executable supplies
process.argvtomain. getArgsresolves built-in options and the positional project name.- Template-defined boolean flags remain template choices rather than built-in options.
- Prompts collect choices that the command did not supply.
- The resolved
GetArgsResultbecomes the input tocreateApp. mainpresents 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.
| Journey | Entry | Input shape | Output or effect |
|---|---|---|---|
| Interactive or scripted CLI use | create-solana-dapp command | Process arguments with prompts for missing choices | Generated project, status messages, and completion guidance |
| Full programmatic command flow | main(argv) | Argument vector | The complete command flow and its user-facing behavior |
| Resolved programmatic creation | createApp(args) | Typed creation request | Project setup and returned instructions |
| Template or input inspection | Root utility and schema exports | Typed arguments or data to validate | Template 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
binmapping aligned with the built executable. Keep the rootexports,main,module, andtypesentries aligned with the built library. - Preserve the distinction between raw CLI arguments handled by
getArgsand the resolvedCreateAppArgscontract consumed bycreateApp. - When adding a built-in CLI option, ensure it is not captured as a template-defined flag during argument handoff.
- When changing
GetArgsResult, review bothmainand 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
| Trigger | Consequence | Guard |
|---|---|---|
| The executable or package metadata points to a missing built entrypoint | Package invocation or consumer import cannot start | Keep the bin and root export targets aligned with build output |
A caller passes incomplete or unresolved data to createApp | Creation can fail after it starts because its contract is not satisfied | Resolve input with getArgs or construct the full CreateAppArgs contract |
| More than one explicit package manager flag is supplied | Argument resolution stops before project creation | Select one package manager source |
| CLI parsing receives an unsupported option shape | The command rejects the invocation before template selection | Use built-in options or supported boolean template flags |
| A root consumer uses a schema or type that is not exported from the package boundary | Consumer validation or type checking fails | Keep schema objects and related types exported from src/index.ts |
| The main flow catches a creation error | The CLI reports cancellation and exits with status 1 | Treat a non-zero CLI exit as a failed creation attempt |
Key files
| File | Why to read it |
|---|---|
| package.json | Defines the package identity, published library targets, and executable command mapping. |
| src/…/index.ts | Shows the process bridge from the shell to the shared program entrypoint. |
| src/index.ts | Defines the root exports and connects argument resolution to app creation. |
| src/…/get-args.ts | Shows where command input becomes a resolved creation request. |
| src/…/get-args-result.ts | Defines the shared contract between input resolution and creation. |
| src/…/create-app.ts | Defines the app-creation initiation point and returned result. |
| test/root-exports-schemas.test.ts | Confirms that the package root exposes the runtime schemas and inferred types used by consumers. |