High-level I/O for web applications.

Fortune is a high-level I/O library for web applications. It provides an implementation of entity-relationship modelling, a data storage adapter and serialization interface, and hooks for application-specific logic. These parts working together can be used to power real-time (WebSocket) and hypermedia applications (RMM Level 3), including web pages and HTTP APIs.

View the website for documentation. Get it from npm:

$ npm install fortune --save

Let's model an API that models Twitter's basic functionality:

// store.js 
const fortune = require('fortune')
module.exports = fortune.create()
.defineType('user', {
  name: { type: String },
  // Following and followers are inversely related (many-to-many). 
  following: { link: 'user', inverse: 'followers', isArray: true },
  followers: { link: 'user', inverse: 'following', isArray: true },
  // Many-to-one relationship of user posts to post author. 
  posts: { link: 'post', inverse: 'author', isArray: true }
.defineType('post', {
  message: { type: String },
  // One-to-many relationship of post author to user posts. 
  author: { link: 'user', inverse: 'posts' }

Then lets add a HTTP server:

// server.js 
const http = require('http')
const fortune = require('fortune')
const store = require('./store')
// The `` helper function returns a listener function which 
// does content negotiation, and maps the internal response to a HTTP response. 
const server = http.createServer(
store.connect().then(() => server.listen(1337))

This yields an ad hoc JSON-over-HTTP API. There are serializers for Micro API (JSON-LD) and JSON API.

By default, the data is persisted in memory. There are adapters for databases such as MongoDB, Postgres, and NeDB.

See the plugins page for more details.

This software is licensed under the MIT license.