Skip to content

create-plinthjs-app ​

Scaffold a new Plinth application with the npm create convention.

Plinth is a faithful, dependency-free TypeScript recreation of a batteries-included full-stack web framework. This is its project scaffolder: one command spins up a ready-to-run app wired to the @plinthjs/* packages.

Usage ​

Use the conventional npm create convention (no global install needed):

bash
npm  create plinthjs-app@latest blog     # npm
pnpm create plinthjs-app blog            # pnpm
yarn create plinthjs-app blog            # yarn
npx  create-plinthjs-app blog            # equivalent, explicit

cd blog
npm install
npx plinth migrate               # create the SQLite schema (storage/database.sqlite)
npm run dev                           # boots an HTTP server on node:http (default :3000)

Run it without a name and it interviews you: the project name, starter, frontend, database, git, dependency install, package manager and whether to run the migrations. Use the arrow keys and Enter; y/n for yes or no; Ctrl+C cancels before anything is written. Any flag below answers its question ahead of time. With the plinth command-line tool the same thing is plinth new.

Starter stacks ​

You're asked to pick a stack (or pass a flag):

StackFlagIncludes
web--webRoutes + controllers + a frontend (your pick of .plinth / Vue / React)
api--apiLean JSON controllers + request validation (@plinthjs/validation), no views

Web frontend ​

For the web stack you also pick a frontend (or pass a flag):

FrontendFlagIncludes
plinth--plinthServer-rendered .plinth views + a full auth starter (the default; see below)
vue--vueA Vite-bundled Vue SPA wired through @plinthjs/vite (+ a /api/message endpoint)
react--reactA Vite-bundled React SPA wired through @plinthjs/vite (+ a /api/message endpoint)

The Vue/React stacks serve an HTML shell carrying the @plinthjs/vite tags and an empty #app; the SPA boots client-side and calls a small JSON route to prove the round-trip. @plinthjs/vite switches between the Vite dev server (HMR) and the built manifest automatically. The build is configured by @plinthjs/vite-plugin - Plinth's own Vite build plugin (input entries, the dev hot file, the build manifest, and full-reload refresh) - so a Plinth app pulls in no extra npm packages. A frontend flag implies --web, so create-plinthjs-app blog --react is all you need.

The plinth auth starter (default) ​

The default plinth stack is more than a hello-world - it ships a working app, the way a typical starter kit does, but baked in:

  • A beautiful landing page - a gradient hero + feature cards (src/resources/views/welcome.plinth), with a shared layout (src/resources/views/layouts/app.plinth) whose nav reflects the auth state.
  • Complete authentication - register, login, and logout, built on @plinthjs/auth's SessionGuard, @plinthjs/session (file-backed sessions), and scrypt password hashing via @plinthjs/encryption. Forms are CSRF-protected and validated with @plinthjs/validation, with errors and old input flashed back on failure.
  • A protected dashboard - guarded by an authenticate middleware (guests are redirected to /login); login/register are guarded by a guest middleware.

It's wired through an AuthServiceProvider (binding the hasher, session manager, and a database-backed DatabaseUserProvider), a ShareCurrentUser global middleware, and an app() helper - all type-checked, lint-clean, and ready to extend.

Options ​

FlagDescription
<name>Project directory/name (positional; prompted if omitted)
--stack=<web|api>Choose the starter stack (or use --web / --api)
--frontend=<plinth|vue|react>Web frontend (or use --plinth / --vue / --react)
--database=<sqlite|mysql|mariadb>Database (or --sqlite / --mysql / --mariadb)
--pm=<npm|pnpm|yarn|bun>Package manager to install with (default: the one running this)
--git, --no-gitInitialise (or skip) a git repository
--install, --no-installInstall (or skip) dependencies
--migrate, --no-migrateRun (or skip) the migrations and demo account seeder after installing
--dry-runPrint the files that would be created, without writing anything
--linkUse workspace:* for @plinthjs/* deps (for in-monorepo dogfooding)
-h, --helpShow help
-v, --versionShow the version

The package manager defaults to the one that started the scaffolder (npm, pnpm, yarn or bun), and you are asked to choose when more than one is installed. When it is not attached to a terminal (a script, CI) it never asks: it uses these defaults and does not run the migrations unless you pass --migrate.

What it generates ​

Every app keeps all of its code under src/, with static files, runtime data and tests at the root:

blog/
├── src/
│   ├── controllers/             # base controller + home / health controllers
│   ├── middleware/              # web stack: authenticate, redirect-if-authenticated, share-current-user
│   ├── providers/               # app and auth service providers
│   ├── auth/                    # web stack: the database user provider
│   ├── models/user.ts           # typed query-builder helper
│   ├── commands/                # migrate, db:seed, route:list, make:*, ... (one file each)
│   ├── support/                 # container, http, view, auth helpers
│   ├── bootstrap/{env.ts, app.ts, providers.ts}   # loads .env, then boots the app
│   ├── config/                      # app, auth, cache, database, filesystems, hashing,
│   │                                # logging, mail, queue, services, session
│   ├── console.ts                   # console entry (run by the plinth CLI)
│   ├── server.ts                    # HTTP entry
│   ├── resources/                   # views (plinth) or js + css (vue/react)
│   ├── database/
│   │   ├── migrations/              # the default trio (see below)
│   │   ├── seeders/database-seeder.ts
│   │   ├── factories/user-factory.ts
│   │   └── mysql-driver.ts          # mysql2-backed driver (used when DB_CONNECTION=mysql)
│   └── routes/                      # web.ts | api.ts + console.ts (each wires GET /up)
├── public/robots.txt                # static files only
├── storage/{app, framework, logs}/  # each runtime dir carries a framework-style .gitignore
├── tests/{feature, unit}/
└── package.json  tsconfig.json  .editorconfig  .env.example  .gitattributes  .gitignore

Like most scaffolders, every app ships the three default migrations:

MigrationTables
0001_01_01_000000_create_users_tableusers, password_reset_tokens, sessions
0001_01_01_000001_create_cache_tablecache, cache_locks
0001_01_01_000002_create_jobs_tablejobs, job_batches, failed_jobs

…plus a GET /up health route on every stack - HTML OK for the web stacks, { "status": "ok" } JSON for the api stack - and the default .env.example key set (APP_MAINTENANCE_DRIVER, LOG_STACK, SESSION_ENCRYPT/SESSION_PATH/SESSION_DOMAIN, BROADCAST_CONNECTION, FILESYSTEM_DISK, QUEUE_CONNECTION, CACHE_STORE, REDIS_*, MAIL_*). config/app.ts carries the matching cipher, previousKeys (from APP_PREVIOUS_KEYS), and maintenance.driver keys.

  • plinth (default): the auth starter - a landing page, a shared layout, register/login/dashboard views under src/resources/views/, plus the controllers, middleware, and providers that power them.
  • vue / react: a Vite SPA (src/resources/js, vite.config.ts) served through @plinthjs/vite - run npm run frontend:dev alongside npm run dev, then npm run frontend:build for production.
  • api: a JSON HealthController with @plinthjs/validation; no src/resources/.

It also ships the full default config tree (config/app.ts, auth, cache, database, filesystems, hashing, logging, mail, queue, services, session), loaded from .env via bootstrap/env.ts and merged into the container's config.

Database (SQLite by default, MySQL ready) ​

The default database is SQLite at storage/database.sqlite (Node's built-in node:sqlite - no native deps), so a fresh app runs with zero setup. MySQL/MariaDB is configured and ready to go:

bash
npm install mysql2          # the driver lives in your app (the framework stays dependency-free)
# then in .env:
#   DB_CONNECTION=mysql
#   DB_HOST=127.0.0.1
#   DB_PORT=3306
#   DB_DATABASE=your_db
#   DB_USERNAME=root
#   DB_PASSWORD=secret
npx plinth migrate     # builds the schema with MySQL's SQL grammar

AppServiceProvider reads config/database.ts and builds the connection for the selected driver: SQLite uses the built-in driver, while MySQL/MariaDB uses the app's src/database/mysql-driver.ts (backed by mysql2). The MySQL SQL dialect - backtick quoting, AUTO_INCREMENT, real column types, ON DUPLICATE KEY UPDATE - is supplied by @plinthjs/database, so migrations and queries Just Work on either engine.

Plinth ​

Every app ships a console, run with the plinth command (@plinthjs/cli). npx plinth list shows everything; the commands follow familiar full-stack framework conventions:

CommandWhat it does
migrateRun pending migrations
migrate:rollback [--step=N]Reverse the last migration batch(es)
migrate:statusShow which migrations have run (as a table)
migrate:refresh [--seed]Roll everything back, re-migrate, optionally seed
db:seed [--class=Name]Run the DatabaseSeeder (or a named seeder)
route:listList registered routes (method, URI, name, action)
key:generateSet a fresh APP_KEY in .env
make:controller {name} [--resource]Generate a controller
make:model {name}Generate a typed query-builder model helper
make:migration {name} [--create=table]Generate a timestamped migration
make:seeder {name}Generate a seeder
make:middleware {name}Generate an HTTP middleware
inspireThe closure-command example
bash
npx plinth make:controller PostController --resource
npx plinth make:migration create_posts_table --create=posts
npx plinth migrate
npx plinth route:list

The commands live in src/commands/ and are registered in src/routes/console.ts - add your own command classes there. Database-aware commands resolve services through the app() helper (src/support/container.ts).

Requirements ​

  • Node.js 22+ (the framework builds on modern Node built-ins; @plinthjs/database uses node:sqlite).

A note on installing the generated app ​

The generated package.json pins @plinthjs/* at ^0.1.0, so a plain npm install resolves them once those packages are published to npm. Until then:

  • Inside the Plinth monorepo, scaffold with --link to get workspace:* ranges that resolve through the workspace, or
  • Link the local build into the project's node_modules/@plinthjs/* (the framework packages ship a built dist/) and run with tsx.

npm start runs the TypeScript sources through tsx, which the generated app lists under dependencies (not devDependencies) so a production-only install can still start it. npm run build bundles src/server.ts with tsup if you prefer to run the built output with node.

After publishing (pnpm release), npm install && npm run dev just works, anywhere.

How it's built ​

create-plinthjs-app is a small Node CLI that dogfoods Plinth's own @plinthjs/console prompt suite. The starter stacks (and the web frontends) are embedded as data and written through a pure, fs-seam-injected scaffold() function, so the generator is fully unit-tested without touching disk.

License ​

MIT

Released under the MIT License.