├── .iex.exs
├── assets
├── .babelrc
├── static
│ ├── favicon.ico
│ ├── images
│ │ └── phoenix.png
│ └── robots.txt
├── package.json
├── js
│ └── app.js
├── webpack.config.js
└── css
│ ├── app.scss
│ └── phoenix.css
├── test
├── test_helper.exs
├── bank_web
│ ├── views
│ │ ├── layout_view_test.exs
│ │ └── error_view_test.exs
│ └── live
│ │ └── page_live_test.exs
└── support
│ ├── channel_case.ex
│ ├── conn_case.ex
│ └── data_case.ex
├── lib
├── bank_web
│ ├── views
│ │ ├── layout_view.ex
│ │ ├── error_view.ex
│ │ └── error_helpers.ex
│ ├── templates
│ │ └── layout
│ │ │ ├── app.html.eex
│ │ │ ├── live.html.leex
│ │ │ └── root.html.leex
│ ├── channels
│ │ └── user_socket.ex
│ ├── live
│ │ ├── page_live.ex
│ │ └── page_live.html.leex
│ ├── router.ex
│ ├── endpoint.ex
│ └── telemetry.ex
├── bank
│ ├── core
│ │ ├── event_store.ex
│ │ ├── application.ex
│ │ ├── supervisor.ex
│ │ ├── router.ex
│ │ ├── accounting
│ │ │ ├── account_entry.ex
│ │ │ └── account_entry_projector.ex
│ │ ├── accounting.ex
│ │ ├── accounts.ex
│ │ └── accounts
│ │ │ ├── money_transfer_process_manager.ex
│ │ │ └── account.ex
│ ├── repo.ex
│ ├── events
│ │ ├── account_opened.ex
│ │ ├── money_deposited.ex
│ │ ├── money_withdrawn.ex
│ │ ├── journal_entry_created.ex
│ │ ├── money_transfer_failed.ex
│ │ ├── money_send_to_account.ex
│ │ ├── money_received_from_account.ex
│ │ └── money_received_from_account_failed.ex
│ ├── commands
│ │ ├── deposit_money.ex
│ │ ├── withdraw_money.ex
│ │ ├── create_loan.ex
│ │ ├── send_money_to_account.ex
│ │ ├── fail_money_transfer.ex
│ │ └── receive_money_from_account.ex
│ └── application.ex
├── bank.ex
└── bank_web.ex
├── priv
└── repo
│ ├── migrations
│ ├── .formatter.exs
│ ├── 20210818213936_create_projection_versions.exs
│ └── 20210818212710_create_account_entries.exs
│ └── seeds.exs
├── .formatter.exs
├── README.md
├── config
├── test.exs
├── prod.secret.exs
├── config.exs
├── prod.exs
└── dev.exs
├── .gitignore
├── mix.exs
└── mix.lock
/.iex.exs:
--------------------------------------------------------------------------------
1 | alias Bank.Core.Events.JournalEntryCreated
2 |
--------------------------------------------------------------------------------
/assets/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "@babel/preset-env"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/test/test_helper.exs:
--------------------------------------------------------------------------------
1 | ExUnit.start()
2 | Ecto.Adapters.SQL.Sandbox.mode(Bank.Repo, :manual)
3 |
--------------------------------------------------------------------------------
/assets/static/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vasspilka/bank/HEAD/assets/static/favicon.ico
--------------------------------------------------------------------------------
/lib/bank_web/views/layout_view.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.LayoutView do
2 | use BankWeb, :view
3 | end
4 |
--------------------------------------------------------------------------------
/priv/repo/migrations/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto_sql],
3 | inputs: ["*.exs"]
4 | ]
5 |
--------------------------------------------------------------------------------
/lib/bank/core/event_store.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.EventStore do
2 | use EventStore, otp_app: :bank
3 | end
4 |
--------------------------------------------------------------------------------
/assets/static/images/phoenix.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vasspilka/bank/HEAD/assets/static/images/phoenix.png
--------------------------------------------------------------------------------
/lib/bank/repo.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Repo do
2 | use Ecto.Repo,
3 | otp_app: :bank,
4 | adapter: Ecto.Adapters.Postgres
5 | end
6 |
--------------------------------------------------------------------------------
/lib/bank/core/application.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Application do
2 | use Commanded.Application, otp_app: :bank
3 |
4 | router(Bank.Core.Router)
5 | end
6 |
--------------------------------------------------------------------------------
/.formatter.exs:
--------------------------------------------------------------------------------
1 | [
2 | import_deps: [:ecto, :phoenix],
3 | inputs: ["*.{ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{ex,exs}"],
4 | subdirectories: ["priv/*/migrations"]
5 | ]
6 |
--------------------------------------------------------------------------------
/lib/bank.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank do
2 | @moduledoc "Banking application"
3 |
4 | @type account_number() :: binary()
5 | @type amount() :: integer()
6 | @type account_entries() :: %{account_number() => amount()}
7 | end
8 |
--------------------------------------------------------------------------------
/assets/static/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/lib/bank/events/account_opened.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.AccountOpened do
2 | @type t :: %__MODULE__{
3 | account_id: Bank.account_number()
4 | }
5 |
6 | @derive Jason.Encoder
7 | defstruct [:account_id]
8 | end
9 |
--------------------------------------------------------------------------------
/lib/bank/commands/deposit_money.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.DepositMoney do
2 | @type t :: %__MODULE__{
3 | account_id: Bank.account_number(),
4 | amount: Bank.amount()
5 | }
6 |
7 | defstruct [:account_id, :amount]
8 | end
9 |
--------------------------------------------------------------------------------
/lib/bank/commands/withdraw_money.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.WithdrawMoney do
2 | @type t :: %__MODULE__{
3 | account_id: Bank.account_number(),
4 | amount: Bank.amount()
5 | }
6 |
7 | defstruct [:account_id, :amount]
8 | end
9 |
--------------------------------------------------------------------------------
/lib/bank_web/templates/layout/app.html.eex:
--------------------------------------------------------------------------------
1 |
2 | <%= get_flash(@conn, :info) %>
3 | <%= get_flash(@conn, :error) %>
4 | <%= @inner_content %>
5 |
6 |
--------------------------------------------------------------------------------
/lib/bank/events/money_deposited.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneyDeposited do
2 | @type t :: %__MODULE__{
3 | account_id: Bank.account_number(),
4 | amount: Bank.amount()
5 | }
6 |
7 | @derive Jason.Encoder
8 | defstruct [:account_id, :amount]
9 | end
10 |
--------------------------------------------------------------------------------
/lib/bank/events/money_withdrawn.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneyWithdrawn do
2 | @type t :: %__MODULE__{
3 | account_id: Bank.account_number(),
4 | amount: Bank.amount()
5 | }
6 |
7 | @derive Jason.Encoder
8 | defstruct [:account_id, :amount]
9 | end
10 |
--------------------------------------------------------------------------------
/test/bank_web/views/layout_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.LayoutViewTest do
2 | use BankWeb.ConnCase, async: true
3 |
4 | # When testing helpers, you may want to import Phoenix.HTML and
5 | # use functions such as safe_to_string() to convert the helper
6 | # result into an HTML string.
7 | # import Phoenix.HTML
8 | end
9 |
--------------------------------------------------------------------------------
/lib/bank/commands/create_loan.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.CreateLoan do
2 | @type t :: %__MODULE__{
3 | loan_id: binary(),
4 | account_id: binary(),
5 | amount: integer(),
6 | loan_fee: integer()
7 | }
8 |
9 | defstruct [:loan_id, :account_id, :amount, :loan_fee]
10 | end
11 |
--------------------------------------------------------------------------------
/lib/bank/commands/send_money_to_account.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.SendMoneyToAccount do
2 | @type t :: %__MODULE__{
3 | from_account_id: Bank.account_number(),
4 | to_account_id: Bank.account_number(),
5 | amount: Bank.amount()
6 | }
7 |
8 | defstruct [
9 | :from_account_id,
10 | :to_account_id,
11 | :amount
12 | ]
13 | end
14 |
--------------------------------------------------------------------------------
/priv/repo/seeds.exs:
--------------------------------------------------------------------------------
1 | # Script for populating the database. You can run it as:
2 | #
3 | # mix run priv/repo/seeds.exs
4 | #
5 | # Inside the script, you can read and write to any of your
6 | # repositories directly:
7 | #
8 | # Bank.Repo.insert!(%Bank.SomeSchema{})
9 | #
10 | # We recommend using the bang functions (`insert!`, `update!`
11 | # and so on) as they will fail if something goes wrong.
12 |
--------------------------------------------------------------------------------
/test/bank_web/live/page_live_test.exs:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.PageLiveTest do
2 | use BankWeb.ConnCase
3 |
4 | import Phoenix.LiveViewTest
5 |
6 | test "disconnected and connected render", %{conn: conn} do
7 | {:ok, page_live, disconnected_html} = live(conn, "/")
8 | assert disconnected_html =~ "Welcome to Phoenix!"
9 | assert render(page_live) =~ "Welcome to Phoenix!"
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/lib/bank/events/journal_entry_created.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.JournalEntryCreated do
2 | alias Bank.Core.Accounting
3 |
4 | @type t :: %__MODULE__{
5 | journal_entry_uuid: binary(),
6 | debit: Accounting.account_entries(),
7 | credit: Accounting.account_entries()
8 | }
9 |
10 | @derive Jason.Encoder
11 | defstruct [:journal_entry_uuid, :debit, :credit]
12 | end
13 |
--------------------------------------------------------------------------------
/lib/bank_web/templates/layout/live.html.leex:
--------------------------------------------------------------------------------
1 |
2 | <%= live_flash(@flash, :info) %>
5 |
6 | <%= live_flash(@flash, :error) %>
9 |
10 | <%= @inner_content %>
11 |
12 |
--------------------------------------------------------------------------------
/priv/repo/migrations/20210818213936_create_projection_versions.exs:
--------------------------------------------------------------------------------
1 | defmodule Bank.Repo.Migrations.CreateProjectionVersions do
2 | use Ecto.Migration
3 |
4 | def change do
5 | create table(:projection_versions, primary_key: false) do
6 | add(:projection_name, :text, primary_key: true)
7 | add(:last_seen_event_number, :bigint)
8 |
9 | timestamps(type: :naive_datetime_usec)
10 | end
11 | end
12 | end
13 |
--------------------------------------------------------------------------------
/lib/bank/commands/fail_money_transfer.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.FailMoneyTransfer do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | defstruct [
10 | :transaction_id,
11 | :from_account_id,
12 | :to_account_id,
13 | :amount
14 | ]
15 | end
16 |
--------------------------------------------------------------------------------
/lib/bank/events/money_transfer_failed.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneyTransferFailed do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | defstruct [
10 | :transaction_id,
11 | :from_account_id,
12 | :to_account_id,
13 | :amount
14 | ]
15 | end
16 |
--------------------------------------------------------------------------------
/lib/bank/commands/receive_money_from_account.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Commands.ReceiveMoneyFromAccount do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | defstruct [
10 | :transaction_id,
11 | :from_account_id,
12 | :to_account_id,
13 | :amount
14 | ]
15 | end
16 |
--------------------------------------------------------------------------------
/lib/bank/events/money_send_to_account.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneySentToAccount do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | @derive Jason.Encoder
10 | defstruct [
11 | :transaction_id,
12 | :from_account_id,
13 | :to_account_id,
14 | :amount
15 | ]
16 | end
17 |
--------------------------------------------------------------------------------
/lib/bank/events/money_received_from_account.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneyReceivedFromAccount do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | @derive Jason.Encoder
10 | defstruct [
11 | :transaction_id,
12 | :from_account_id,
13 | :to_account_id,
14 | :amount
15 | ]
16 | end
17 |
--------------------------------------------------------------------------------
/lib/bank/core/supervisor.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Supervisor do
2 | use Supervisor
3 |
4 | def start_link(init_arg) do
5 | Supervisor.start_link(__MODULE__, init_arg, name: __MODULE__)
6 | end
7 |
8 | def init(_args) do
9 | children = [
10 | Bank.Core.Application,
11 | Bank.Core.Accounting.AccountEntryProjector,
12 | Bank.Core.Accounts.MoneyTransferProcessManager
13 | ]
14 |
15 | Supervisor.init(children, strategy: :one_for_one)
16 | end
17 | end
18 |
--------------------------------------------------------------------------------
/test/bank_web/views/error_view_test.exs:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.ErrorViewTest do
2 | use BankWeb.ConnCase, async: true
3 |
4 | # Bring render/3 and render_to_string/3 for testing custom views
5 | import Phoenix.View
6 |
7 | test "renders 404.html" do
8 | assert render_to_string(BankWeb.ErrorView, "404.html", []) == "Not Found"
9 | end
10 |
11 | test "renders 500.html" do
12 | assert render_to_string(BankWeb.ErrorView, "500.html", []) == "Internal Server Error"
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/lib/bank/events/money_received_from_account_failed.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Events.MoneyReceivedFromAccountFailed do
2 | @type t :: %__MODULE__{
3 | transaction_id: binary(),
4 | from_account_id: Bank.account_number(),
5 | to_account_id: Bank.account_number(),
6 | amount: Bank.amount()
7 | }
8 |
9 | @derive Jason.Encoder
10 | defstruct [
11 | :transaction_id,
12 | :from_account_id,
13 | :to_account_id,
14 | :amount
15 | ]
16 | end
17 |
--------------------------------------------------------------------------------
/priv/repo/migrations/20210818212710_create_account_entries.exs:
--------------------------------------------------------------------------------
1 | defmodule Bank.Repo.Migrations.CreateAccountEntries do
2 | use Ecto.Migration
3 |
4 | def change do
5 | create table(:accounting_account_entries_v1) do
6 | add :journal_entry_uuid, :uuid, null: false
7 |
8 | add :account, :string, null: false
9 |
10 | add :credit, :integer, default: 0, null: false
11 | add :debit, :integer, default: 0, null: false
12 |
13 | add :metadata, :map
14 | end
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/lib/bank_web/views/error_view.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.ErrorView do
2 | use BankWeb, :view
3 |
4 | # If you want to customize a particular status code
5 | # for a certain format, you may uncomment below.
6 | # def render("500.html", _assigns) do
7 | # "Internal Server Error"
8 | # end
9 |
10 | # By default, Phoenix returns the status message from
11 | # the template name. For example, "404.html" becomes
12 | # "Not Found".
13 | def template_not_found(template, _assigns) do
14 | Phoenix.Controller.status_message_from_template(template)
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/lib/bank/application.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Application do
2 | @moduledoc false
3 |
4 | use Application
5 |
6 | def start(_type, _args) do
7 | children = [
8 | Bank.Repo,
9 | BankWeb.Telemetry,
10 | {Phoenix.PubSub, name: Bank.PubSub},
11 | BankWeb.Endpoint,
12 | Bank.Core.Supervisor
13 | ]
14 |
15 | opts = [strategy: :one_for_one, name: Bank.Supervisor]
16 | Supervisor.start_link(children, opts)
17 | end
18 |
19 | def config_change(changed, _new, removed) do
20 | BankWeb.Endpoint.config_change(changed, removed)
21 | :ok
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/lib/bank/core/router.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Router do
2 | use Commanded.Commands.Router
3 |
4 | alias Bank.Core.Commands
5 |
6 | dispatch(
7 | [
8 | Commands.DepositMoney,
9 | Commands.WithdrawMoney
10 | ],
11 | to: Bank.Core.Accounts.Account,
12 | identity: :account_id
13 | )
14 |
15 | dispatch(
16 | [Commands.SendMoneyToAccount, Commands.FailMoneyTransfer],
17 | to: Bank.Core.Accounts.Account,
18 | identity: :from_account_id
19 | )
20 |
21 | dispatch(
22 | [Commands.ReceiveMoneyFromAccount],
23 | to: Bank.Core.Accounts.Account,
24 | identity: :to_account_id
25 | )
26 | end
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bank
2 |
3 | An example event-source application used for my ElixirConfEU 2021 talk.
4 |
5 | * Install dependencies with `mix deps.get`
6 | * Create and migrate your database with `mix ecto.setup`
7 | * Run app with `iex -S mix`
8 |
9 | ## Learn more
10 |
11 | * Talk Slides: https://drive.google.com/file/d/1nW0Bg3u-ZDMJe9W3yaFs6X17dFWYG_kV/view
12 | * Commanded Repo: https://github.com/commanded/commanded
13 | * Eventsourcing: https://martinfowler.com/eaaDev/EventSourcing.html
14 | * Recording: https://www.youtube.com/watch?v=ggfrpP88r2A
15 |
16 | ## Todos
17 |
18 | * Add tests
19 | * Additional features?? (Make requests in issues)
20 |
--------------------------------------------------------------------------------
/lib/bank/core/accounting/account_entry.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounting.AccountEntry do
2 | @moduledoc """
3 | This module defines the AccountEntry schema.
4 | Used to model single account entries.
5 | """
6 |
7 | use Ecto.Schema
8 |
9 | @type t() :: %{
10 | journal_entry_uuid: binary(),
11 | account: binary(),
12 | credit: integer(),
13 | debit: integer()
14 | }
15 |
16 | schema "accounting_account_entries_v1" do
17 | field :journal_entry_uuid, :binary_id
18 | field :account, :string
19 |
20 | field :credit, :integer, default: 0
21 | field :debit, :integer, default: 0
22 | end
23 | end
24 |
--------------------------------------------------------------------------------
/config/test.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # Configure your database
4 | #
5 | # The MIX_TEST_PARTITION environment variable can be used
6 | # to provide built-in test partitioning in CI environment.
7 | # Run `mix help test` for more information.
8 | config :bank, Bank.Repo,
9 | username: "postgres",
10 | password: "postgres",
11 | database: "bank_test#{System.get_env("MIX_TEST_PARTITION")}",
12 | hostname: "localhost",
13 | pool: Ecto.Adapters.SQL.Sandbox
14 |
15 | # We don't run a server during test. If one is required,
16 | # you can enable the server option below.
17 | config :bank, BankWeb.Endpoint,
18 | http: [port: 4002],
19 | server: false
20 |
21 | # Print only warnings and errors during test
22 | config :logger, level: :warn
23 |
--------------------------------------------------------------------------------
/lib/bank_web/views/error_helpers.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.ErrorHelpers do
2 | @moduledoc """
3 | Conveniences for translating and building error messages.
4 | """
5 |
6 | use Phoenix.HTML
7 |
8 | @doc """
9 | Generates tag for inlined form input errors.
10 | """
11 | def error_tag(form, field) do
12 | Enum.map(Keyword.get_values(form.errors, field), fn error ->
13 | content_tag(:span, translate_error(error),
14 | class: "invalid-feedback",
15 | phx_feedback_for: input_name(form, field)
16 | )
17 | end)
18 | end
19 |
20 | @doc """
21 | Translates an error message.
22 | """
23 | def translate_error({msg, opts}) do
24 | # Because the error messages we show in our forms and APIs
25 | # are defined inside Ecto, we need to translate them dynamically.
26 | Enum.reduce(opts, msg, fn {key, value}, acc ->
27 | String.replace(acc, "%{#{key}}", to_string(value))
28 | end)
29 | end
30 | end
31 |
--------------------------------------------------------------------------------
/assets/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "repository": {},
3 | "description": " ",
4 | "license": "MIT",
5 | "scripts": {
6 | "deploy": "webpack --mode production",
7 | "watch": "webpack --mode development --watch"
8 | },
9 | "dependencies": {
10 | "phoenix": "file:../deps/phoenix",
11 | "phoenix_html": "file:../deps/phoenix_html",
12 | "phoenix_live_view": "file:../deps/phoenix_live_view",
13 | "topbar": "^0.1.4"
14 | },
15 | "devDependencies": {
16 | "@babel/core": "^7.0.0",
17 | "@babel/preset-env": "^7.0.0",
18 | "babel-loader": "^8.0.0",
19 | "copy-webpack-plugin": "^5.1.1",
20 | "css-loader": "^3.4.2",
21 | "hard-source-webpack-plugin": "^0.13.1",
22 | "mini-css-extract-plugin": "^0.9.0",
23 | "node-sass": "^4.13.1",
24 | "optimize-css-assets-webpack-plugin": "^5.0.1",
25 | "sass-loader": "^8.0.2",
26 | "terser-webpack-plugin": "^2.3.2",
27 | "webpack": "^4.41.5",
28 | "webpack-cli": "^3.3.2"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # The directory Mix will write compiled artifacts to.
2 | /_build/
3 |
4 | # If you run "mix test --cover", coverage assets end up here.
5 | /cover/
6 |
7 | # The directory Mix downloads your dependencies sources to.
8 | /deps/
9 |
10 | # Where 3rd-party dependencies like ExDoc output generated docs.
11 | /doc/
12 |
13 | # Ignore .fetch files in case you like to edit your project deps locally.
14 | /.fetch
15 |
16 | # If the VM crashes, it generates a dump, let's ignore it too.
17 | erl_crash.dump
18 |
19 | # Also ignore archive artifacts (built via "mix archive.build").
20 | *.ez
21 |
22 | # Ignore package tarball (built via "mix hex.build").
23 | bank-*.tar
24 |
25 | # If NPM crashes, it generates a log, let's ignore it too.
26 | npm-debug.log
27 |
28 | # The directory NPM downloads your dependencies sources to.
29 | /assets/node_modules/
30 |
31 | # Since we are building assets from assets/,
32 | # we ignore priv/static. You may want to comment
33 | # this depending on your deployment strategy.
34 | /priv/static/
35 |
36 | .DS_Store
37 |
--------------------------------------------------------------------------------
/lib/bank_web/channels/user_socket.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.UserSocket do
2 | use Phoenix.Socket
3 |
4 | ## Channels
5 | # channel "room:*", BankWeb.RoomChannel
6 |
7 | # Socket params are passed from the client and can
8 | # be used to verify and authenticate a user. After
9 | # verification, you can put default assigns into
10 | # the socket that will be set for all channels, ie
11 | #
12 | # {:ok, assign(socket, :user_id, verified_user_id)}
13 | #
14 | # To deny connection, return `:error`.
15 | #
16 | # See `Phoenix.Token` documentation for examples in
17 | # performing token verification on connect.
18 | @impl true
19 | def connect(_params, socket, _connect_info) do
20 | {:ok, socket}
21 | end
22 |
23 | # Socket id's are topics that allow you to identify all sockets for a given user:
24 | #
25 | # def id(socket), do: "user_socket:#{socket.assigns.user_id}"
26 | #
27 | # Would allow you to broadcast a "disconnect" event and terminate
28 | # all active sockets and channels for a given user:
29 | #
30 | # BankWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
31 | #
32 | # Returning `nil` makes this socket anonymous.
33 | @impl true
34 | def id(_socket), do: nil
35 | end
36 |
--------------------------------------------------------------------------------
/lib/bank_web/live/page_live.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.PageLive do
2 | use BankWeb, :live_view
3 |
4 | @impl true
5 | def mount(_params, _session, socket) do
6 | {:ok, assign(socket, query: "", results: %{})}
7 | end
8 |
9 | @impl true
10 | def handle_event("suggest", %{"q" => query}, socket) do
11 | {:noreply, assign(socket, results: search(query), query: query)}
12 | end
13 |
14 | @impl true
15 | def handle_event("search", %{"q" => query}, socket) do
16 | case search(query) do
17 | %{^query => vsn} ->
18 | {:noreply, redirect(socket, external: "https://hexdocs.pm/#{query}/#{vsn}")}
19 |
20 | _ ->
21 | {:noreply,
22 | socket
23 | |> put_flash(:error, "No dependencies found matching \"#{query}\"")
24 | |> assign(results: %{}, query: query)}
25 | end
26 | end
27 |
28 | defp search(query) do
29 | if not BankWeb.Endpoint.config(:code_reloader) do
30 | raise "action disabled when not in development"
31 | end
32 |
33 | for {app, desc, vsn} <- Application.started_applications(),
34 | app = to_string(app),
35 | String.starts_with?(app, query) and not List.starts_with?(desc, ~c"ERTS"),
36 | into: %{},
37 | do: {app, vsn}
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/test/support/channel_case.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.ChannelCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | channel tests.
5 |
6 | Such tests rely on `Phoenix.ChannelTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | we enable the SQL sandbox, so changes done to the database
12 | are reverted at the end of every test. If you are using
13 | PostgreSQL, you can even run database tests asynchronously
14 | by setting `use BankWeb.ChannelCase, async: true`, although
15 | this option is not recommended for other databases.
16 | """
17 |
18 | use ExUnit.CaseTemplate
19 |
20 | using do
21 | quote do
22 | # Import conveniences for testing with channels
23 | import Phoenix.ChannelTest
24 | import BankWeb.ChannelCase
25 |
26 | # The default endpoint for testing
27 | @endpoint BankWeb.Endpoint
28 | end
29 | end
30 |
31 | setup tags do
32 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Bank.Repo)
33 |
34 | unless tags[:async] do
35 | Ecto.Adapters.SQL.Sandbox.mode(Bank.Repo, {:shared, self()})
36 | end
37 |
38 | :ok
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/lib/bank_web/router.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.Router do
2 | use BankWeb, :router
3 |
4 | pipeline :browser do
5 | plug :accepts, ["html"]
6 | plug :fetch_session
7 | plug :fetch_live_flash
8 | plug :put_root_layout, {BankWeb.LayoutView, :root}
9 | plug :protect_from_forgery
10 | plug :put_secure_browser_headers
11 | end
12 |
13 | pipeline :api do
14 | plug :accepts, ["json"]
15 | end
16 |
17 | scope "/", BankWeb do
18 | pipe_through :browser
19 |
20 | live "/", PageLive, :index
21 | end
22 |
23 | # Other scopes may use custom stacks.
24 | # scope "/api", BankWeb do
25 | # pipe_through :api
26 | # end
27 |
28 | # Enables LiveDashboard only for development
29 | #
30 | # If you want to use the LiveDashboard in production, you should put
31 | # it behind authentication and allow only admins to access it.
32 | # If your application does not have an admins-only section yet,
33 | # you can use Plug.BasicAuth to set up some basic authentication
34 | # as long as you are also using SSL (which you should anyway).
35 | if Mix.env() in [:dev, :test] do
36 | import Phoenix.LiveDashboard.Router
37 |
38 | scope "/" do
39 | pipe_through :browser
40 | live_dashboard "/dashboard", metrics: BankWeb.Telemetry
41 | end
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/lib/bank_web/templates/layout/root.html.leex:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | <%= csrf_meta_tag() %>
8 | <%= live_title_tag assigns[:page_title] || "Bank", suffix: " · Phoenix Framework" %>
9 | "/>
10 |
11 |
12 |
13 |
28 | <%= @inner_content %>
29 |
30 |
31 |
--------------------------------------------------------------------------------
/config/prod.secret.exs:
--------------------------------------------------------------------------------
1 | # In this file, we load production configuration and secrets
2 | # from environment variables. You can also hardcode secrets,
3 | # although such is generally not recommended and you have to
4 | # remember to add this file to your .gitignore.
5 | use Mix.Config
6 |
7 | database_url =
8 | System.get_env("DATABASE_URL") ||
9 | raise """
10 | environment variable DATABASE_URL is missing.
11 | For example: ecto://USER:PASS@HOST/DATABASE
12 | """
13 |
14 | config :bank, Bank.Repo,
15 | # ssl: true,
16 | url: database_url,
17 | pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")
18 |
19 | secret_key_base =
20 | System.get_env("SECRET_KEY_BASE") ||
21 | raise """
22 | environment variable SECRET_KEY_BASE is missing.
23 | You can generate one by calling: mix phx.gen.secret
24 | """
25 |
26 | config :bank, BankWeb.Endpoint,
27 | http: [
28 | port: String.to_integer(System.get_env("PORT") || "4000"),
29 | transport_options: [socket_opts: [:inet6]]
30 | ],
31 | secret_key_base: secret_key_base
32 |
33 | # ## Using releases (Elixir v1.9+)
34 | #
35 | # If you are doing OTP releases, you need to instruct Phoenix
36 | # to start each relevant endpoint:
37 | #
38 | # config :bank, BankWeb.Endpoint, server: true
39 | #
40 | # Then you can assemble a release by calling `mix release`.
41 | # See `mix help release` for more information.
42 |
--------------------------------------------------------------------------------
/test/support/conn_case.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.ConnCase do
2 | @moduledoc """
3 | This module defines the test case to be used by
4 | tests that require setting up a connection.
5 |
6 | Such tests rely on `Phoenix.ConnTest` and also
7 | import other functionality to make it easier
8 | to build common data structures and query the data layer.
9 |
10 | Finally, if the test case interacts with the database,
11 | we enable the SQL sandbox, so changes done to the database
12 | are reverted at the end of every test. If you are using
13 | PostgreSQL, you can even run database tests asynchronously
14 | by setting `use BankWeb.ConnCase, async: true`, although
15 | this option is not recommended for other databases.
16 | """
17 |
18 | use ExUnit.CaseTemplate
19 |
20 | using do
21 | quote do
22 | # Import conveniences for testing with connections
23 | import Plug.Conn
24 | import Phoenix.ConnTest
25 | import BankWeb.ConnCase
26 |
27 | alias BankWeb.Router.Helpers, as: Routes
28 |
29 | # The default endpoint for testing
30 | @endpoint BankWeb.Endpoint
31 | end
32 | end
33 |
34 | setup tags do
35 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Bank.Repo)
36 |
37 | unless tags[:async] do
38 | Ecto.Adapters.SQL.Sandbox.mode(Bank.Repo, {:shared, self()})
39 | end
40 |
41 | {:ok, conn: Phoenix.ConnTest.build_conn()}
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/assets/js/app.js:
--------------------------------------------------------------------------------
1 | // We need to import the CSS so that webpack will load it.
2 | // The MiniCssExtractPlugin is used to separate it out into
3 | // its own CSS file.
4 | import "../css/app.scss"
5 |
6 | // webpack automatically bundles all modules in your
7 | // entry points. Those entry points can be configured
8 | // in "webpack.config.js".
9 | //
10 | // Import deps with the dep name or local files with a relative path, for example:
11 | //
12 | // import {Socket} from "phoenix"
13 | // import socket from "./socket"
14 | //
15 | import "phoenix_html"
16 | import {Socket} from "phoenix"
17 | import topbar from "topbar"
18 | import {LiveSocket} from "phoenix_live_view"
19 |
20 | let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
21 | let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}})
22 |
23 | // Show progress bar on live navigation and form submits
24 | topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
25 | window.addEventListener("phx:page-loading-start", info => topbar.show())
26 | window.addEventListener("phx:page-loading-stop", info => topbar.hide())
27 |
28 | // connect if there are any LiveViews on the page
29 | liveSocket.connect()
30 |
31 | // expose liveSocket on window for web console debug logs and latency simulation:
32 | // >> liveSocket.enableDebug()
33 | // >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
34 | // >> liveSocket.disableLatencySim()
35 | window.liveSocket = liveSocket
36 |
37 |
--------------------------------------------------------------------------------
/lib/bank/core/accounting.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounting do
2 | @moduledoc "Accounting context."
3 |
4 | alias Bank.Core.Accounting.AccountEntry
5 | alias Bank.Core.Events.JournalEntryCreated
6 | alias Bank.Repo
7 | import Ecto.Query
8 |
9 | @spec create_raw_entry(Bank.account_entries(), Bank.account_entries()) ::
10 | :ok | {:error, term()}
11 | def create_raw_entry(debit, credit) do
12 | Bank.Core.EventStore.append_to_stream("raw_entries", :any_version, [
13 | %EventStore.EventData{
14 | event_id: Ecto.UUID.generate(),
15 | event_type: "#{JournalEntryCreated}",
16 | causation_id: Ecto.UUID.generate(),
17 | correlation_id: Ecto.UUID.generate(),
18 | data: %JournalEntryCreated{
19 | journal_entry_uuid: Ecto.UUID.generate(),
20 | debit: debit,
21 | credit: credit
22 | }
23 | }
24 | ])
25 | end
26 |
27 | @spec current_balance(Bank.account_number()) :: integer()
28 | def current_balance(account) do
29 | Repo.one(
30 | from e in AccountEntry,
31 | where: e.account == ^account,
32 | select: sum(e.debit) - sum(e.credit)
33 | )
34 | end
35 |
36 | @spec validate_event(%JournalEntryCreated{}) :: :ok | {:error, term()}
37 | def validate_event(je) do
38 | total_debit = je.debit |> Map.values() |> Enum.sum()
39 | total_credit = je.credit |> Map.values() |> Enum.sum()
40 |
41 | if total_debit == total_credit do
42 | :ok
43 | else
44 | {:error, :bad_entry}
45 | end
46 | end
47 | end
48 |
--------------------------------------------------------------------------------
/lib/bank/core/accounts.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounts do
2 | @moduledoc "Core context of user Accounts."
3 |
4 | alias Bank.Core.Commands.{DepositMoney, WithdrawMoney, SendMoneyToAccount}
5 | alias Commanded.Commands.ExecutionResult
6 | alias Bank.Core.Accounting.AccountEntry
7 | alias Bank.Repo
8 | import Ecto.Query
9 |
10 | @spec deposit_money(Bank.account_number(), Bank.amount()) ::
11 | {:ok, ExecutionResult.t()} | {:error, term()}
12 | def deposit_money(acc_id, amount) do
13 | %DepositMoney{account_id: acc_id, amount: amount}
14 | |> Bank.Core.Application.dispatch(returning: :execution_result)
15 | end
16 |
17 | @spec withdraw_money(Bank.account_number(), Bank.amount()) ::
18 | {:ok, ExecutionResult.t()} | {:error, term()}
19 | def withdraw_money(acc_id, amount) do
20 | %WithdrawMoney{account_id: acc_id, amount: amount}
21 | |> Bank.Core.Application.dispatch(returning: :execution_result)
22 | end
23 |
24 | @spec send_money(Bank.account_number(), Bank.account_number(), Bank.amount()) ::
25 | {:ok, ExecutionResult.t()} | {:error, term()}
26 | def send_money(from_acc_id, to_acc_id, amount) do
27 | %SendMoneyToAccount{from_account_id: from_acc_id, to_account_id: to_acc_id, amount: amount}
28 | |> Bank.Core.Application.dispatch(returning: :execution_result)
29 | end
30 |
31 | @spec view_balance(Bank.account_number()) :: Bank.amount()
32 | def view_balance(account) do
33 | Repo.one(
34 | from e in AccountEntry,
35 | where: e.account == ^account,
36 | select: sum(e.debit) - sum(e.credit)
37 | )
38 | end
39 | end
40 |
--------------------------------------------------------------------------------
/lib/bank/core/accounting/account_entry_projector.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounting.AccountEntryProjector do
2 | use Commanded.Projections.Ecto,
3 | name: "Accounting.AccountEntriesProjector",
4 | application: Bank.Core.Application,
5 | consistency: :strong
6 |
7 | alias Bank.Core.Accounting.AccountEntry
8 | alias Bank.Core.Events.JournalEntryCreated
9 |
10 | project(
11 | %JournalEntryCreated{} = evt,
12 | _metadata,
13 | fn multi ->
14 | Ecto.Multi.insert_all(
15 | multi,
16 | :insert_account_entries,
17 | AccountEntry,
18 | from_journal_entry(evt)
19 | )
20 | end
21 | )
22 |
23 | @spec from_journal_entry(%JournalEntryCreated{}) :: [AccountEntry.t()]
24 | defp from_journal_entry(journal_entry) do
25 | journal_entry
26 | |> Map.take([:debit, :credit])
27 | |> Enum.flat_map(fn {type, account_entries} ->
28 | Enum.map(account_entries, fn {account_id, amount} ->
29 | {account_id, type, amount}
30 | end)
31 | end)
32 | |> Enum.group_by(&elem(&1, 0), fn {_account_id, type, amount} ->
33 | {type, amount}
34 | end)
35 | |> convert_to_entries(journal_entry)
36 | end
37 |
38 | defp convert_to_entries(account_entries, journal_entry) do
39 | account_entries
40 | |> Enum.map(fn {account, entries} ->
41 | entries
42 | |> Enum.reduce(%{}, fn {type, amount}, acc ->
43 | Map.put(acc, type, amount)
44 | end)
45 | |> Map.merge(%{
46 | journal_entry_uuid: journal_entry.journal_entry_uuid,
47 | account: account
48 | })
49 | end)
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/lib/bank/core/accounts/money_transfer_process_manager.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounts.MoneyTransferProcessManager do
2 | use Commanded.ProcessManagers.ProcessManager,
3 | name: "Bank.Core.Accounts.MoneyTransferProcessManager",
4 | start_from: :origin,
5 | application: Bank.Core.Application
6 |
7 | alias Bank.Core.Commands.{ReceiveMoneyFromAccount, FailMoneyTransfer}
8 |
9 | alias Bank.Core.Events.{
10 | MoneySentToAccount,
11 | MoneyReceivedFromAccount,
12 | MoneyReceivedFromAccountFailed,
13 | MoneyTransferFailed
14 | }
15 |
16 | defstruct [:transaction_id]
17 |
18 | def interested?(%MoneySentToAccount{transaction_id: id}), do: {:start, id}
19 | def interested?(%MoneyReceivedFromAccountFailed{transaction_id: id}), do: {:continue, id}
20 | def interested?(%MoneyReceivedFromAccount{transaction_id: id}), do: {:stop, id}
21 | def interested?(%MoneyTransferFailed{transaction_id: id}), do: {:stop, id}
22 |
23 | def handle(%__MODULE__{}, %MoneySentToAccount{} = evt),
24 | do: [
25 | %ReceiveMoneyFromAccount{
26 | transaction_id: evt.transaction_id,
27 | from_account_id: evt.from_account_id,
28 | to_account_id: evt.to_account_id,
29 | amount: evt.amount
30 | }
31 | ]
32 |
33 | def handle(%__MODULE__{}, %MoneyReceivedFromAccountFailed{} = evt),
34 | do: [
35 | %FailMoneyTransfer{
36 | transaction_id: evt.transaction_id,
37 | from_account_id: evt.from_account_id,
38 | to_account_id: evt.to_account_id,
39 | amount: evt.amount
40 | }
41 | ]
42 |
43 | def apply(_state, %MoneySentToAccount{} = evt) do
44 | %__MODULE__{transaction_id: evt.transaction_id}
45 | end
46 | end
47 |
--------------------------------------------------------------------------------
/lib/bank_web/live/page_live.html.leex:
--------------------------------------------------------------------------------
1 |
2 | Welcome to Phoenix!
3 | Peace of mind from prototype to production
4 |
5 |
14 |
15 |
16 |
17 |
18 | Resources
19 |
30 |
31 |
32 | Help
33 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/config/config.exs:
--------------------------------------------------------------------------------
1 | # This file is responsible for configuring your application
2 | # and its dependencies with the aid of the Mix.Config module.
3 | #
4 | # This configuration file is loaded before any dependency and
5 | # is restricted to this project.
6 |
7 | # General application configuration
8 | use Mix.Config
9 |
10 | config :bank,
11 | ecto_repos: [Bank.Repo],
12 | generators: [binary_id: true]
13 |
14 | # Configures the endpoint
15 | config :bank, BankWeb.Endpoint,
16 | url: [host: "localhost"],
17 | secret_key_base: "prm6nLI2xPzdBMBium1edIbSMmBuPIgnJpHdvRePgl3NYli70fTA08McBTJ8P+Dw",
18 | render_errors: [view: BankWeb.ErrorView, accepts: ~w(html json), layout: false],
19 | pubsub_server: Bank.PubSub,
20 | live_view: [signing_salt: "B7g2cLHS"]
21 |
22 | # Configures Elixir's Logger
23 | config :logger, :console,
24 | format: "$time $metadata[$level] $message\n",
25 | metadata: [:request_id]
26 |
27 | # Use Jason for JSON parsing in Phoenix
28 | config :phoenix, :json_library, Jason
29 |
30 | config :bank, Bank.Core.EventStore,
31 | username: "postgres",
32 | password: "postgres",
33 | database: "bank_eventstore_dev",
34 | hostname: "localhost",
35 | serializer: EventStore.TermSerializer
36 |
37 | config :bank, event_stores: [Bank.Core.EventStore]
38 |
39 | config :commanded_ecto_projections,
40 | repo: Bank.Repo
41 |
42 | config :bank, Bank.Core.Application,
43 | event_store: [
44 | adapter: Commanded.EventStore.Adapters.EventStore,
45 | event_store: Bank.Core.EventStore
46 | ],
47 | pubsub: :local,
48 | registry: :local
49 |
50 | # Import environment specific config. This must remain at the bottom
51 | # of this file so it overrides the configuration defined above.
52 | import_config "#{Mix.env()}.exs"
53 |
--------------------------------------------------------------------------------
/assets/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 | const glob = require('glob');
3 | const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
4 | const MiniCssExtractPlugin = require('mini-css-extract-plugin');
5 | const TerserPlugin = require('terser-webpack-plugin');
6 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
7 | const CopyWebpackPlugin = require('copy-webpack-plugin');
8 |
9 | module.exports = (env, options) => {
10 | const devMode = options.mode !== 'production';
11 |
12 | return {
13 | optimization: {
14 | minimizer: [
15 | new TerserPlugin({ cache: true, parallel: true, sourceMap: devMode }),
16 | new OptimizeCSSAssetsPlugin({})
17 | ]
18 | },
19 | entry: {
20 | 'app': glob.sync('./vendor/**/*.js').concat(['./js/app.js'])
21 | },
22 | output: {
23 | filename: '[name].js',
24 | path: path.resolve(__dirname, '../priv/static/js'),
25 | publicPath: '/js/'
26 | },
27 | devtool: devMode ? 'eval-cheap-module-source-map' : undefined,
28 | module: {
29 | rules: [
30 | {
31 | test: /\.js$/,
32 | exclude: /node_modules/,
33 | use: {
34 | loader: 'babel-loader'
35 | }
36 | },
37 | {
38 | test: /\.[s]?css$/,
39 | use: [
40 | MiniCssExtractPlugin.loader,
41 | 'css-loader',
42 | 'sass-loader',
43 | ],
44 | }
45 | ]
46 | },
47 | plugins: [
48 | new MiniCssExtractPlugin({ filename: '../css/app.css' }),
49 | new CopyWebpackPlugin([{ from: 'static/', to: '../' }])
50 | ]
51 | .concat(devMode ? [new HardSourceWebpackPlugin()] : [])
52 | }
53 | };
54 |
--------------------------------------------------------------------------------
/test/support/data_case.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.DataCase do
2 | @moduledoc """
3 | This module defines the setup for tests requiring
4 | access to the application's data layer.
5 |
6 | You may define functions here to be used as helpers in
7 | your tests.
8 |
9 | Finally, if the test case interacts with the database,
10 | we enable the SQL sandbox, so changes done to the database
11 | are reverted at the end of every test. If you are using
12 | PostgreSQL, you can even run database tests asynchronously
13 | by setting `use Bank.DataCase, async: true`, although
14 | this option is not recommended for other databases.
15 | """
16 |
17 | use ExUnit.CaseTemplate
18 |
19 | using do
20 | quote do
21 | alias Bank.Repo
22 |
23 | import Ecto
24 | import Ecto.Changeset
25 | import Ecto.Query
26 | import Bank.DataCase
27 | end
28 | end
29 |
30 | setup tags do
31 | :ok = Ecto.Adapters.SQL.Sandbox.checkout(Bank.Repo)
32 |
33 | unless tags[:async] do
34 | Ecto.Adapters.SQL.Sandbox.mode(Bank.Repo, {:shared, self()})
35 | end
36 |
37 | :ok
38 | end
39 |
40 | @doc """
41 | A helper that transforms changeset errors into a map of messages.
42 |
43 | assert {:error, changeset} = Accounts.create_user(%{password: "short"})
44 | assert "password is too short" in errors_on(changeset).password
45 | assert %{password: ["password is too short"]} = errors_on(changeset)
46 |
47 | """
48 | def errors_on(changeset) do
49 | Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
50 | Regex.replace(~r"%{(\w+)}", message, fn _, key ->
51 | opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
52 | end)
53 | end)
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/lib/bank_web/endpoint.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.Endpoint do
2 | use Phoenix.Endpoint, otp_app: :bank
3 |
4 | # The session will be stored in the cookie and signed,
5 | # this means its contents can be read but not tampered with.
6 | # Set :encryption_salt if you would also like to encrypt it.
7 | @session_options [
8 | store: :cookie,
9 | key: "_bank_key",
10 | signing_salt: "A8FJMKiC"
11 | ]
12 |
13 | socket "/socket", BankWeb.UserSocket,
14 | websocket: true,
15 | longpoll: false
16 |
17 | socket "/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]
18 |
19 | # Serve at "/" the static files from "priv/static" directory.
20 | #
21 | # You should set gzip to true if you are running phx.digest
22 | # when deploying your static files in production.
23 | plug Plug.Static,
24 | at: "/",
25 | from: :bank,
26 | gzip: false,
27 | only: ~w(css fonts images js favicon.ico robots.txt)
28 |
29 | # Code reloading can be explicitly enabled under the
30 | # :code_reloader configuration of your endpoint.
31 | if code_reloading? do
32 | socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
33 | plug Phoenix.LiveReloader
34 | plug Phoenix.CodeReloader
35 | plug Phoenix.Ecto.CheckRepoStatus, otp_app: :bank
36 | end
37 |
38 | plug Phoenix.LiveDashboard.RequestLogger,
39 | param_key: "request_logger",
40 | cookie_key: "request_logger"
41 |
42 | plug Plug.RequestId
43 | plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
44 |
45 | plug Plug.Parsers,
46 | parsers: [:urlencoded, :multipart, :json],
47 | pass: ["*/*"],
48 | json_decoder: Phoenix.json_library()
49 |
50 | plug Plug.MethodOverride
51 | plug Plug.Head
52 | plug Plug.Session, @session_options
53 | plug BankWeb.Router
54 | end
55 |
--------------------------------------------------------------------------------
/assets/css/app.scss:
--------------------------------------------------------------------------------
1 | /* This file is for your main application css. */
2 | @import "./phoenix.css";
3 |
4 | /* LiveView specific classes for your customizations */
5 | .phx-no-feedback.invalid-feedback,
6 | .phx-no-feedback .invalid-feedback {
7 | display: none;
8 | }
9 |
10 | .phx-click-loading {
11 | opacity: 0.5;
12 | transition: opacity 1s ease-out;
13 | }
14 |
15 | .phx-disconnected{
16 | cursor: wait;
17 | }
18 | .phx-disconnected *{
19 | pointer-events: none;
20 | }
21 |
22 | .phx-modal {
23 | opacity: 1!important;
24 | position: fixed;
25 | z-index: 1;
26 | left: 0;
27 | top: 0;
28 | width: 100%;
29 | height: 100%;
30 | overflow: auto;
31 | background-color: rgb(0,0,0);
32 | background-color: rgba(0,0,0,0.4);
33 | }
34 |
35 | .phx-modal-content {
36 | background-color: #fefefe;
37 | margin: 15% auto;
38 | padding: 20px;
39 | border: 1px solid #888;
40 | width: 80%;
41 | }
42 |
43 | .phx-modal-close {
44 | color: #aaa;
45 | float: right;
46 | font-size: 28px;
47 | font-weight: bold;
48 | }
49 |
50 | .phx-modal-close:hover,
51 | .phx-modal-close:focus {
52 | color: black;
53 | text-decoration: none;
54 | cursor: pointer;
55 | }
56 |
57 |
58 | /* Alerts and form errors */
59 | .alert {
60 | padding: 15px;
61 | margin-bottom: 20px;
62 | border: 1px solid transparent;
63 | border-radius: 4px;
64 | }
65 | .alert-info {
66 | color: #31708f;
67 | background-color: #d9edf7;
68 | border-color: #bce8f1;
69 | }
70 | .alert-warning {
71 | color: #8a6d3b;
72 | background-color: #fcf8e3;
73 | border-color: #faebcc;
74 | }
75 | .alert-danger {
76 | color: #a94442;
77 | background-color: #f2dede;
78 | border-color: #ebccd1;
79 | }
80 | .alert p {
81 | margin-bottom: 0;
82 | }
83 | .alert:empty {
84 | display: none;
85 | }
86 | .invalid-feedback {
87 | color: #a94442;
88 | display: block;
89 | margin: -1rem 0 2rem;
90 | }
91 |
--------------------------------------------------------------------------------
/lib/bank_web/telemetry.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb.Telemetry do
2 | use Supervisor
3 | import Telemetry.Metrics
4 |
5 | def start_link(arg) do
6 | Supervisor.start_link(__MODULE__, arg, name: __MODULE__)
7 | end
8 |
9 | @impl true
10 | def init(_arg) do
11 | children = [
12 | # Telemetry poller will execute the given period measurements
13 | # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics
14 | {:telemetry_poller, measurements: periodic_measurements(), period: 10_000}
15 | # Add reporters as children of your supervision tree.
16 | # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()}
17 | ]
18 |
19 | Supervisor.init(children, strategy: :one_for_one)
20 | end
21 |
22 | def metrics do
23 | [
24 | # Phoenix Metrics
25 | summary("phoenix.endpoint.stop.duration",
26 | unit: {:native, :millisecond}
27 | ),
28 | summary("phoenix.router_dispatch.stop.duration",
29 | tags: [:route],
30 | unit: {:native, :millisecond}
31 | ),
32 |
33 | # Database Metrics
34 | summary("bank.repo.query.total_time", unit: {:native, :millisecond}),
35 | summary("bank.repo.query.decode_time", unit: {:native, :millisecond}),
36 | summary("bank.repo.query.query_time", unit: {:native, :millisecond}),
37 | summary("bank.repo.query.queue_time", unit: {:native, :millisecond}),
38 | summary("bank.repo.query.idle_time", unit: {:native, :millisecond}),
39 |
40 | # VM Metrics
41 | summary("vm.memory.total", unit: {:byte, :kilobyte}),
42 | summary("vm.total_run_queue_lengths.total"),
43 | summary("vm.total_run_queue_lengths.cpu"),
44 | summary("vm.total_run_queue_lengths.io")
45 | ]
46 | end
47 |
48 | defp periodic_measurements do
49 | [
50 | # A module, function and arguments to be invoked periodically.
51 | # This function must call :telemetry.execute/3 and a metric must be added above.
52 | # {BankWeb, :count_users, []}
53 | ]
54 | end
55 | end
56 |
--------------------------------------------------------------------------------
/config/prod.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # For production, don't forget to configure the url host
4 | # to something meaningful, Phoenix uses this information
5 | # when generating URLs.
6 | #
7 | # Note we also include the path to a cache manifest
8 | # containing the digested version of static files. This
9 | # manifest is generated by the `mix phx.digest` task,
10 | # which you should run after static files are built and
11 | # before starting your production server.
12 | config :bank, BankWeb.Endpoint,
13 | url: [host: "example.com", port: 80],
14 | cache_static_manifest: "priv/static/cache_manifest.json"
15 |
16 | # Do not print debug messages in production
17 | config :logger, level: :info
18 |
19 | # ## SSL Support
20 | #
21 | # To get SSL working, you will need to add the `https` key
22 | # to the previous section and set your `:url` port to 443:
23 | #
24 | # config :bank, BankWeb.Endpoint,
25 | # ...
26 | # url: [host: "example.com", port: 443],
27 | # https: [
28 | # port: 443,
29 | # cipher_suite: :strong,
30 | # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
31 | # certfile: System.get_env("SOME_APP_SSL_CERT_PATH"),
32 | # transport_options: [socket_opts: [:inet6]]
33 | # ]
34 | #
35 | # The `cipher_suite` is set to `:strong` to support only the
36 | # latest and more secure SSL ciphers. This means old browsers
37 | # and clients may not be supported. You can set it to
38 | # `:compatible` for wider support.
39 | #
40 | # `:keyfile` and `:certfile` expect an absolute path to the key
41 | # and cert in disk or a relative path inside priv, for example
42 | # "priv/ssl/server.key". For all supported SSL configuration
43 | # options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
44 | #
45 | # We also recommend setting `force_ssl` in your endpoint, ensuring
46 | # no data is ever sent via http, always redirecting to https:
47 | #
48 | # config :bank, BankWeb.Endpoint,
49 | # force_ssl: [hsts: true]
50 | #
51 | # Check `Plug.SSL` for all available options in `force_ssl`.
52 |
53 | # Finally import the config/prod.secret.exs which loads secrets
54 | # and configuration from environment variables.
55 | import_config "prod.secret.exs"
56 |
--------------------------------------------------------------------------------
/mix.exs:
--------------------------------------------------------------------------------
1 | defmodule Bank.MixProject do
2 | use Mix.Project
3 |
4 | def project do
5 | [
6 | app: :bank,
7 | version: "0.1.0",
8 | elixir: "~> 1.7",
9 | elixirc_paths: elixirc_paths(Mix.env()),
10 | compilers: [:phoenix] ++ Mix.compilers(),
11 | start_permanent: Mix.env() == :prod,
12 | aliases: aliases(),
13 | deps: deps()
14 | ]
15 | end
16 |
17 | # Configuration for the OTP application.
18 | #
19 | # Type `mix help compile.app` for more information.
20 | def application do
21 | [
22 | mod: {Bank.Application, []},
23 | extra_applications: [:logger, :runtime_tools]
24 | ]
25 | end
26 |
27 | # Specifies which paths to compile per environment.
28 | defp elixirc_paths(:test), do: ["lib", "test/support"]
29 | defp elixirc_paths(_), do: ["lib"]
30 |
31 | # Specifies your project dependencies.
32 | # Type `mix help deps` for examples and options.
33 | defp deps do
34 | [
35 | {:commanded, "~> 1.2.0"},
36 | {:commanded_eventstore_adapter, "~> 1.2.0"},
37 | {:commanded_ecto_projections, "~> 1.2"},
38 | {:eventstore, "~> 1.3.0"},
39 | {:phoenix, "~> 1.5.9"},
40 | {:phoenix_ecto, "~> 4.1"},
41 | {:ecto_sql, "~> 3.4"},
42 | {:postgrex, ">= 0.0.0"},
43 | {:phoenix_live_view, "~> 0.15.1"},
44 | {:floki, ">= 0.30.0", only: :test},
45 | {:phoenix_html, "~> 2.11"},
46 | {:phoenix_live_reload, "~> 1.2", only: :dev},
47 | {:phoenix_live_dashboard, "~> 0.4"},
48 | {:telemetry_metrics, "~> 0.4"},
49 | {:telemetry_poller, "~> 0.4"},
50 | {:jason, "~> 1.0"},
51 | {:plug_cowboy, "~> 2.0"}
52 | ]
53 | end
54 |
55 | # Aliases are shortcuts or tasks specific to the current project.
56 | # For example, to install project dependencies and perform other setup tasks, run:
57 | #
58 | # $ mix setup
59 | #
60 | # See the documentation for `Mix` for more info on aliases.
61 | defp aliases do
62 | [
63 | setup: ["deps.get", "ecto.setup", "cmd npm install --prefix assets"],
64 | "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
65 | "ecto.reset": ["ecto.drop", "ecto.setup"],
66 | test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
67 | ]
68 | end
69 | end
70 |
--------------------------------------------------------------------------------
/config/dev.exs:
--------------------------------------------------------------------------------
1 | use Mix.Config
2 |
3 | # Configure your database
4 | config :bank, Bank.Repo,
5 | username: "postgres",
6 | password: "postgres",
7 | database: "bank_dev",
8 | hostname: "localhost",
9 | show_sensitive_data_on_connection_error: true,
10 | pool_size: 10
11 |
12 | # For development, we disable any cache and enable
13 | # debugging and code reloading.
14 | #
15 | # The watchers configuration can be used to run external
16 | # watchers to your application. For example, we use it
17 | # with webpack to recompile .js and .css sources.
18 | config :bank, BankWeb.Endpoint,
19 | http: [port: 4000],
20 | debug_errors: true,
21 | code_reloader: true,
22 | check_origin: false,
23 | watchers: [
24 | node: [
25 | "node_modules/webpack/bin/webpack.js",
26 | "--mode",
27 | "development",
28 | "--watch-stdin",
29 | cd: Path.expand("../assets", __DIR__)
30 | ]
31 | ]
32 |
33 | # ## SSL Support
34 | #
35 | # In order to use HTTPS in development, a self-signed
36 | # certificate can be generated by running the following
37 | # Mix task:
38 | #
39 | # mix phx.gen.cert
40 | #
41 | # Note that this task requires Erlang/OTP 20 or later.
42 | # Run `mix help phx.gen.cert` for more information.
43 | #
44 | # The `http:` config above can be replaced with:
45 | #
46 | # https: [
47 | # port: 4001,
48 | # cipher_suite: :strong,
49 | # keyfile: "priv/cert/selfsigned_key.pem",
50 | # certfile: "priv/cert/selfsigned.pem"
51 | # ],
52 | #
53 | # If desired, both `http:` and `https:` keys can be
54 | # configured to run both http and https servers on
55 | # different ports.
56 |
57 | # Watch static and templates for browser reloading.
58 | config :bank, BankWeb.Endpoint,
59 | live_reload: [
60 | patterns: [
61 | ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
62 | ~r"lib/bank_web/(live|views)/.*(ex)$",
63 | ~r"lib/bank_web/templates/.*(eex)$"
64 | ]
65 | ]
66 |
67 | # Do not include metadata nor timestamps in development logs
68 | config :logger, :console, format: "[$level] $message\n", level: :info
69 |
70 | # Set a higher stacktrace during development. Avoid configuring such
71 | # in production as building large stacktraces may be expensive.
72 | config :phoenix, :stacktrace_depth, 20
73 |
74 | # Initialize plugs at runtime for faster development compilation
75 | config :phoenix, :plug_init_mode, :runtime
76 |
--------------------------------------------------------------------------------
/lib/bank_web.ex:
--------------------------------------------------------------------------------
1 | defmodule BankWeb do
2 | @moduledoc """
3 | The entrypoint for defining your web interface, such
4 | as controllers, views, channels and so on.
5 |
6 | This can be used in your application as:
7 |
8 | use BankWeb, :controller
9 | use BankWeb, :view
10 |
11 | The definitions below will be executed for every view,
12 | controller, etc, so keep them short and clean, focused
13 | on imports, uses and aliases.
14 |
15 | Do NOT define functions inside the quoted expressions
16 | below. Instead, define any helper function in modules
17 | and import those modules here.
18 | """
19 |
20 | def controller do
21 | quote do
22 | use Phoenix.Controller, namespace: BankWeb
23 |
24 | import Plug.Conn
25 | alias BankWeb.Router.Helpers, as: Routes
26 | end
27 | end
28 |
29 | def view do
30 | quote do
31 | use Phoenix.View,
32 | root: "lib/bank_web/templates",
33 | namespace: BankWeb
34 |
35 | # Import convenience functions from controllers
36 | import Phoenix.Controller,
37 | only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
38 |
39 | # Include shared imports and aliases for views
40 | unquote(view_helpers())
41 | end
42 | end
43 |
44 | def live_view do
45 | quote do
46 | use Phoenix.LiveView,
47 | layout: {BankWeb.LayoutView, "live.html"}
48 |
49 | unquote(view_helpers())
50 | end
51 | end
52 |
53 | def live_component do
54 | quote do
55 | use Phoenix.LiveComponent
56 |
57 | unquote(view_helpers())
58 | end
59 | end
60 |
61 | def router do
62 | quote do
63 | use Phoenix.Router
64 |
65 | import Plug.Conn
66 | import Phoenix.Controller
67 | import Phoenix.LiveView.Router
68 | end
69 | end
70 |
71 | def channel do
72 | quote do
73 | use Phoenix.Channel
74 | end
75 | end
76 |
77 | defp view_helpers do
78 | quote do
79 | # Use all HTML functionality (forms, tags, etc)
80 | use Phoenix.HTML
81 |
82 | # Import LiveView helpers (live_render, live_component, live_patch, etc)
83 | import Phoenix.LiveView.Helpers
84 |
85 | # Import basic rendering functionality (render, render_layout, etc)
86 | import Phoenix.View
87 |
88 | import BankWeb.ErrorHelpers
89 | alias BankWeb.Router.Helpers, as: Routes
90 | end
91 | end
92 |
93 | @doc """
94 | When used, dispatch to the appropriate controller/view/etc.
95 | """
96 | defmacro __using__(which) when is_atom(which) do
97 | apply(__MODULE__, which, [])
98 | end
99 | end
100 |
--------------------------------------------------------------------------------
/lib/bank/core/accounts/account.ex:
--------------------------------------------------------------------------------
1 | defmodule Bank.Core.Accounts.Account do
2 | alias Bank.Core.Commands.{
3 | DepositMoney,
4 | WithdrawMoney,
5 | SendMoneyToAccount,
6 | ReceiveMoneyFromAccount,
7 | FailMoneyTransfer
8 | }
9 |
10 | alias Bank.Core.Events.{
11 | MoneyDeposited,
12 | MoneyWithdrawn,
13 | JournalEntryCreated,
14 | AccountOpened,
15 | MoneyReceivedFromAccount,
16 | MoneyReceivedFromAccountFailed,
17 | MoneySentToAccount,
18 | MoneyTransferFailed
19 | }
20 |
21 | alias Bank.Core.Accounts.Account
22 |
23 | @type t() :: %__MODULE__{id: binary(), balance: integer()}
24 | defstruct [:id, balance: 0]
25 |
26 | def execute(%Account{}, %DepositMoney{account_id: "000-000"}),
27 | do: {:error, :unable_to_create_account}
28 |
29 | def execute(%Account{id: nil}, %DepositMoney{} = cmd) do
30 | [
31 | %AccountOpened{
32 | account_id: cmd.account_id
33 | },
34 | %MoneyDeposited{
35 | account_id: cmd.account_id,
36 | amount: cmd.amount
37 | },
38 | %JournalEntryCreated{
39 | journal_entry_uuid: Ecto.UUID.generate(),
40 | debit: %{"#{cmd.account_id}" => cmd.amount},
41 | credit: %{"000-000" => cmd.amount}
42 | }
43 | ]
44 | end
45 |
46 | def execute(%Account{id: nil}, %ReceiveMoneyFromAccount{} = cmd) do
47 | %MoneyReceivedFromAccountFailed{
48 | transaction_id: cmd.transaction_id,
49 | from_account_id: cmd.from_account_id,
50 | to_account_id: cmd.to_account_id,
51 | amount: cmd.amount
52 | }
53 | end
54 |
55 | def execute(%Account{id: nil}, _cmd),
56 | do: {:error, :not_found}
57 |
58 | def execute(%Account{}, %DepositMoney{} = cmd) do
59 | [
60 | %MoneyDeposited{
61 | account_id: cmd.account_id,
62 | amount: cmd.amount
63 | },
64 | %JournalEntryCreated{
65 | journal_entry_uuid: Ecto.UUID.generate(),
66 | debit: %{"#{cmd.account_id}" => cmd.amount},
67 | credit: %{"000-000" => cmd.amount}
68 | }
69 | ]
70 | end
71 |
72 | def execute(%Account{}, %WithdrawMoney{} = cmd) do
73 | [
74 | %MoneyWithdrawn{
75 | account_id: cmd.account_id,
76 | amount: cmd.amount
77 | },
78 | %JournalEntryCreated{
79 | journal_entry_uuid: Ecto.UUID.generate(),
80 | debit: %{"000-000" => cmd.amount},
81 | credit: %{"#{cmd.account_id}" => cmd.amount}
82 | }
83 | ]
84 | end
85 |
86 | def execute(%Account{} = state, %ReceiveMoneyFromAccount{} = cmd) do
87 | [
88 | %MoneyReceivedFromAccount{
89 | transaction_id: cmd.transaction_id,
90 | from_account_id: cmd.from_account_id,
91 | to_account_id: state.id,
92 | amount: cmd.amount
93 | },
94 | %JournalEntryCreated{
95 | journal_entry_uuid: Ecto.UUID.generate(),
96 | credit: %{"#{cmd.transaction_id}" => cmd.amount},
97 | debit: %{"#{cmd.to_account_id}" => cmd.amount}
98 | }
99 | ]
100 | end
101 |
102 | def execute(%Account{} = state, %FailMoneyTransfer{} = cmd) do
103 | [
104 | %MoneyTransferFailed{
105 | transaction_id: cmd.transaction_id,
106 | from_account_id: state.id,
107 | to_account_id: cmd.to_account_id,
108 | amount: cmd.amount
109 | },
110 | %JournalEntryCreated{
111 | journal_entry_uuid: Ecto.UUID.generate(),
112 | credit: %{"#{cmd.transaction_id}" => cmd.amount},
113 | debit: %{"#{state.id}" => cmd.amount}
114 | }
115 | ]
116 | end
117 |
118 | def execute(%Account{balance: balance}, %SendMoneyToAccount{amount: amount})
119 | when balance < amount do
120 | {:error, :insufficient_balance}
121 | end
122 |
123 | def execute(%Account{} = state, %SendMoneyToAccount{} = cmd) do
124 | transaction_id = Ecto.UUID.generate()
125 |
126 | [
127 | %MoneySentToAccount{
128 | transaction_id: transaction_id,
129 | from_account_id: state.id,
130 | to_account_id: cmd.to_account_id,
131 | amount: cmd.amount
132 | },
133 | %JournalEntryCreated{
134 | journal_entry_uuid: Ecto.UUID.generate(),
135 | debit: %{"#{transaction_id}" => cmd.amount},
136 | credit: %{"#{state.id}" => cmd.amount}
137 | }
138 | ]
139 | end
140 |
141 | def apply(state, %MoneySentToAccount{} = evt) do
142 | %{state | balance: state.balance - evt.amount}
143 | end
144 |
145 | def apply(state, %MoneyTransferFailed{} = evt) do
146 | %{state | balance: state.balance + evt.amount}
147 | end
148 |
149 | def apply(state, %MoneyReceivedFromAccount{} = evt) do
150 | %{state | balance: state.balance + evt.amount}
151 | end
152 |
153 | def apply(state, %AccountOpened{} = evt) do
154 | %{state | id: evt.account_id}
155 | end
156 |
157 | def apply(state, %MoneyDeposited{} = evt) do
158 | %{state | balance: state.balance + evt.amount}
159 | end
160 |
161 | def apply(state, %MoneyWithdrawn{} = evt) do
162 | %{state | balance: state.balance - evt.amount}
163 | end
164 |
165 | def apply(state, %JournalEntryCreated{}), do: state
166 |
167 | def apply(state, %MoneyReceivedFromAccountFailed{}), do: state
168 | end
169 |
--------------------------------------------------------------------------------
/assets/css/phoenix.css:
--------------------------------------------------------------------------------
1 | /* Includes some default style for the starter application.
2 | * This can be safely deleted to start fresh.
3 | */
4 |
5 | /* Milligram v1.3.0 https://milligram.github.io
6 | * Copyright (c) 2017 CJ Patoilo Licensed under the MIT license
7 | */
8 |
9 | *,*:after,*:before{box-sizing:inherit}html{box-sizing:border-box;font-size:62.5%}body{color:#000000;font-family:'Helvetica', 'Arial', sans-serif;font-size:1.6em;font-weight:300;line-height:1.6}blockquote{border-left:0.3rem solid #d1d1d1;margin-left:0;margin-right:0;padding:1rem 1.5rem}blockquote *:last-child{margin-bottom:0}.button,button,input[type='button'],input[type='reset'],input[type='submit']{background-color:#0069d9;border:0.1rem solid #0069d9;border-radius:.4rem;color:#fff;cursor:pointer;display:inline-block;font-size:1.1rem;font-weight:700;height:3.8rem;letter-spacing:.1rem;line-height:3.8rem;padding:0 3.0rem;text-align:center;text-decoration:none;text-transform:uppercase;white-space:nowrap}.button:focus,.button:hover,button:focus,button:hover,input[type='button']:focus,input[type='button']:hover,input[type='reset']:focus,input[type='reset']:hover,input[type='submit']:focus,input[type='submit']:hover{background-color:#606c76;border-color:#606c76;color:#fff;outline:0}.button[disabled],button[disabled],input[type='button'][disabled],input[type='reset'][disabled],input[type='submit'][disabled]{cursor:default;opacity:.5}.button[disabled]:focus,.button[disabled]:hover,button[disabled]:focus,button[disabled]:hover,input[type='button'][disabled]:focus,input[type='button'][disabled]:hover,input[type='reset'][disabled]:focus,input[type='reset'][disabled]:hover,input[type='submit'][disabled]:focus,input[type='submit'][disabled]:hover{background-color:#0069d9;border-color:#0069d9}.button.button-outline,button.button-outline,input[type='button'].button-outline,input[type='reset'].button-outline,input[type='submit'].button-outline{background-color:transparent;color:#0069d9}.button.button-outline:focus,.button.button-outline:hover,button.button-outline:focus,button.button-outline:hover,input[type='button'].button-outline:focus,input[type='button'].button-outline:hover,input[type='reset'].button-outline:focus,input[type='reset'].button-outline:hover,input[type='submit'].button-outline:focus,input[type='submit'].button-outline:hover{background-color:transparent;border-color:#606c76;color:#606c76}.button.button-outline[disabled]:focus,.button.button-outline[disabled]:hover,button.button-outline[disabled]:focus,button.button-outline[disabled]:hover,input[type='button'].button-outline[disabled]:focus,input[type='button'].button-outline[disabled]:hover,input[type='reset'].button-outline[disabled]:focus,input[type='reset'].button-outline[disabled]:hover,input[type='submit'].button-outline[disabled]:focus,input[type='submit'].button-outline[disabled]:hover{border-color:inherit;color:#0069d9}.button.button-clear,button.button-clear,input[type='button'].button-clear,input[type='reset'].button-clear,input[type='submit'].button-clear{background-color:transparent;border-color:transparent;color:#0069d9}.button.button-clear:focus,.button.button-clear:hover,button.button-clear:focus,button.button-clear:hover,input[type='button'].button-clear:focus,input[type='button'].button-clear:hover,input[type='reset'].button-clear:focus,input[type='reset'].button-clear:hover,input[type='submit'].button-clear:focus,input[type='submit'].button-clear:hover{background-color:transparent;border-color:transparent;color:#606c76}.button.button-clear[disabled]:focus,.button.button-clear[disabled]:hover,button.button-clear[disabled]:focus,button.button-clear[disabled]:hover,input[type='button'].button-clear[disabled]:focus,input[type='button'].button-clear[disabled]:hover,input[type='reset'].button-clear[disabled]:focus,input[type='reset'].button-clear[disabled]:hover,input[type='submit'].button-clear[disabled]:focus,input[type='submit'].button-clear[disabled]:hover{color:#0069d9}code{background:#f4f5f6;border-radius:.4rem;font-size:86%;margin:0 .2rem;padding:.2rem .5rem;white-space:nowrap}pre{background:#f4f5f6;border-left:0.3rem solid #0069d9;overflow-y:hidden}pre>code{border-radius:0;display:block;padding:1rem 1.5rem;white-space:pre}hr{border:0;border-top:0.1rem solid #f4f5f6;margin:3.0rem 0}input[type='email'],input[type='number'],input[type='password'],input[type='search'],input[type='tel'],input[type='text'],input[type='url'],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:0.1rem solid #d1d1d1;border-radius:.4rem;box-shadow:none;box-sizing:inherit;height:3.8rem;padding:.6rem 1.0rem;width:100%}input[type='email']:focus,input[type='number']:focus,input[type='password']:focus,input[type='search']:focus,input[type='tel']:focus,input[type='text']:focus,input[type='url']:focus,textarea:focus,select:focus{border-color:#0069d9;outline:0}select{background:url('data:image/svg+xml;utf8,') center right no-repeat;padding-right:3.0rem}select:focus{background-image:url('data:image/svg+xml;utf8,')}textarea{min-height:6.5rem}label,legend{display:block;font-size:1.6rem;font-weight:700;margin-bottom:.5rem}fieldset{border-width:0;padding:0}input[type='checkbox'],input[type='radio']{display:inline}.label-inline{display:inline-block;font-weight:normal;margin-left:.5rem}.row{display:flex;flex-direction:column;padding:0;width:100%}.row.row-no-padding{padding:0}.row.row-no-padding>.column{padding:0}.row.row-wrap{flex-wrap:wrap}.row.row-top{align-items:flex-start}.row.row-bottom{align-items:flex-end}.row.row-center{align-items:center}.row.row-stretch{align-items:stretch}.row.row-baseline{align-items:baseline}.row .column{display:block;flex:1 1 auto;margin-left:0;max-width:100%;width:100%}.row .column.column-offset-10{margin-left:10%}.row .column.column-offset-20{margin-left:20%}.row .column.column-offset-25{margin-left:25%}.row .column.column-offset-33,.row .column.column-offset-34{margin-left:33.3333%}.row .column.column-offset-50{margin-left:50%}.row .column.column-offset-66,.row .column.column-offset-67{margin-left:66.6666%}.row .column.column-offset-75{margin-left:75%}.row .column.column-offset-80{margin-left:80%}.row .column.column-offset-90{margin-left:90%}.row .column.column-10{flex:0 0 10%;max-width:10%}.row .column.column-20{flex:0 0 20%;max-width:20%}.row .column.column-25{flex:0 0 25%;max-width:25%}.row .column.column-33,.row .column.column-34{flex:0 0 33.3333%;max-width:33.3333%}.row .column.column-40{flex:0 0 40%;max-width:40%}.row .column.column-50{flex:0 0 50%;max-width:50%}.row .column.column-60{flex:0 0 60%;max-width:60%}.row .column.column-66,.row .column.column-67{flex:0 0 66.6666%;max-width:66.6666%}.row .column.column-75{flex:0 0 75%;max-width:75%}.row .column.column-80{flex:0 0 80%;max-width:80%}.row .column.column-90{flex:0 0 90%;max-width:90%}.row .column .column-top{align-self:flex-start}.row .column .column-bottom{align-self:flex-end}.row .column .column-center{-ms-grid-row-align:center;align-self:center}@media (min-width: 40rem){.row{flex-direction:row;margin-left:-1.0rem;width:calc(100% + 2.0rem)}.row .column{margin-bottom:inherit;padding:0 1.0rem}}a{color:#0069d9;text-decoration:none}a:focus,a:hover{color:#606c76}dl,ol,ul{list-style:none;margin-top:0;padding-left:0}dl dl,dl ol,dl ul,ol dl,ol ol,ol ul,ul dl,ul ol,ul ul{font-size:90%;margin:1.5rem 0 1.5rem 3.0rem}ol{list-style:decimal inside}ul{list-style:circle inside}.button,button,dd,dt,li{margin-bottom:1.0rem}fieldset,input,select,textarea{margin-bottom:1.5rem}blockquote,dl,figure,form,ol,p,pre,table,ul{margin-bottom:2.5rem}table{border-spacing:0;width:100%}td,th{border-bottom:0.1rem solid #e1e1e1;padding:1.2rem 1.5rem;text-align:left}td:first-child,th:first-child{padding-left:0}td:last-child,th:last-child{padding-right:0}b,strong{font-weight:bold}p{margin-top:0}h1,h2,h3,h4,h5,h6{font-weight:300;letter-spacing:-.1rem;margin-bottom:2.0rem;margin-top:0}h1{font-size:4.6rem;line-height:1.2}h2{font-size:3.6rem;line-height:1.25}h3{font-size:2.8rem;line-height:1.3}h4{font-size:2.2rem;letter-spacing:-.08rem;line-height:1.35}h5{font-size:1.8rem;letter-spacing:-.05rem;line-height:1.5}h6{font-size:1.6rem;letter-spacing:0;line-height:1.4}img{max-width:100%}.clearfix:after{clear:both;content:' ';display:table}.float-left{float:left}.float-right{float:right}
10 |
11 | /* General style */
12 | h1{font-size: 3.6rem; line-height: 1.25}
13 | h2{font-size: 2.8rem; line-height: 1.3}
14 | h3{font-size: 2.2rem; letter-spacing: -.08rem; line-height: 1.35}
15 | h4{font-size: 1.8rem; letter-spacing: -.05rem; line-height: 1.5}
16 | h5{font-size: 1.6rem; letter-spacing: 0; line-height: 1.4}
17 | h6{font-size: 1.4rem; letter-spacing: 0; line-height: 1.2}
18 | pre{padding: 1em;}
19 |
20 | .container{
21 | margin: 0 auto;
22 | max-width: 80.0rem;
23 | padding: 0 2.0rem;
24 | position: relative;
25 | width: 100%
26 | }
27 | select {
28 | width: auto;
29 | }
30 |
31 | /* Phoenix promo and logo */
32 | .phx-hero {
33 | text-align: center;
34 | border-bottom: 1px solid #e3e3e3;
35 | background: #eee;
36 | border-radius: 6px;
37 | padding: 3em 3em 1em;
38 | margin-bottom: 3rem;
39 | font-weight: 200;
40 | font-size: 120%;
41 | }
42 | .phx-hero input {
43 | background: #ffffff;
44 | }
45 | .phx-logo {
46 | min-width: 300px;
47 | margin: 1rem;
48 | display: block;
49 | }
50 | .phx-logo img {
51 | width: auto;
52 | display: block;
53 | }
54 |
55 | /* Headers */
56 | header {
57 | width: 100%;
58 | background: #fdfdfd;
59 | border-bottom: 1px solid #eaeaea;
60 | margin-bottom: 2rem;
61 | }
62 | header section {
63 | align-items: center;
64 | display: flex;
65 | flex-direction: column;
66 | justify-content: space-between;
67 | }
68 | header section :first-child {
69 | order: 2;
70 | }
71 | header section :last-child {
72 | order: 1;
73 | }
74 | header nav ul,
75 | header nav li {
76 | margin: 0;
77 | padding: 0;
78 | display: block;
79 | text-align: right;
80 | white-space: nowrap;
81 | }
82 | header nav ul {
83 | margin: 1rem;
84 | margin-top: 0;
85 | }
86 | header nav a {
87 | display: block;
88 | }
89 |
90 | @media (min-width: 40.0rem) { /* Small devices (landscape phones, 576px and up) */
91 | header section {
92 | flex-direction: row;
93 | }
94 | header nav ul {
95 | margin: 1rem;
96 | }
97 | .phx-logo {
98 | flex-basis: 527px;
99 | margin: 2rem 1rem;
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/mix.lock:
--------------------------------------------------------------------------------
1 | %{
2 | "backoff": {:hex, :backoff, "1.1.6", "83b72ed2108ba1ee8f7d1c22e0b4a00cfe3593a67dbc792799e8cce9f42f796b", [:rebar3], [], "hexpm", "cf0cfff8995fb20562f822e5cc47d8ccf664c5ecdc26a684cbe85c225f9d7c39"},
3 | "commanded": {:hex, :commanded, "1.2.0", "d0c604e885132cbca875c238b741e0e2059c54395b4087d3d91763ebf06254d2", [:mix], [{:backoff, "~> 1.1", [hex: :backoff, repo: "hexpm", optional: false]}, {:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}], "hexpm", "64e51d04773d0b74568ea1d0886c57e350139438096992ad3456d9d80363d0b5"},
4 | "commanded_ecto_projections": {:hex, :commanded_ecto_projections, "1.2.1", "ad1e274d2458a4dab268deb95601e0fb644ab141fb14995f540c66de1788731f", [:mix], [{:commanded, "~> 1.2", [hex: :commanded, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.5", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "461a1e3489c56f6e7564f54e4200a41afcab5618fdf396e0c00269613328f00c"},
5 | "commanded_eventstore_adapter": {:hex, :commanded_eventstore_adapter, "1.2.0", "a311247d70ce775b2d4b5484d09dbefd27911025ac7deb3e5b79b79f243e6fb1", [:mix], [{:commanded, "~> 1.2", [hex: :commanded, repo: "hexpm", optional: false]}, {:eventstore, "~> 1.1", [hex: :eventstore, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "b2cce46dfccf400f3956322a72997e591c0f833d0c20557e1074c7609564dae2"},
6 | "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
7 | "cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
8 | "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
9 | "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
10 | "db_connection": {:hex, :db_connection, "2.4.0", "d04b1b73795dae60cead94189f1b8a51cc9e1f911c234cc23074017c43c031e5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad416c21ad9f61b3103d254a71b63696ecadb6a917b36f563921e0de00d7d7c8"},
11 | "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
12 | "ecto": {:hex, :ecto, "3.6.2", "efdf52acfc4ce29249bab5417415bd50abd62db7b0603b8bab0d7b996548c2bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "efad6dfb04e6f986b8a3047822b0f826d9affe8e4ebdd2aeedbfcb14fd48884e"},
13 | "ecto_sql": {:hex, :ecto_sql, "3.6.2", "9526b5f691701a5181427634c30655ac33d11e17e4069eff3ae1176c764e0ba3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.6.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5ec9d7e6f742ea39b63aceaea9ac1d1773d574ea40df5a53ef8afbd9242fdb6b"},
14 | "elixir_uuid": {:hex, :elixir_uuid, "1.2.1", "dce506597acb7e6b0daeaff52ff6a9043f5919a4c3315abb4143f0b00378c097", [:mix], [], "hexpm", "f7eba2ea6c3555cea09706492716b0d87397b88946e6380898c2889d68585752"},
15 | "eventstore": {:hex, :eventstore, "1.3.1", "011fd090cfc77baefb2dd0695dd3322433e187fb946f8450644932ca6e1fdd71", [:mix], [{:elixir_uuid, "~> 1.2", [hex: :elixir_uuid, repo: "hexpm", optional: false]}, {:fsm, "~> 0.3", [hex: :fsm, repo: "hexpm", optional: false]}, {:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "6f26540b9282b16395be7b6989ec6f014628da231166f0d277e5e02699f7bee0"},
16 | "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
17 | "floki": {:hex, :floki, "0.31.0", "f05ee8a8e6a3ced4e62beeb2c79a63bc8e12ab98fbaaf6e6a3d9b76b1278e23f", [:mix], [{:html_entities, "~> 0.5.0", [hex: :html_entities, repo: "hexpm", optional: false]}], "hexpm", "b05afa372f5c345a5bf240ac25ea1f0f3d5fcfd7490ac0beeb4a203f9444891e"},
18 | "fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm", "fbf0d53f89e9082b326b0b5828b94b4c549ff9d1452bbfd00b4d1ac082208e96"},
19 | "gen_stage": {:hex, :gen_stage, "1.1.1", "78d83b14ca742f4c252770bcdf674d83378ca41579c387c57e2f06d70f596317", [:mix], [], "hexpm", "eb90d2d72609050a66ce42b7d4a69323a60c892a09ead0680d5d8ef16b9a034e"},
20 | "html_entities": {:hex, :html_entities, "0.5.2", "9e47e70598da7de2a9ff6af8758399251db6dbb7eebe2b013f2bbd2515895c3c", [:mix], [], "hexpm", "c53ba390403485615623b9531e97696f076ed415e8d8058b1dbaa28181f4fdcc"},
21 | "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
22 | "mime": {:hex, :mime, "2.0.1", "0de4c81303fe07806ebc2494d5321ce8fb4df106e34dd5f9d787b637ebadc256", [:mix], [], "hexpm", "7a86b920d2aedce5fb6280ac8261ac1a739ae6c1a1ad38f5eadf910063008942"},
23 | "phoenix": {:hex, :phoenix, "1.5.10", "3ee7d5c17ff9626d72d374d8fc8909bf00f4323fd15549fbe3abbbd38b5299c8", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f9c2eaa5a8fe5a412610c6aa84ccdb6f3e92f333d4df7fbaeb0d5a157dbfb48d"},
24 | "phoenix_ecto": {:hex, :phoenix_ecto, "4.3.0", "2c69a452c2e0ee8c93345ae1cdc1696ef4877ff9cbb15c305def41960c3c4ebf", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "0ac491924217550c8f42c81c1f390b5d81517d12ceaf9abf3e701156760a848e"},
25 | "phoenix_html": {:hex, :phoenix_html, "2.14.3", "51f720d0d543e4e157ff06b65de38e13303d5778a7919bcc696599e5934271b8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "efd697a7fff35a13eeeb6b43db884705cba353a1a41d127d118fda5f90c8e80f"},
26 | "phoenix_live_dashboard": {:hex, :phoenix_live_dashboard, "0.4.0", "87990e68b60213d7487e65814046f9a2bed4a67886c943270125913499b3e5c3", [:mix], [{:ecto_psql_extras, "~> 0.4.1 or ~> 0.5", [hex: :ecto_psql_extras, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.14.1 or ~> 2.15", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:phoenix_live_view, "~> 0.15.0", [hex: :phoenix_live_view, repo: "hexpm", optional: false]}, {:telemetry_metrics, "~> 0.4.0 or ~> 0.5.0 or ~> 0.6.0", [hex: :telemetry_metrics, repo: "hexpm", optional: false]}], "hexpm", "8d52149e58188e9e4497cc0d8900ab94d9b66f96998ec38c47c7a4f8f4f50e57"},
27 | "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.3.3", "3a53772a6118d5679bf50fc1670505a290e32a1d195df9e069d8c53ab040c054", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm", "766796676e5f558dbae5d1bdb066849673e956005e3730dfd5affd7a6da4abac"},
28 | "phoenix_live_view": {:hex, :phoenix_live_view, "0.15.7", "09720b8e5151b3ca8ef739cd7626d4feb987c69ba0b509c9bbdb861d5a365881", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix, "~> 1.5.7", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14", [hex: :phoenix_html, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.2 or ~> 0.5", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a756cf662420272d0f1b3b908cce5222163b5a95aa9bab404f9d29aff53276e"},
29 | "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
30 | "plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"},
31 | "plug_cowboy": {:hex, :plug_cowboy, "2.5.1", "7cc96ff645158a94cf3ec9744464414f02287f832d6847079adfe0b58761cbd0", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "107d0a5865fa92bcb48e631cc0729ae9ccfa0a9f9a1bd8f01acb513abf1c2d64"},
32 | "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
33 | "postgrex": {:hex, :postgrex, "0.15.10", "2809dee1b1d76f7cbabe570b2a9285c2e7b41be60cf792f5f2804a54b838a067", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "1560ca427542f6b213f8e281633ae1a3b31cdbcd84ebd7f50628765b8f6132be"},
34 | "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
35 | "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
36 | "telemetry_metrics": {:hex, :telemetry_metrics, "0.6.1", "315d9163a1d4660aedc3fee73f33f1d355dcc76c5c3ab3d59e76e3edf80eef1f", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7be9e0871c41732c233be71e4be11b96e56177bf15dde64a8ac9ce72ac9834c6"},
37 | "telemetry_poller": {:hex, :telemetry_poller, "0.5.1", "21071cc2e536810bac5628b935521ff3e28f0303e770951158c73eaaa01e962a", [:rebar3], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4cab72069210bc6e7a080cec9afffad1b33370149ed5d379b81c7c5f0c663fd4"},
38 | }
39 |
--------------------------------------------------------------------------------