Getting Started
Create a project, learn the layout, and run the CLI
Quick Start
What you get is the CMS: posts, pages, categories, tags, media, comments, an admin panel and a headless content API at /api/v1. Not a blank application — a working one you delete the parts of that you do not want. The first account you register becomes the admin.
Apps are TypeScript. Nothing forces you to annotate anything — Vite compiles the app either way — but the types are there when you want them, and the admin panel is written against them. BasicBen requires Node 24 or later.
The command downloads the CMS repository rather than unpacking a copy bundled inside the package, so it is never a stale snapshot. What it gives you is yours, with no link back — which is usually what you want, and means framework fixes reach you through @basicbenframework/core but CMS changes do not. If you would rather track the CMS and merge its fixes, fork it instead of scaffolding: git clone https://github.com/BasicBenFramework/basicben.git my-app.
Project Structure
my-app/ ├── src/ │ ├── client/ # React frontend │ │ ├── components/ # Reusable components │ │ ├── contexts/ # React context providers │ │ ├── layouts/ # Page layouts │ │ └── pages/ # Page components, including admin/ │ ├── routes/ │ │ ├── App.tsx # Client routes │ │ └── api/ # API route files │ ├── controllers/ # Request handlers │ ├── models/ # Database models │ ├── middleware/ # Request middleware │ ├── helpers/ # Shared utilities │ ├── types/ # Shared type definitions │ ├── server/ # Server entry point │ └── main.tsx # Client entry point ├── db/ │ ├── migrations/ # Database migrations │ └── seeds/ # Database seeders ├── mail/ # Email templates ├── public/ # Static assets ├── index.html # HTML shell ├── tsconfig.json # TypeScript config ├── vite.config.ts # Vite config └── basicben.config.js # Framework config
Both halves of the app live under src/routes/. App.tsx defines the routes the browser renders, and everything in api/ defines the routes the server answers. Files in api/ are loaded automatically at startup, so a new file becomes live routes without being registered anywhere.
CLI Commands
A new project ships with npm scripts for the commands you run most. Everything else is available through npx basicben, and npx basicben help lists the full set.
Development
npm run devStart Vite and the API server with hot reload
npm run buildBuild client and server for production
npm run build -- --staticBuild the client only, for static hosts
npm run startRun the production server
npm run testRun tests with node --test
Scaffolding
npm run make:controller PostGenerate a controller
npm run make:model PostGenerate a model
npm run make:migration create_postsGenerate a migration
npx basicben make:route postGenerate a route file
npx basicben make:middleware authGenerate middleware
npx basicben make:seed postsGenerate a seeder
Database
npm run migrateRun pending migrations
npm run migrate:rollbackRoll back the last batch
npm run migrate:freshDrop everything and re-run
npm run migrate:statusShow migration status
npx basicben migrate:unlockClear a migration lock left by a crashed run
npx basicben seedRun database seeders
The generators write TypeScript and refuse to overwrite a file that already exists. Migrations and seeders are .ts too — Node strips the types, so they run with no build step.
Imports
The framework is published as @basicbenframework/core. It is organised into subpaths so the client bundle never pulls in server code.
import { createServer } from '@basicbenframework/core/server'
import { createClientApp } from '@basicbenframework/core/client'
import { db, query } from '@basicbenframework/core/db'
import { validate, rules } from '@basicbenframework/core/validation'
import { signJwt, verifyJwt } from '@basicbenframework/core/auth'
import { can, ROLES } from '@basicbenframework/core/auth/permissions'
import { hooks, HOOKS } from '@basicbenframework/core/hooks'
import { createApiToken } from '@basicbenframework/core/auth/api-tokens'Configuration
basicben.config.js is read at startup. Every key is optional and falls back to a default, so you only set what you want to change.
export default {
port: 3001,
cors: {
origin: '*',
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
credentials: true
},
bodyParser: {
limit: '1mb'
},
static: {
dir: 'public',
spa: true // serve index.html for unmatched client routes
},
db: {
driver: 'sqlite',
url: process.env.DATABASE_URL || './data.db'
}
}Set spa: true before deploying. Without it the production server returns 404 for any client route that is not a real file, which breaks deep links and page refreshes.
The same keys can be passed straight to createServer, which is what the generated src/server/index.ts does; an argument there wins over the file.