# caueferreira/akka-bank architecture

> Architecture diagram of the GitHub repository caueferreira/akka-bank, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/caueferreira/akka-bank
- Repository: https://github.com/caueferreira/akka-bank

## Overview

##### Project Type and Purpose
**Akka Bank** is a **concurrent and event-sourced financial operations application** built using the [Akka](https://akka.io/) framework. The primary purpose of the project is to emulate financial operations such as reading account balances, crediting, debiting, and transferring funds between accounts. It ensures idempotence, parallelism, and concurrency in its operations, leveraging event sourcing to maintain immutable event records.

##### File Structure Analysis
- **Top-Level Directories:**
- `.circleci`, `.github`: Configuration for CI/CD pipelines and GitHub integrations.
- `src`: Contains all source code and tests.
- `main/java`: Application source code.
- `actors`: Defines Akka actors like `Account`, `AccountSupervisor`, and `TransferSaga`.
- `commands`, `requests`, `responses`: Define the various command, request, and response types used in operations.
- `server`: Contains server setup (`BankServer.kt`, `Main.kt`).
- `source`: Includes `EventStore.kt` for event sourcing.
- `test/java`: Unit tests for actors, commands, requests, and the event store.
- `test/resources`: Includes Mockito extensions for testing.
- `pom.xml`: Maven configuration for project dependencies and build.
- `.gitignore`, `README.md`: Standard project files.

- **Architectural Patterns:**
- **Actor Model:** Utilizes Akka actors (`Account`, `AccountSupervisor`, `TransferSaga`) to handle concurrent operations.
- **Event Sourcing:** Implements an `EventStore` to manage immutable events, reconstructing account states from event histories.
- **Saga Pattern:** Uses `TransferSaga` to manage complex transfer transactions and compensations.

##### README Insights
The README elaborates on:
- **Core Operations:** READ, CREDIT, DEBIT, TRANSFER.
- **Architecture:** Emphasis on event sourcing, actor supervision, idempotent operations, and concurrency management.
- **Technical Stack:** Akka, Akka-Http, JUnit.
- **Execution Details:** Instructions to run the server and tests.

**a. Identify Main Components:**
- **Frontend (If Applicable):** Not explicitly present; the focus is on backend operations.
- **Backend Components:**
- **Actors:**
- `Account`
- `AccountSupervisor`
- `TransferSaga`
- **Event Store:** `EventStore`
- **Server:** `BankServer`, `Main`
- **External Services:**
- **Clients:** Interaction points for sending requests.
- **CI/CD Pipelines:** CircleCI configurations.

**b. Determine Relationships and Interactions:**
- **Client Requests:** Sent to `BankServer`, which interacts with `AccountSupervisor`.
- **AccountSupervisor:** Manages `Account` actors and forwards events.
- **TransferSaga:** Handles transfer logic by coordinating `Account` actors.
- **EventStore:** Stores and retrieves events for accounts, enabling state reconstruction.
- **Actors:** Communicate asynchronously to handle operations, ensuring concurrency and idempotence.

**c. Highlight Architectural Patterns:**
- **Actor Model:** Enables concurrent processing of requests.
- **Event Sourcing:** Maintains a history of immutable events for state management.
- **Saga Pattern:** Manages long-running transactions and compensations in transfers.

**d. Include Relevant Technologies:**
- **Frameworks/Libraries:** Akka, Akka-Http, JUnit.
- **Build Tools:** Maven (`pom.xml`).
- **CI/CD Tools:** CircleCI.
- **Testing Tools:** Mockito for mocking in tests.

##### External Client
- Sends Requests to **BankServer**.

##### BankServer
- Routes requests to **AccountSupervisor**.

##### AccountSupervisor
- Manages `Account` actors.
- Forwards operations to appropriate `Account`.

##### Account Actors
- Handle `Credit`, `Debit`, `Read` operations.
- Interact with **EventStore** for event logging and retrieval.

##### TransferSaga
- Coordinates `Transfer` operations between two `Account` actors.
- Manages compensations in case of failures.

##### EventStore
- Stores all immutable events.
- Provides event history to `Account` actors for state reconstruction.

##### CI/CD Pipeline
- Represents automated testing and deployment via CircleCI.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Define nodes
    ExternalClient["External Client"]:::external
    BankServer["BankServer"]:::server
    Main["Main"]:::server
    AccountSupervisor["AccountSupervisor"]:::actor
    Account["Account"]:::actor
    TransferSaga["TransferSaga"]:::actor
    EventStore["EventStore"]:::eventstore
    CICD["CI/CD Pipeline"]:::cicd
    GitHub["GitHub Configuration"]:::external

    %% Define connections
    ExternalClient --> BankServer
    Main --> BankServer
    BankServer --> AccountSupervisor
    AccountSupervisor --> Account
    AccountSupervisor --> TransferSaga
    Account --> EventStore
    TransferSaga --> Account
    CICD --> BankServer
    GitHub --> CICD

    %% Define click events
    click Account "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/actors/Account.kt"
    click AccountSupervisor "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/actors/AccountSupervisor.kt"
    click TransferSaga "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/actors/TransferSaga.kt"
    click EventStore "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/source/EventStore.kt"
    click BankServer "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/server/BankServer.kt"
    click Main "https://github.com/caueferreira/akka-bank/blob/master/src/main/java/server/Main.kt"
    click CICD "https://github.com/caueferreira/akka-bank/blob/master/.circleci/config.yml"
    click GitHub "https://github.com/caueferreira/akka-bank/tree/master/.github/"

    %% Define styles
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:1px
    classDef actor fill:#add8e6,stroke:#000,stroke-width:1px
    classDef eventstore fill:#90ee90,stroke:#000,stroke-width:1px
    classDef server fill:#ffa500,stroke:#000,stroke-width:1px
    classDef cicd fill:#d8bfd8,stroke:#000,stroke-width:1px
```
