Directory Structure
Introduction
A generated Plinth application has a conventional layout, so you always know where a thing lives. All code lives under src/, in lowercase, kebab-case folders: the application, the HTTP entry server.ts, the console entry console.ts, and the views and frontend sources in src/resources/. Static files sit in public/, runtime files in storage/, and tests in tests/.
This page walks through the tree of the default web stack (server-rendered .plinth views with the authentication starter) folder by folder, and notes where the API, Vue, and React stacks differ. It describes what create-plinthjs-app actually generates; see Installation for how to create one.
blog/
├── public/
│ └── robots.txt
├── src/
│ ├── auth/
│ ├── bootstrap/
│ ├── commands/
│ ├── config/
│ ├── controllers/
│ ├── database/
│ ├── middleware/
│ ├── models/
│ ├── providers/
│ ├── resources/
│ │ └── views/
│ ├── routes/
│ ├── support/
│ ├── console.ts
│ └── server.ts
├── storage/
│ ├── app/
│ ├── framework/
│ └── logs/
├── tests/
│ ├── feature/
│ └── unit/
├── .env
├── .env.example
├── .gitignore
├── package.json
└── tsconfig.jsonThe root directory
package.json
The scripts are the commands you will run most:
| Script | What it runs |
|---|---|
npm run dev | tsx watch src/server.ts: the server, restarting when source files change |
npm start | tsx src/server.ts: the server once, without watching |
npm run build | tsup src/server.ts --format esm --target es2022: bundles the entry to dist |
npm run plinth -- <command> | The plinth command line tool (see below) |
npm test | vitest run |
npm run typecheck | tsc --noEmit |
The Vue and React stacks add frontend:dev (vite) and frontend:build (vite build).
The plinth command
The plinth command comes from the @plinthjs/cli package in devDependencies. It finds the project from any folder, runs src/console.ts with tsx, and passes the command along, for example npx plinth migrate. There is no launcher file in the project. See The plinth command and Console.
.env and .env.example
.env holds the settings for this machine, including the generated APP_KEY. It is ignored by git. .env.example documents every key and is committed. See Configuration.
Other files
tsconfig.json enables strict TypeScript with ES modules. .editorconfig and .gitattributes set editor and line-ending defaults. .gitignore excludes node_modules, dist, .env, log files, and the SQLite database. README.md is a short readme for the new project.
public
public holds static files and nothing else, so you can serve or copy the folder as it is.
robots.txt is the only static file the scaffold includes. Plinth's kernel routes requests; it does not serve static files by itself. In the Vue and React stacks a fallback route in src/routes/web.ts serves built assets from public/build, and the public/build and public/hot paths are ignored by git.
src
Everything that is application code lives in src/.
Folder and file names are lowercase and kebab-case, and each folder has one job:
src/controllers
A base controller.ts that all your controllers extend, plus the controllers for each stack: home-controller.ts and dashboard-controller.ts in the web stack, auth/authenticated-session-controller.ts and auth/registered-user-controller.ts for login and registration, and health-controller.ts in the API stack. See Controllers.
src/middleware
The web stack's middleware: authenticate.ts (redirects guests to /login), redirect-if-authenticated.ts (keeps signed-in users away from the login and register pages), and share-current-user.ts (looks up the signed-in user once per request). See Middleware.
src/providers
The service providers. app-service-provider.ts binds the database connection, the logger, and the exception handler. The web stack adds auth-service-provider.ts, which binds the password hasher, the session manager, and the user provider. See Service Providers.
src/auth
Web stack only. database-user-provider.ts looks users up in the users table for the authentication guards. See Authentication.
src/models
user.ts, a typed helper over the query builder for the users table.
src/commands
The console commands: the migration and seed commands, route:list, key:generate, the make:* generators, and inspire, one file per command (for example migrate-command.ts). migrations.ts discovers the migration files.
src/support
Small helpers: container.ts (the app() and db() accessors), http.ts (redirect, back, a login throttle, and forceJson, which the API stack uses to make every error render as JSON), and in the web stack view.ts (the view renderer) and auth.ts (the session guard and currentUser).
src/bootstrap
bootstrap/app.ts creates the Application, merges the config files, and boots the service providers. Both src/server.ts and console.ts call it, so the web server and the console start from the same place. bootstrap/env.ts loads .env into the process environment before any config file is read. bootstrap/providers.ts is the list of service providers: add yours here. bootstrap/router.ts (web stack) builds a router for tools such as route:list.
src/config
One file per area of configuration: app, auth, cache, database, filesystems, hashing, logging, mail, queue, services, and session. See Configuration.
src/resources
src/resources/views holds the .plinth templates. A template at src/resources/views/auth/login.plinth is rendered with the dotted name auth.login. The web stack includes a shared layout and a few pages:
src/resources/views/
├── layouts/app.plinth
├── auth/login.plinth
├── auth/register.plinth
├── dashboard.plinth
└── welcome.plinthSee Views. The Vue and React stacks have no .plinth views. They have src/resources/js (the entry app.ts and App.vue, or app.tsx), src/resources/css, and a src/resources/tsconfig.json for the frontend code; vite.config.ts at the project root points the build at the entry file. See Vite. The API stack has no resources directory.
src/routes
routes/web.ts registers the routes of the web stacks, and routes/api.ts registers the API stack's routes. Each file exports a function that receives the Router. Every stack defines a GET /up health route, covered in Deployment. routes/console.ts registers the console commands on the console kernel; add your own command classes there. See Routing.
src/database
mysql-driver.tsis themysql2-backed driver used whenDB_CONNECTIONismysqlormariadb.migrationscontains the default migrations:create_users_table(which also createspassword_reset_tokensandsessions),create_cache_table(cacheandcache_locks), andcreate_jobs_table(jobs,job_batches, andfailed_jobs). File names start with a timestamp and run in order. See Migrations.seederscontainsdatabase-seeder.ts. In the web stack it creates the demo accounttest@example.com. See Seeding.factoriescontainsuser-factory.ts, a small function that builds user rows for tests and seeders.
src/server.ts
src/server.ts is the HTTP entry point: the file you run to serve the app. It boots the application, builds the router, registers the global middleware, creates an HttpKernel, and starts listening with serve. It also installs graceful shutdown. If you want to add a global middleware, change the port handling, or swap the server, this is the file to edit. The Request Lifecycle explains what it does.
src/console.ts
The console entry point. It boots the application, builds the command kernel from routes/console.ts, runs the command you typed, and closes the database connection so the process can exit.
storage
storage holds files the application writes at runtime. Each directory has a .gitignore that excludes its contents but keeps the directory itself.
storage/appis for files your application stores.storage/frameworkholds framework-generated files:cache,sessions, andviews.storage/logsholds the log file written by the logger.storage/database.sqliteis created the first time you runmigratewith the default SQLite connection.
The directory must be writable by the user that runs the application.
tests
tests/feature and tests/unit contain an example test each, run with Vitest. The feature example boots the application through createApplication() and checks the config; the unit example tests the user factory. See Testing.
Where to go next
To learn how a request travels through src/server.ts, routes/web.ts and a controller, read The Request Lifecycle.