All Projects → remult → remult

remult / remult

Licence: MIT license
A CRUD framework for full stack TypeScript

Programming Languages

typescript
32286 projects
HTML
75241 projects

Projects that are alternatives of or similar to remult

helppo
Instant admin UI for your database
Stars: ✭ 14 (-99.06%)
Mutual labels:  crud, express-middleware
Bisonapp
A Full Stack Jamstack in-a-box brought to you by Echobind
Stars: ✭ 322 (-78.36%)
Mutual labels:  fullstack, jamstack
crisp-react
React boilerplate written in TypeScript with a variety of Jamstack and full stack deployments. Comes with SSR and without need to learn a framework. Helps to split a monolithic React app into multiple SPAs and avoid vendor lock-in.
Stars: ✭ 147 (-90.12%)
Mutual labels:  fullstack, jamstack
Stator
Stator, your go-to template for the perfect stack. 😍🙏
Stars: ✭ 217 (-85.42%)
Mutual labels:  crud, fullstack
redwood
The App Framework for Startups
Stars: ✭ 15,079 (+913.37%)
Mutual labels:  jamstack
express-json-validator-middleware
Express middleware for validating requests against JSON schema
Stars: ✭ 148 (-90.05%)
Mutual labels:  express-middleware
therack
Laravel 7 e-commerce website
Stars: ✭ 77 (-94.83%)
Mutual labels:  crud
Processor
Ontology-driven Linked Data processor and server for SPARQL backends. Apache License.
Stars: ✭ 54 (-96.37%)
Mutual labels:  crud
api
_api is an autogenerated CRUD API built on LowDB and ExpressJS.
Stars: ✭ 73 (-95.09%)
Mutual labels:  crud
dcdesignweek.org
✨ - 2021 DC Design Week Website
Stars: ✭ 13 (-99.13%)
Mutual labels:  jamstack
payload
A javascript single page application (SPA) driver for REST API payload management.
Stars: ✭ 16 (-98.92%)
Mutual labels:  jamstack
sql-repository
[PHP 7] SQL Repository implementation
Stars: ✭ 37 (-97.51%)
Mutual labels:  crud
fullstackDevelopment
Material & Projects related to full stack development
Stars: ✭ 90 (-93.95%)
Mutual labels:  fullstack
vscode-azurestaticwebapps
Azure Static Web Apps extension for VS Code
Stars: ✭ 63 (-95.77%)
Mutual labels:  jamstack
logrocket deno api
A functional CRUD-like API with Deno and Postgres
Stars: ✭ 23 (-98.45%)
Mutual labels:  crud
cookbook
VueJS + NodeJS Evergreen Cookbook
Stars: ✭ 440 (-70.43%)
Mutual labels:  crud
crudcast
Create and deploy a RESTful API with a few lines of YAML
Stars: ✭ 32 (-97.85%)
Mutual labels:  crud
express-error-slack
Express error handling middleware for reporting error to Slack
Stars: ✭ 14 (-99.06%)
Mutual labels:  express-middleware
vacme-zurich-parser
Helps to find available slots on zh.vacme.ch corona vaccination service
Stars: ✭ 12 (-99.19%)
Mutual labels:  fullstack
components
Example Components (Built with Tonic)
Stars: ✭ 62 (-95.83%)
Mutual labels:  jamstack

Remult

A CRUD framework for full-stack TypeScript

CircleCI GitHub license npm version npm downloads Join Discord Twitter URL



Video thumbnail

Watch code demo on YouTube here

What is Remult?

Remult is a full-stack CRUD framework that uses your TypeScript entities as a single source of truth for your API, frontend type-safe API client and backend ORM.

  • Zero-boilerplate CRUD API routes with paging, sorting, and filtering for Express / Fastify / Next.js / NestJS / Koa / others...
  • 👌 Fullstack type-safety for API queries, mutations and RPC, without code generation
  • Input validation, defined once, runs both on the backend and on the frontend for best UX
  • 🔒 Fine-grained code-based API authorization
  • 😌 Incrementally adoptable
  • 🚀 Production ready

Status

Remult is production-ready and, in fact, used in production apps since 2018. However, we’re keeping the major version at zero so we can use community feedback to finalize the v1 API.

Motivation

Full-stack web development is (still) too complicated. Simple CRUD, a common requirement of any business application, should be simple to build, maintain, and extend when the need arises.

Remult abstracts away repetitive, boilerplate, error-prone, and poorly designed code on the one hand, and enables total flexibility and control on the other. Remult helps building fullstack apps using only TypeScript code you can easily follow and safely refactor, and fits nicely into any existing or new project by being minimalistic and completely unopinionated regarding the developer’s choice of other frameworks and tools.

