You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A double-entry accounting database with a typed GraphQL API, supporting:
6
+
7
+
- Immutable entries
8
+
- An API introspected directly from a PostgreSQL schema
9
+
- GraphQL subscriptions for real-time updates
10
+
11
+
## Basics
12
+
13
+
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.
14
+
15
+
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](http://localhost:5000/graphiql)
16
+
17
+
First, create some `account`s:
18
+
19
+
```
20
+
mutation {
21
+
createAccount(input: {account: {type: EQUITY, name: "Y Combinator Seed"}}) {
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.
52
+
53
+
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.
54
+
55
+
The general ledger can be queried after `posting`s are created:
56
+
57
+
```
58
+
query {
59
+
ledgers {
60
+
nodes {
61
+
accountName
62
+
balance
63
+
currency
64
+
}
65
+
}
66
+
}
67
+
```
68
+
69
+
Lastly, Scaledger also supports WebSockets for newly created postings via the GraphQL Subscription primitive:
70
+
71
+
```
72
+
subscription {
73
+
postingCreated {
74
+
posting {
75
+
amount
76
+
id
77
+
}
78
+
}
79
+
}
80
+
```
81
+
82
+
## Stack
83
+
84
+
Scaledger uses a purpose-built PostgreSQL schema and provides a GraphQL API.
85
+
86
+
### Services
87
+
-*scaledger-db*: a PostgreSQL database and ledger schema
88
+
-*scaledger-server*: a node-based [PostGraphile](https://www.graphile.org/) GraphQL API
89
+
90
+
## Development
91
+
92
+
scaledger includes a `docker-compose` configuration out of box.
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`.
101
+
102
+
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.
103
+
104
+
If you wish to recreate the database, or reset it, without any seed data you can run `./schema` instead.
105
+
106
+
To connect to the docker container running the database with `psql` run `./scripts/psql`.
107
+
108
+
### Services In Development
109
+
- View `scaledger-server`'s GraphiQL testbed at [http://localhost:5000/graphiql](http://localhost:5000/graphiql)
110
+
-`scaledger-server` is mounted at [http://localhost:5000/](http://localhost:5000)
111
+
-`scaledger-db` runs on `5432`, use `./scripts/psql` to run a console
0 commit comments