Giter Club home page Giter Club logo

scaledger's Introduction

Scaledger

pipeline status

A double-entry accounting database with a typed GraphQL API, supporting:

  • Immutable entries
  • An API introspected directly from a PostgreSQL schema
  • GraphQL subscriptions for real-time updates

Basics

Scaledger is designed to be used as a service for recording transactions (called postings) between accounts, and reporting their balances through an entity called ledger. This is particularly useful when you have to track the balances for thousands, or even millions, of individual user accounts such as in the case of marketplaces.

To use it, you deploy it as part of your service architecture and connect over a GraphQL interface. Documentation this interface is available at http://localhost:5000/graphiql

First, create some accounts:

mutation {
  createAccount(input: {account: {type: EQUITY, name: "Y Combinator Seed"}}) {
    account {
      id
    }
  }
}

mutation {
  createAccount(input: {account: {type: ASSET, name: "Cash"}}) {
    account {
      id
    }
  }
}

Next, create a posting between them:

mutation {
  createPosting(input: { posting: {
    creditId: "5c70baa8-f917-4220-afad-1521fdecb5a7",
    debitId: "9c42c59a-7404-47f2-9a63-fb3a8ecab111",
    currency: USD,
    amount: 15000000,
    externalId: "yc-safe-transfer"
  }})
}

You'll notice that the amount field is denominated in the minor value of the currency. This is important - don't use floats for accounting systems! Next, you'll notice currency - Scaledger is natively multi-currency and supports all of the ISO 4217 currency codes. If you're wondering what externalId is, that's required so that each posting from a downstream service is idempotent - as a defense against you sending the same request twice.

Both account and posting also support a metadata field which can be used to store abitrary key/value JSON dictionaries of extra data. Like any good ledger, posting cannot be mutated after it is created - to void a transaction you need to reverse it by creating an inverted one.

The general ledger can be queried after postings are created:

query {
  ledgers {
    nodes {
      accountName
      balance
      currency
    }
  }
}

Lastly, Scaledger also supports WebSockets for newly created postings via the GraphQL Subscription primitive:

subscription {
  postingCreated {
    posting {
      amount
      id
    }
  }
}

Stack

Scaledger uses a purpose-built PostgreSQL schema and provides a GraphQL API.

Services

  • scaledger-db: a PostgreSQL database and ledger schema
  • scaledger-server: a node-based PostGraphile GraphQL API

Development

scaledger includes a docker-compose configuration out of box.

  1. Clone the project
  2. Install Docker Compose
  3. cd docker
  4. Build images with ./scripts/images
  5. docker-compose up

By default, your first initialization of the container will automatically run the schema. Depending on how you've installed docker, you may need to prefix sudo on docker-compose up and on any of the scripts in docker/scripts.

If you'd like to create test data, run ./scripts/seed from inside of docker. You can run ./seed at any point to return the test data and schema to an initial state.

If you wish to recreate the database, or reset it, without any seed data you can run ./schema instead.

To connect to the docker container running the database with psql run ./scripts/psql.

Services In Development

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.