Other frameworks tend to fall into either too much abstraction (no-code, low-code, BaaS) or partial abstraction (MVC frameworks, GraphQL, ORMs, API generators, code generators), and tend to be opinionated regarding the development tool-chain, deployment environment, configuration/conventions or DSL. Remult attempts to strike a better balance.

Installation

The remult package is one and the same for both the frontend bundle and the backend. Install it once for a monolith project or per-repo in a monorepo.

npm i remult

Usage

Define model classes

// shared/product.ts

import { Entity, Fields } from "remult";

@Entity("products", {
  allowApiCrud: true,
})
export class Product {
  @Fields.string()
  name = "";

  @Fields.number()
  unitPrice = 0;
}

Setup API backend using an Express middleware

// backend/index.ts

import express from "express";
import { remultExpress } from "remult/remult-express";
import { Product } from "../shared/product";

const port = 3001;
const app = express();

app.use(remultExpress({
  entities: [Product],
}));

app.listen(port, () => {
  console.log(`Example API listening at http://localhost:${port}`);
});

🚀 API Ready

> curl http://localhost:3001/api/products

[{"name":"Tofu","unitPrice":5}]

Find and manipulate data in type-safe frontend code

// frontend/code.ts

import { remult } from "remult";
import { Product } from "../shared/product";

async function increasePriceOfTofu(priceIncrease: number) {
  const productsRepo = remult.repo(Product);

  const product = await productsRepo.findFirst({ name: "Tofu" }); // filter is passed through API request all the way to the db
  product.unitPrice += priceIncrease;
  productsRepo.save(product); // mutation request updates the db with no boilerplate code
}

...exactly the same way as in backend code

@BackendMethod({ allowed: Allow.authenticated })
static async increasePriceOfTofu(priceIncrease: number) {
  const productsRepo = remult.repo(Product);

  const product = await productsRepo.findFirst({ name: 'Tofu' }); // use Remult in the backend as an ORM
  product.unitPrice += priceIncrease;
  productsRepo.save(product);
}

☑️ Data validation and constraints - defined once

import { Entity, Fields, Validators } from "remult";

@Entity("products", {
  allowApiCrud: true,
})
export class Product {
  @Fields.string({
    validate: Validators.required,
  })
  name = "";

  @Fields.string<Product>({
    validate: (product) => {
      if (product.description.trim().length < 50) {
        throw "too short";
      }
    },
  })
  description = "";

  @Fields.number({
    validate: (_, field) => {
      if (field.value < 0) {
        field.error = "must not be less than 0"; // or: throw "must not be less than 0";
      }
    },
  })
  unitPrice = 0;
}

Enforced in frontend:

const product = productsRepo.create();

try {
  await productsRepo.save(product);
} catch (e: any) {
  console.error(e.message); // Browser console will display - "Name: required"
}

Enforced in backend:

> curl http://localhost:3001/api/products -H "Content-Type: application/json" -d "{""unitPrice"":-1}"

{"modelState":{"unitPrice":"must not be less than 0","name":"required"},"message":"Name: required"}

🔒 Secure the API with fine-grained authorization

@Entity<Article>("Articles", {
  allowApiRead: true,
  allowApiInsert: (remult) => remult.authenticated(),
  allowApiUpdate: (remult, article) => article.author.id == remult.user.id,
})
export class Article {
  @Fields.string({ allowApiUpdate: false })
  slug = "";

  @Field(() => Profile, { allowApiUpdate: false })
  author!: Profile;

  @Fields.string()
  content = "";
}

What about complex CRUD?

While simple CRUD shouldn’t require any backend coding, using Remult means having the ability to handle any complex scenario by controlling the backend in numerous ways:

  • Backend computed (read-only) fields - from simple expressions to complex data lookups or even direct db access (SQL)
  • Custom side-effects with entity lifecycle hooks (before/after saving/deleting)
  • Backend only updatable fields (e.g. “last updated at”)
  • Many-to-one relations with lazy/eager loading
  • Roll-your-own type-safe endpoints with Backend Methods
  • Roll-your-own low-level endpoints (Express, Fastify, koa, others…)

Getting started

The best way to learn Remult is by following a tutorial of a simple Todo web app with a Node.js Express backend.

Documentation

The documentation covers the main features of Remult. However, it is still a work-in-progress.

Example Apps

Contributing

Contributions are welcome. See CONTRIBUTING.md.

  • 💬 Any feedback or suggestions? Start a discussion.
  • 💪 Want to help out? Look for "help wanted" labeled issues.
  • Give this repo a star.

License

Remult is MIT Licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].