Skip to content

Horizon is a realtime, open-source backend for JavaScript apps.

License

Notifications You must be signed in to change notification settings

jonathan-casarrubias/horizon

 
 

Repository files navigation

What is Horizon?

Horizon is an open-source developer platform for building sophisticated realtime apps. It provides a complete backend that makes it dramatically simpler to build, deploy, manage, and scale engaging JavaScript web and mobile apps. Horizon is extensible, integrates with the Node.js stack, and allows building modern, arbitrarily complex applications.

Horizon is built on top of RethinkDB and consists of four components:

  • Horizon server -- a middleware server that connects to/is built on top of RethinkDB, and exposes a simple API/protocol to front-end applications.
  • Horizon client library -- a JavaScript client library that wraps Horizon server's protocol in a convenient API for front-end developers.
  • Horizon CLI - hz -- a command line tool aiding in scaffolding, development, and deployment
  • GraphQL support -- the server will have a GraphQL adapter so anyone can get started building React/Relay apps without writing any backend code at the beginning. This will not ship in v1, but we'll follow up with a GraphQL adapter quickly after launch.

The first version of Horizon will expose the following services to developers:

  • Subscribe -- a streaming API for building realtime apps directly from the browser without writing any backend code.
  • Auth -- an authentication API that connects to common auth providers (e.g. Facebook, Google, GitHub).
  • Identity -- an API for listing and manipulating user accounts.
  • Permissions -- a security model that allows the developer to protect data from unauthorized access.

Upcoming versions of Horizon will likely expose the following additional services:

  • Session management -- manage browser session and session information.
  • Geolocation -- an API that makes it very easy to build location-aware apps.
  • Presence -- an API for detecting presence information for a given user and sharing it with others.
  • Plugins -- a system for extending Horizon with user-defined services in a consistent, discoverable way.
  • Backend -- an API/protocol to integrate custom backend code with Horizon server/client-libraries.

Why Horizon?

While technologies like RethinkDB and WebSocket make it possible to build engaging realtime apps, empirically there is still too much friction for most developers. Building realtime apps now requires understanding and manually orchestrating multiple systems across the software stack, understanding distributed stream processing, and learning how to deploy and scale realtime systems. The learning curve is quite steep, and most of the initial work involves boilerplate code that is far removed from the primary task of building a realtime app.

Horizon sets out to solve this problem. Developers can start building apps using their favorite front-end framework using Horizon's APIs without having to write any backend code.

Since Horizon stores data in RethinkDB, once the app gets sufficiently complex to need custom business logic on the backend, developers can incrementally add backend code at any time in the development cycle of their app.

Get Involved

We'd love for you to help us build Horizon. If you'd like to be a contributor, check out our Contributing guide.

Also, to stay up-to-date on all Horizon related news and the community you should definitely join us on Slack, follow us on Twitter, and join our Horizon mailing list at Horizon.io.

FAQ

How do you start Horizon?

This first step is to install the Horizon command line tool.

$ npm install -g horizon

You can then create the boilerplate with hz init and then launch Horizon Server and an instance of RethinkDB with hz serve --dev. RethinkDB needs to be installed and accessible from the Path.

$ hz init myapp
$ hz serve myapp --dev
# localhost:8181 has a demo page on it
# Horizon client connections can be made to ws://localhost:8181/horizon
# The horizon client library is served from localhost:8181/horizon/horizon.js

Check out the Getting Started guide for a complete walkthrough.

What does the code look like?

Here is currently what you'd write on the front-end for a simple todo list application:

// Connect to horizon
const horizon = Horizon();
const todoCollection = horizon('todo_items');

const todoApp = document.querySelector('#app')

// Function called when a user adds a todo item in the UI
todoCollection.watch().subscribe( todos => {
  const todoHTML = todos.map(todo =>
    `<div class="todo" id="${todo.id}">
       <input type="checkbox" ${todo.done ? 'checked' : ''}>
       ${todo.text} -- ${todo.date}
     </div>`);
  todoApp.innerHTML = todoHTML.join('');
});

Want to see more? Check out our README for the Horizon client library, we have an initial set of docs as well as a expanded getting started guide to get you started with using Horizon.

How do I get it?

You have two options:

  1. npm install -g horizon (we try to publish weekly)
  2. Move into the /test folder here and run ./setupDev.sh which will install it on your system using this repo.

Refer to the the CLI README for the most up-to-date public install instructions.

Where do I start?

Check out our Getting Started guide. If you have more questions, come join us on Slack in #horizon or feel free to tweet us at @horizonjs.

How is Horizon different from Firebase?

There are a few major differences:

  • Horizon is open-source. You can run it on your laptop, deploy it to the cloud, or deploy it to any infrastructure you want.
  • Horizon will allow you to build complex enterprise apps, not just basic applications with limited functionality. Since Horizon stores data in RethinkDB, once your app grows beyond the basic Horizon API, you can start adding backend code of arbitrary complexity that has complete access to a fully-featured database.
  • Since Horizon is built on RethinkDB, we'll be able to expose services that are much more sophisticated than simple document sync (e.g. realtime analytics, streams on joined tables, etc.)

How is Horizon different from Meteor?

Horizon has philosophical and technical differences with Meteor that will result in vastly different developer experiences.

Horizon is a small layer on top of RethinkDB with a narrow, purpose-built API designed to make it very easy to get started building realtime apps without backend code. Horizon isn't prescriptive -- you can use any front-end framework without any magic/customizations, and once your app outgrows the Horizon API you can use any backend technology (e.g. Node.js, Python, Ruby) and any backend framework (e.g. Rails, Express, Koa, etc.)

By contrast, Meteor is a much more prescriptive framework. Horizon is a reasonably small component that has a very clean separation with the database and the front-end, while Meteor is a much more monolithic experience.

Another major difference is architectural -- Meteor uses a LiveQuery component built by tailing MongoDB's oplog. This approach is fundamentally limited -- it's impossible to do many operations efficiently, and even the basic functionality is extremely difficult to scale.

Horizon is built on RethinkDB, so the LiveQuery functionality is in the database. This allows for much more sophisticated streaming operations, and scalability is dramatically simpler because the database has all the necessary information to allow for a scalable feeds implementation.

How will Horizon be licensed?

The Horizon server, client and cli are available under the MIT license

About

Horizon is a realtime, open-source backend for JavaScript apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.7%
  • Other 0.3%