Git Product home page Git Product logo

hobby.trailblazer_architecture's Introduction

This project could help in figuring out best practices for architecting an API with Trailblazer and Hobby. Please feel free to open an issue if you would like to discuss anything related.

To install the dependencies: bundle. To start all the services: bundle exec foreman start.

Services

Entry points for services are defined in Procfile:

  • db:
    • sessions(6379)
    • capabilities(6380)
    • store(6381)
  • api:
    • clients(8080)
    • projects(8081)

sessions

A Redis server which maps an active session(token) to a client(client_id, a Redis String).

capabilities

A Redis server which maps a client(client_id) to its capabilities(a Redis Set) inside of a namespace("Clients" or "Projects"). It determines what a client can call inside of this namespace.

Full capabilities:

{
  "#{client_id}.Clients"  => { "Create", "Read", "Update", "Delete" },
  "#{client_id}.Projects" => { "Create", "Read", "Update", "Delete" },
}

store

A Redis server which stores the user data of Clients and Projects.

clients

A CRUD API for Clients. The entry point is at services/clients.rb.

projects

A CRUD API for Projects. The entry point is at services/projects.rb.

RPC Protocol

The APIs work via a simple request-response RPC protocol providing access to Trailblazer functions over HTTP POST requests. It is defined in lib/rpc.rb.

The client must make a request with ns(namespace), fn(function), and in(input). For example, to call Clients::Create with curl:

curl -H "Content-Type: application/json" -H "Authorization: root token" -X POST -d '{"ns":"Clients","fn":"Create","in":{"name":"Alice"}}' http://localhost:8080

Or the same with Ruby:

require_relative 'spec/rpc_client'

rpc = RPCClient.new 'http://localhost:8080', token: 'root token'
rpc['Clients::Create', name: 'Alice']

The server can respond with:

  • 200: OK A Hash from ctx[:output]. For example:

      {
        id: some_id,
        name: 'Alice',
      }
    
  • 400: Bad Request

  • 403: Forbidden

The authorization logic is defined in lib/roles/client.rb and lib/act.rb.

Specs

To run the specs: bundle exec rspec.

The specs expect to find all the services listening(after bundle exec foreman start spinned them up).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.