Skip to main content

docs/demo_script.md

# Demo script

The demo scenario is available in two forms:

1. **Livebook** — `docs/livebooks/logistiki_demo.livemd`. Open it in
   [Livebook](https://livebook.dev/) for an interactive, step-by-step walkthrough
   with rendered output.

2. **Script** — `Logistiki.Demo.run_demo/0` from an `iex` or `mix run` session.
   Seeds the demo entity and account trees, links entities to accounts, processes
   the demo business events end-to-end, and prints the results.

## Running the livebook

```bash
# From the project root — no PostgreSQL required, the livebook uses SQLite in-memory:
livebook open docs/livebooks/logistiki_demo.livemd
```

The livebook uses `Mix.install` with `LOGISTIKI_DB_ADAPTER=sqlite` and
`ecto_sqlite3` to create an in-memory SQLite database. It runs migrations
programmatically via `Ecto.Migrator`. No external services are needed.

## Running the script

On a fresh, migrated database:

```bash
mix ecto.drop && mix ecto.create && mix ecto.migrate
mix run -e 'Logistiki.Demo.run_demo()'
```

Or use the simulation backend explicitly and switch to the Beancount oracle:

```elixir
Logistiki.put_ledger_backend(Logistiki.Ledger.Simulation)
Logistiki.Demo.run_demo()

Logistiki.put_ledger_backend(Logistiki.Ledger.Beancount)
Logistiki.Demo.run_demo()
```

## Demo business entities

```
Acme Holdings
  Acme Trading Ltd
  Acme Treasury Ltd

Bluewater Trust
  Bluewater Operating Company
```

## Demo virtual accounts

```
Assets
  Cash
    USD
      Nostro USD

Liabilities
  Client Deposits
    USD
      Acme Holdings
        Operating
        Payroll
        Escrow
      Bluewater Trust
        Operating

Income
  Fees
    Wire Fees

Expenses
  Interest Expense

Suspense
  USD Suspense
```

## Demo events

1. Deposit received for Acme Operating.
2. Internal transfer from Acme Operating to Acme Payroll (template available).
3. Wire fee assessed to Acme Operating.
4. Mistaken fee reversed.
5. Suspense posting corrected (template available).
6. Customer account opened with no accounting impact.

## What the demo shows

1. Load knowledge program.
2. Create entity tree.
3. Create account tree.
4. Link entities to accounts.
5. Process deposit event.
6. Show policy selected by Datalog (`:cash_deposit`).
7. Show generated journal.
8. Show generated postings.
9. Show ledger backend execution.
10. Show balance.
11. Show statement (with running balance).
12. Process fee event (`:corporate_wire_fee`).
13. Reverse the fee.
14. Show balance restored.
15. Show audit evidence explaining everything.

## Seed script

`priv/repo/seeds.exs` seeds the demo entity and account trees (idempotent — it
skips if entities already exist). Run with `mix ecto.setup` or
`mix ecto.reset`.