What is Teenybase?

Teenybase is a backend framework. You define your entire backend in a single TypeScript file (teenybase.ts) and deploy it with one command. Teenybase reads that file and generates the REST API, database migrations, auth endpoints, security rules, OpenAPI docs, and an admin panel.

teenybase.ts

Your entire backend is defined in teenybase.ts. Tables, fields, auth, access rules, triggers. This example teenybase.ts sets up a users table with authentication and row-level security:

typescript
import { DatabaseSettings, TableAuthExtensionData,
         TableRulesExtensionData } from 'teenybase'
import { baseFields, authFields,                        // ① Pre-built field sets
         createdTrigger, updatedTrigger } from 'teenybase/scaffolds/fields'

export default {
    appUrl: 'http://localhost:8787',                     // ② Used for OAuth redirects and email links
    jwtSecret: '$JWT_SECRET',                            // ③ Secret from .dev.vars ($-prefixed = env var)
    tables: [{
        name: 'users',                                   // ④ Table name → /api/v1/table/users/
        autoSetUid: true,                                // ⑤ Auto-generate unique ID on insert
        fields: [
            ...baseFields,                               // ⑥ id + created + updated
            ...authFields,                               // ⑦ username, email, password, name, avatar, role, etc.
        ],
        triggers: [createdTrigger, updatedTrigger],      // ⑧ Auto-manage created/updated timestamps
        extensions: [
            { name: 'auth',                              // ⑨ Enables sign-up, login, password reset, OAuth
              jwtSecret: '$JWT_SECRET_USERS',
              jwtTokenDuration: 3600,
              maxTokenRefresh: 5,
            } as TableAuthExtensionData,
            { name: 'rules',                             // ⑩ Row-level security
              listRule: 'auth.uid == id',                 //    Only see your own record
              viewRule: 'auth.uid == id',
              createRule: 'true',                         //    Needed for sign-up
              updateRule: 'auth.uid == id',
              deleteRule: 'auth.uid == id',
            } as TableRulesExtensionData,
        ],
    }],
} satisfies DatabaseSettings                             // ⑪ Full IDE autocomplete and type checking

The above produces a users table with:

  • sign-up
  • login
  • JWT tokens
  • password reset
  • row-level security
  • auto-migrations
  • OpenAPI docs at /api/v1/doc/ui
  • admin panel at /api/v1/pocket/

How it works

teenybase.ts is the source of truth. When you run teeny deploy, the CLI diffs your config against the current database schema, generates SQL migrations, and applies them.

Locally:

bash
teeny deploy --local    # generate migrations + apply to local DB
teeny dev               # start dev server at localhost:8787
bash
npx teeny deploy --local    # generate migrations + apply to local DB
npx teeny dev               # start dev server at localhost:8787

To production:

bash
teeny deploy --remote   # generate migrations + deploy to production
bash
npx teeny deploy --remote   # generate migrations + deploy to production

What's included

FeatureDescription
REST APICRUD endpoints for every table
AuthEmail/password, JWT, OAuth (Google, GitHub, Discord, LinkedIn)
Row-level securityRules like auth.uid == owner_id, compiled to SQL WHERE clauses
Auto-migrationsNo migration files to write
ActionsServer-side logic with typed params, callable via API
Full-text searchSQLite FTS5
File uploadsR2, S3, or Backblaze
OpenAPI docsAuto-generated 3.1.0 spec + Swagger UI
Admin panelBrowse tables, edit records, role-based access

Deployment

Teenybase runs on SQLite. Three deployment options:

Teenybase Cloud. Managed hosting. Free tier included.

bash
teeny register          # one-time, free
teeny deploy --remote   # deployed
bash
npx teeny register          # one-time, free
npx teeny deploy --remote   # deployed

Self-hosted on Cloudflare. Deploy to your own Cloudflare account with the same teeny deploy command.

Custom stack. Pluggable adapters for compute, database, and storage:

LayerOptions
ComputeCloudflare Workers, Node.js
DatabaseCloudflare D1, Turso, local SQLite
StorageCloudflare R2, AWS S3, Backblaze B2

The default stack is Workers + D1 + R2. It deploys with one command and runs on Cloudflare's edge network.

Next steps