Skip to content

jaksa76/matte.js

Repository files navigation

matte.js

A lightweight framework for rapidly building full-stack applications with automatic API generation, database management, and type-safe entity definitions.

Features

  • 🎯 Array-based entity schemas with guaranteed field ordering
  • 🔧 Shortcut helpers for common field types
  • 🔗 Chainable API for fluent field configuration
  • 🚀 Automatic REST API generation from entity definitions
  • 💾 Built-in database adapter (SQLite)
  • 🔐 Multi-tenant ownership support
  • Type-safe with full TypeScript support

Quick Start

To install dependencies:

bun install

Define Entities

import { ownedEntity, field, string, richtext, date, number, file, t } from './framework';

const Task = ownedEntity("Task", [
  string("title").required(),
  richtext("description"),
  field("status", t.enum(["open", "in_progress", "done"]).default("open")),
  field("priority", t.enum(["low", "medium", "high", "urgent"]).default("medium")),
  date("dueDate"),
  number("estimate").min(0),
  file("attachments").array(),
]);

Field Shortcuts

  • string(name) - String field
  • number(name) - Number field
  • date(name) - Date field
  • richtext(name) - Rich text field
  • file(name) - File field
  • boolean(name) - Boolean field
  • field(name, type) - For complex types like enums

All shortcuts support method chaining:

string("email").required().maxLength(100)
number("price").min(0).default(0)
file("avatar").maxSize(5 * 1024 * 1024)

Run the Framework

import { Matte } from './framework';

const app = new Matte({
  dbPath: './data.db',
  port: 3000,
});

// Register entities
app.register(Task);

// Start the framework (initialization happens automatically)
await app.start();

This automatically:

  • Initializes the database
  • Creates database tables
  • Generates REST API endpoints
  • Serves a UI at http://localhost:3000

API Endpoints

For each entity, the following endpoints are automatically generated:

  • GET /api/{entities} - List all records
  • GET /api/{entities}/:id - Get single record
  • POST /api/{entities} - Create record
  • PUT /api/{entities}/:id - Update record
  • DELETE /api/{entities}/:id - Delete record

Examples

See the src/examples/ directory:

  • simple-entity.ts - Basic entity definition
  • customizable-fields.ts - Advanced field customization
  • field-api-demo.ts - Comprehensive API demo
  • verify-ordering.ts - Field ordering demonstration

To run an example:

bun run ./src/examples/simple-entity.ts

Testing

bun test

All 107 tests pass ✅

Documentation

License

MIT


This project was created using bun init in bun v1.3.3. Bun is a fast all-in-one JavaScript runtime.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published