OpenServicePrivate preview

    The Node.js service framework under Chips.gg.

    OpenService splits a backend into small services that call each other as if they were local. Calls and events travel over NATS, and a WebSocket layer gives the browser the same calls plus live state. It runs the roughly 30 services behind Chips.gg.

    It is in private preview. Tell us what you are building and we will get you access.

    How it works

    Small services, plain functions

    Four ideas carry the whole framework.

    A service is a function

    It gets its config, clients for the services it uses, and an emit function, and returns its methods. No classes, no base types to extend.

    Calls look local

    List the services you need under clients and call their methods. Each call crosses the transport and comes back as a promise.

    The transport is config

    The same services run in one process on the in-process transport, or across machines on NATS JetStream, NATS Streaming or Redis Streams. JetStream key-value buckets are handed to services that use them.

    The browser is included

    A WebSocket server with per-connection rate limits, batched messages, an origin allowlist and topic subscriptions, and a browser client that calls actions as promises and keeps a state tree current from server events.

    In code

    Two services, one call

    The chat service keeps the last messages per room and emits an event for each one. The bot lists chat as a client and posts through it.

    Both run in one process here. Point the namespace at a NATS transport and the same files run as separate processes, with nothing in the services changed.

    chat.js
    // chat.js: a service is a function that returns its public methods.
    module.exports = async (config, services, emit) => {
      const rooms = new Map();
    
      return {
        post(room, text) {
          const message = { room, text, at: Date.now() };
          rooms.set(room, [...(rooms.get(room) || []), message].slice(-config.keep));
          emit("message", message);
          return message;
        },
        history(room) {
          return rooms.get(room) || [];
        },
      };
    };
    bot.js
    // bot.js: other services arrive as clients; calls cross the transport.
    module.exports = async (config, { chat }) => {
      return {
        async welcome(room) {
          return chat.post(room, "Welcome in.");
        },
      };
    };
    config.js (excerpt)
    // config.js (excerpt)
    demo: {
      transport: "local", // or a NATS transport: same code, separate processes
      start: ["chat", "bot"],
      chat: { require: "chat", config: { keep: 100 } },
      bot: { require: "bot", clients: ["chat"] },
    },

    Want to build on it?

    Tell us what you are building and how your services talk today. We reply within 1-2 business days.