# younghoney/financetoy architecture

> Architecture diagram of the GitHub repository younghoney/financetoy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/younghoney/financetoy
- Repository: https://github.com/younghoney/financetoy

## Overview

1. **Repository shape**
   - This is a split monorepo: `Backend/` is the system of record and business engine, while `Frontend/` is a Vue 3 work console.
   - The root `README` makes the key architectural choice explicit: the frontend talks to the backend through a Vite dev proxy on `/api`, and the backend runs against PostgreSQL.

2. **Backend runtime and persistence**
   - The backend is a **Java 21 / Spring Boot 3** application (`FinanceToyApplication`).
   - Persistence is repository-based and likely JPA/Hibernate-backed, with domain entities under feature packages and PostgreSQL as the primary database.
   - A Docker Compose setup is used to bring up the database locally; tests also run against PostgreSQL rather than an in-memory database, using a dedicated schema.

3. **Domain-first backend structure**
   - The backend is organized into business domains rather than technical layers:
     - `order` for trade order lifecycle
     - `ledger` for balances and ledger entries
     - `audit` for audit logging
     - `execution` for execution simulation / outcomes
     - `experiment` for scenario runs and metrics
     - `reconciliation` for consistency checks and jobs
   - `common` contains shared infrastructure such as time-base entities, exception handling, OpenAPI config, and data seeding.

4. **Order processing flow**
   - `OrderController` exposes order-related APIs.
   - `OrderService` appears to be the orchestration point for creating and advancing orders.
   - Core order state is modeled with `TradeOrder`, `OrderStatus`, `OrderSide`, and `FailureMode`.
   - Order history and traceability are captured via `OrderEvent` and `OrderEventRepository`, suggesting each state transition is persisted as an event rather than only overwriting current state.

5. **Financial ledger subsystem**
   - The ledger is separated from order state, with `AccountBalance` representing current balance and `LedgerEntry` representing immutable financial movements.
   - `LedgerEntryType` defines the kinds of balance-affecting operations.
   - `AccountBalanceRepository` and `LedgerEntryRepository` imply that order execution and account mutation are persisted independently, which is important for auditability and reconciliation.

6. **Execution simulation boundary**
   - The `execution` package contains `ExecutionSimulator`, `ExecutionDecision`, and `ExternalExecutionOutcome`.
   - This suggests the system can simulate how an order would be executed, likely producing deterministic or scenario-driven outcomes for testing or experimentation.
   - That simulator is a key boundary between business order flow and external market/exchange behavior, even though no real external broker integration is visible in the tree.

7. **Experiment analysis subsystem**
   - `ExperimentController`, `ExperimentService`, and `ExperimentRunRepository` indicate a separate workflow for running experiments over execution scenarios.
   - DTOs such as `ExperimentRunRequest`, `ExperimentRunResponse`, and `ExperimentSummaryMetrics` show that this is an analytical/reporting API, not part of the core transaction path.
   - This subsystem likely consumes execution/order data to evaluate outcomes and summarize metrics.

8. **Reconciliation and consistency**
   - `ReconciliationController`, `ReconciliationJob`, and `ReconciliationService` form a batch-oriented consistency layer.
   - The presence of `ReconciliationResultResponse` and a job repository suggests scheduled or manually triggered checks that compare order, ledger, and/or execution state to find discrepancies.
   - Architecturally, this is the compensating control for the transactional flow: it validates that persisted artifacts stay aligned.

9. **Audit and traceability**
   - `AuditLog`, `AuditLogRepository`, and `AuditLogService` provide a separate audit trail from order events.
   - The DTOs in `order/dto` include timeline responses for audit, ledger, and order events, which implies the UI can render a unified operational timeline built from multiple subsystems.
   - This is a strong signal that observability and traceability are first-class requirements of the application.

