This ledger system is a prototype implementation of the real world accounting ledger system. This project was inspired after taking on similar project in my current day-job. The aim of this project is to both learn about how the real world ledger accounting system works while also improving on my go-lang skills.
- Gorm (for ORM)
- Gen tool (from Gorm for generating models and data access objects from sql)
- Goose (for managing migrations)
The goose tool is used to generate versioned migration written in either go or sql. Here is a sample command to generate sql migration file named init:
~/go/bin/goose -dir pkg/db/migrations postgres "host=localhost user=postgres password=password dbname=accounting_ledger port=5432 sslmode=disable TimeZone=Asia/Shanghai" create init sql
When you run the above command, goose will generate a migration file that may look like this:
-- +goose Up
-- +goose StatementBegin
SELECT * WHERE 1 = 1
-- +goose StatementEnd
notice that goose generated an empty sql file. This means that you have to manually write the sql schema yourself. You can edit the sql file generated and put in your sql statements. Here is a sample SQL command to create a user table:
-- +goose Up
-- +goose StatementBegin
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS users(
id UUID DEFAULT uuid_generate_v4 (),
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NULL DEFAULT NULL,
deleted_at TIMESTAMP NULL DEFAULT NULL,
email_address VARCHAR(255) NOT NULL UNIQUE,
phone_number VARCHAR(20) NOT NULL UNIQUE,
PRIMARY KEY (id)
);
-- +goose StatementEnd
After generating and modifying the migration file(s), the next step is to execute (or run) the migration file(s). This step is to ensure that the sql schema is effected in the database. Here is a sample command for running migration:
~/go/bin/goose -dir pkg/db/migrations postgres "host=localhost user=postgres password=password dbname=accounting_ledger port=5432 sslmode=disable TimeZone=Asia/Shanghai" up
You can optionally check migration status:
~/go/bin/goose postgres "host=localhost user=postgres password=password dbname=accounting_ledger port=5432 sslmode=disable TimeZone=Asia/Shanghai" status
The next step is to generate models and data access objects from the database using the Gorm gen tool. This step will automatically generate these models and data objects from the migrated database schema. The following is a sample command to generate the models:
~/go/bin/gentool -dsn "postgresql://postgres:postgres@localhost:5432/accounting_ledger?connect_timeout=10&sslmode=disable" -db postgres -outPath "pkg/db/dao"
The ledger system will feature a dashboard application that lets users explore / manage their ledger. The following are the features of this app:
- Manage Wallet Types
- Create Wallet Types
- Edit Wallet types (updating the rules of the wallet type)
- List wallet types
- List all wallets in an organization
- Show details of a wallet
- List the ledger accounts in a wallet
- Show the number of transaction blocks for an account in a wallet
- List the transaction blocks for an account in a wallet
- List the transactions contained in an account block
- List account transaction statements for an account in a wallet
- Dashboard Metrics
- Total Number of wallet types (owned by the organization)
- Total Number of wallets owned by the organization
- Total Number of transaction blocks created for the organization
- Total Number of transactions
- Wallet Type metrics
- Total Number of wallets
- Total Number of transaction blocks
- Total Number of transactions