Getting Started

Create a project, learn the layout, and run the CLI

Quick Start

# Create a new project
npx @basicbenframework/create my-app
# Navigate to the project
cd my-app
# Install dependencies
npm install
# Create the database
npm run migrate
# Start the development server
npm run dev

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 dev

Start Vite and the API server with hot reload

npm run build

Build client and server for production

npm run build -- --static

Build the client only, for static hosts

npm run start

Run the production server

npm run test

Run tests with node --test

Scaffolding

npm run make:controller Post

Generate a controller

npm run make:model Post

Generate a model

npm run make:migration create_posts

Generate a migration

npx basicben make:route post

Generate a route file

npx basicben make:middleware auth

Generate middleware

npx basicben make:seed posts

Generate a seeder

Database

npm run migrate

Run pending migrations

npm run migrate:rollback

Roll back the last batch

npm run migrate:fresh

Drop everything and re-run

npm run migrate:status

Show migration status

npx basicben migrate:unlock

Clear a migration lock left by a crashed run

npx basicben seed

Run 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.