10. **API and error handling conventions**
   - Controllers are feature-specific, while shared error handling lives in `common.exception.GlobalExceptionHandler`.
   - `ApiError`, `NotFoundException`, and `InsufficientFundsException` indicate the API returns structured errors for business and lookup failures.
   - `OpenApiConfig` suggests the backend publishes API documentation, likely for the frontend work console and manual exploration.

11. **Initialization and demo data**
   - `DataInitializer` and `DemoAccounts` point to startup seeding of sample accounts or baseline data.
   - This fits the “toy project” nature of the repo and suggests the system is designed to be runnable locally with meaningful demo state immediately after boot.

12. **Frontend role**
   - The frontend is a compact Vue 3 + Vite application rather than a large SPA platform.
   - `api.js`, `constants.js`, and `main.js` imply a thin client that centralizes backend calls and UI configuration.
   - Based on the backend DTOs, the frontend likely presents order management plus timelines/summary views for audit, ledger, experiment, and reconciliation results.

13. **Testing and development topology**
   - Backend tests include a single integration test class and a PostgreSQL-backed test schema (`financetoy_test`), which implies a strong integration-test bias over unit-only validation.
   - Development topology is local-first: PostgreSQL container on `5430`, backend on `8080`, frontend on `5173`.
   - The architecture therefore centers on a single backend service, one relational database, and a lightweight console UI, with no separate microservices or external brokers evident in the tree.

Main entry points: [`Backend/src/main/java/com/financetoy/order/OrderService.java`](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderService.java) (Order Service), [`Backend/src/main/java/com/financetoy/common/BaseTimeEntity.java`](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/common/BaseTimeEntity.java) (Common Core), [`Backend/src/main/java/com/financetoy/reconciliation/ReconciliationService.java`](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/reconciliation/ReconciliationService.java) (Reconciliation Service), [`Frontend/src/api.js`](https://github.com/younghoney/financetoy/blob/main/Frontend/src/api.js) (API Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend"]
  node_app["FinanceToy<br/>Spring Boot app"]
  node_order_api["Order API<br/>REST controller"]
  node_order_service["Order Service<br/>orchestration<br/>[OrderService.java]"]
  node_trade_order["Trade Order<br/>domain model<br/>[TradeOrder.java]"]
  node_order_events["Order Events<br/>event log<br/>[OrderEvent.java]"]
  node_ledger[("Ledger<br/>accounting domain")]
  node_execution{{"Execution Simulator<br/>simulation boundary"}}
  node_experiment_api["Experiment API<br/>analysis controller"]
  node_experiment_service["Experiment Service<br/>analysis orchestration"]
  node_recon_api["Recon API<br/>batch controller"]
  node_recon_service["Reconciliation Service<br/>consistency checks"]
  node_audit["Audit Log<br/>audit trail<br/>[AuditLog.java]"]
  node_common{{"Common Core<br/>shared infrastructure"}}
end

subgraph group_frontend["Frontend"]
  node_frontend_app["Vue Console<br/>Vue 3 app<br/>[App.vue]"]
  node_frontend_api["API Client<br/>client adapter<br/>[api.js]"]
end

subgraph group_data["Data"]
  node_db[("PostgreSQL<br/>relational database<br/>[docker-compose.yml]")]
  node_testdb[("Test Schema<br/>integration schema<br/>[test-schema.sql]")]
  node_docker{{"Compose Stack<br/>local runtime<br/>[docker-compose.yml]"}}
end

node_frontend_app -->|"calls"| node_frontend_api
node_frontend_api -->|"/api"| node_order_api
node_frontend_api -->|"experiments"| node_experiment_api
node_frontend_api -->|"reconcile"| node_recon_api
node_order_api -->|"orchestrates"| node_order_service
node_order_service -->|"updates"| node_trade_order
node_order_service -->|"records"| node_order_events
node_order_service -->|"posts"| node_ledger
node_order_service -->|"simulates"| node_execution
node_execution -->|"affects"| node_ledger
node_experiment_api -->|"orchestrates"| node_experiment_service
node_experiment_service -->|"runs"| node_execution
node_experiment_service -->|"consumes"| node_order_service
node_recon_api -->|"orchestrates"| node_recon_service
node_recon_service -->|"checks"| node_order_events
node_recon_service -->|"checks"| node_ledger
node_recon_service -->|"cross-checks"| node_audit
node_common -->|"errors"| node_order_api
node_common -->|"errors"| node_experiment_api
node_common -->|"errors"| node_recon_api
node_common -->|"boots"| node_app
node_app -->|"persists"| node_db
node_docker -->|"starts"| node_db
node_testdb -.->|"isolates"| node_db

click node_app "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/FinanceToyApplication.java"
click node_order_api "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderController.java"
click node_order_service "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderService.java"
click node_trade_order "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/TradeOrder.java"
click node_order_events "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderEvent.java"
click node_ledger "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/ledger/AccountBalance.java"
click node_execution "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/execution/ExecutionSimulator.java"
click node_experiment_api "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/experiment/ExperimentController.java"
click node_experiment_service "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/experiment/ExperimentService.java"
click node_recon_api "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/reconciliation/ReconciliationController.java"
click node_recon_service "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/reconciliation/ReconciliationService.java"
click node_audit "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/audit/AuditLog.java"
click node_common "https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/common/BaseTimeEntity.java"
click node_frontend_app "https://github.com/younghoney/financetoy/blob/main/Frontend/src/App.vue"
click node_frontend_api "https://github.com/younghoney/financetoy/blob/main/Frontend/src/api.js"
click node_db "https://github.com/younghoney/financetoy/blob/main/Backend/docker-compose.yml"
click node_testdb "https://github.com/younghoney/financetoy/blob/main/Backend/src/test/resources/test-schema.sql"
click node_docker "https://github.com/younghoney/financetoy/blob/main/Backend/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_order_api,node_order_service,node_trade_order,node_order_events,node_ledger,node_execution,node_experiment_api,node_experiment_service,node_recon_api,node_recon_service,node_audit,node_common toneBlue
class node_frontend_app,node_frontend_api toneAmber
class node_db,node_testdb,node_docker toneMint
```

## Components

### Backend

Spring Boot domain engine and PostgreSQL persistence

- [FinanceToy](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/FinanceToyApplication.java): Spring Boot app · Java 21 entrypoint for the backend service · `Backend/src/main/java/com/financetoy/FinanceToyApplication.java`
- [Order API](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderController.java): REST controller · Order lifecycle endpoints and operator views · `Backend/src/main/java/com/financetoy/order/OrderController.java`
- [Order Service](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderService.java): orchestration · Coordinates order creation, progression, and timeline assembly · `Backend/src/main/java/com/financetoy/order/OrderService.java`
- [Trade Order](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/TradeOrder.java): domain model · Core order state and status model · `Backend/src/main/java/com/financetoy/order/TradeOrder.java`
- [Order Events](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/order/OrderEvent.java): event log · Persisted order transitions and event history · `Backend/src/main/java/com/financetoy/order/OrderEvent.java`
- [Ledger](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/ledger/AccountBalance.java): accounting domain · Balances and immutable money movements · `Backend/src/main/java/com/financetoy/ledger/AccountBalance.java`
- [Execution Simulator](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/execution/ExecutionSimulator.java): simulation boundary · Produces execution decisions and external outcomes · `Backend/src/main/java/com/financetoy/execution/ExecutionSimulator.java`
- [Experiment API](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/experiment/ExperimentController.java): analysis controller · Runs scenarios and returns summary metrics · `Backend/src/main/java/com/financetoy/experiment/ExperimentController.java`
- [Experiment Service](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/experiment/ExperimentService.java): analysis orchestration · Executes experiment runs and assembles metrics · `Backend/src/main/java/com/financetoy/experiment/ExperimentService.java`
- [Recon API](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/reconciliation/ReconciliationController.java): batch controller · Triggers reconciliation checks and returns results · `Backend/src/main/java/com/financetoy/reconciliation/ReconciliationController.java`
- [Reconciliation Service](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/reconciliation/ReconciliationService.java): consistency checks · Compares order, ledger, and execution state · `Backend/src/main/java/com/financetoy/reconciliation/ReconciliationService.java`
- [Audit Log](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/audit/AuditLog.java): audit trail · Separate audit records for operational traceability · `Backend/src/main/java/com/financetoy/audit/AuditLog.java`
- [Common Core](https://github.com/younghoney/financetoy/blob/main/Backend/src/main/java/com/financetoy/common/BaseTimeEntity.java): shared infrastructure · Time base, errors, API config, and startup seeding · `Backend/src/main/java/com/financetoy/common/BaseTimeEntity.java`

### Frontend

Vue 3 work console

- [Vue Console](https://github.com/younghoney/financetoy/blob/main/Frontend/src/App.vue): Vue 3 app · Thin operator UI for orders, timelines, and reports · `Frontend/src/App.vue`
- [API Client](https://github.com/younghoney/financetoy/blob/main/Frontend/src/api.js): client adapter · Centralized backend calls used by the console · `Frontend/src/api.js`

### Data

Relational state and local test schema

- [PostgreSQL](https://github.com/younghoney/financetoy/blob/main/Backend/docker-compose.yml): relational database · Primary persistent store for runtime data · `Backend/docker-compose.yml`
- [Test Schema](https://github.com/younghoney/financetoy/blob/main/Backend/src/test/resources/test-schema.sql): integration schema · Dedicated PostgreSQL schema for backend tests · `Backend/src/test/resources/test-schema.sql`
- [Compose Stack](https://github.com/younghoney/financetoy/blob/main/Backend/docker-compose.yml): local runtime · Local database bootstrap for development · `Backend/docker-compose.yml`

## Connections

- Vue Console → API Client: calls · UI issues backend requests through the client adapter
- API Client → Order API: /api · Vite dev proxy routes console traffic to backend endpoints
- API Client → Experiment API: experiments · Console submits scenario runs and reads summaries
- API Client → Recon API: reconcile · Console can trigger consistency checks
- Order API → Order Service: orchestrates · Controller delegates order workflows to the service layer
- Order Service → Trade Order: updates · Service mutates order state
- Order Service → Order Events: records · Each transition is persisted as an event
- Order Service → Ledger: posts · Execution and balance changes are written independently
- Order Service → Execution Simulator: simulates · Order progression depends on simulated execution outcomes
- Execution Simulator → Ledger: affects · Execution outcomes can drive balance movements
- Experiment API → Experiment Service: orchestrates · API delegates scenario execution and reporting
- Experiment Service → Execution Simulator: runs · Experiments reuse execution simulation as the scenario engine
- Experiment Service → Order Service: consumes · Experiment runs build on order lifecycle data
- Recon API → Reconciliation Service: orchestrates · Controller delegates batch consistency checks
- Reconciliation Service → Order Events: checks · Reconciliation inspects order history
- Reconciliation Service → Ledger: checks · Reconciliation compares financial state
- Reconciliation Service → Audit Log: cross-checks · Audit trail supports discrepancy investigation
- Common Core → Order API: errors · Shared exception handling and API error shaping
- Common Core → Experiment API: errors · Shared exception handling and API error shaping
- Common Core → Recon API: errors · Shared exception handling and API error shaping
- Common Core → FinanceToy: boots · Application startup and demo data initialization
- FinanceToy → PostgreSQL: persists · Backend runtime reads and writes PostgreSQL
- Compose Stack → PostgreSQL: starts · Compose brings up the local database
- Test Schema → PostgreSQL: isolates · Tests use a dedicated PostgreSQL schema
