Skip to content

feat(fintech): add full functional Bank domain with events, observers, and smart constructors#14

Open
TATCHIwillyjunior wants to merge 5 commits into
web-development-mart:mainfrom
TATCHIwillyjunior:feat/fintech-domain
Open

feat(fintech): add full functional Bank domain with events, observers, and smart constructors#14
TATCHIwillyjunior wants to merge 5 commits into
web-development-mart:mainfrom
TATCHIwillyjunior:feat/fintech-domain

Conversation

@TATCHIwillyjunior

Copy link
Copy Markdown

Summary

This PR introduces the complete FinTech (Bank) domain implemented in a fully functional style, aligned with the existing DDD + Observer architecture used in the project.

What’s Included

🏦 Bank Domain

  • Added types.ts with branded types:
    • AccountId, AccountName, Balance, DailyLimit, PositiveAmount, BankAccount
  • Added factories.ts:
    • createAccountId, createAccountName, createBalance, createDailyLimit, createPositiveAmount, createBankAccount
  • Added bank.ts:
    • Pure withdraw() domain logic
    • Emits domain events (withdrawal-made, large-withdrawal)

📣 Domain Events

  • Added events.ts with:
    • WithdrawalMadeEvent
    • LargeWithdrawalEvent
    • DomainEvent union

👀 Observers (Infrastructure)

  • Added observer.ts:
    • Observer type
    • observers array
    • registerObserver()
    • emit()
  • Added sms.ts:
    • Fraud detection observer (SMS mock)
  • Added audit.ts:
    • Audit log observer

🧪 index.ts (Wiring)

  • Registers observers
  • Creates a bank account
  • Performs a withdrawal
  • Emits events
  • Logs updated account

Architecture Notes

  • Fully functional implementation (no classes)
  • Domain remains pure and side‑effect free
  • Observers handle all external effects
  • Structure mirrors the existing product/ domain for consistency

Ready for Review

Let me know if you'd like any adjustments or additional documentation.

TATCHIwillyjunior and others added 5 commits March 5, 2026 10:15
…and enforce domain invariants

-Introduce Price, Quantity, and Total branded types
-Add factory functions to validate user input and prevent invalid values
-Replace primitive price, quantity, and total with domain‑safe constructors
-Add consistency rule ensuring total === price × quantity
-Add upper/lower bounds for price, quantity, and total
-Wrap order creation in a try/catch to surface validation errors
-Preserve original structure while enforcing domain rules
…nt flow

- Added /domain/bank/ folder with:
  - types.ts (AccountId, Balance, DailyLimit, PositiveAmount, BankAccount)
  - factories.ts (smart constructors for all branded types + createBankAccount)
  - bank.ts (pure withdraw() domain logic emitting events)

- Added /domain/events/events.ts with:
  - WithdrawalMadeEvent
  - LargeWithdrawalEvent
  - DomainEvent union

- Added /infrastructure/observers/:
  - observer.ts (Observer type, registry, emit(), registerObserver())
  - sms.ts (Fraud Detection observer using SMS mock)
  - audit.ts (Audit Log observer)

- Added index.ts wiring:
  - register observers
  - create account
  - perform withdrawal
  - emit events
  - log updated account

- Ensured full functional style (no classes)
- Ensured branded types and smart constructors
- Ensured domain purity and observer separation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant