Cosmic Module
O
Qubits of DPK
March 20, 2026
Core Open Source
Why Patterns Matter
Every single class in Fineract follows a set of design patterns. If you understand these patterns, you can navigate ANY file in the codebase — even one you've never seen before — because the structure is always the same.
Pattern 1 — CQRS (Command Query Responsibility Segregation)
Layman Explanation
Imagine a bank with two counters:
- Counter A — only handles READING ("What is my balance?")
- Counter B — only handles WRITING ("Transfer ₹5000 to Rahul")
They are completely separate. The person at Counter A never touches money. The person at Counter B never looks up balances.
This is CQRS. Fineract separates every operation into:
- Query → Read data, return it, NO changes to DB
- Command → Change data, trigger events, audit trail
In Code
Every domain has TWO service interfaces:
java
QUBITS OF DPK
Why?
- Read operations can be cached, scaled horizontally, run without locks
- Write operations need transactions, audit logging, event publishing
- Separating them keeps code clean and prevents accidental writes in read paths
Pattern 2 — The Command Pattern
Layman Explanation
Think of a restaurant. When you order food:
- #You tell the waiter (API layer)
- #The waiter writes it on a ticket (Command object)
- #The ticket goes to the kitchen (CommandHandler)
- #The kitchen cooks and sends back a result
The waiter doesn't cook. The kitchen doesn't take orders. Clean separation.
The Full Flow in Fineract
javascript
QUBITS OF DPK
JsonCommand — The Ticket
java
QUBITS OF DPK
CommandHandler — The Kitchen
java
QUBITS OF DPK
CommandProcessingResult — The Receipt
java
QUBITS OF DPK
Pattern 3 — Domain-Driven Design (DDD)
Layman Explanation
DDD says: organise your code around REAL business concepts, not technical layers.
Bad (technical layers):
javascript
QUBITS OF DPK
Everything for loans, clients, savings mixed together.
Good (DDD — Fineract's way):
javascript
QUBITS OF DPK
The Standard 4-Layer Package Structure
Every domain in Fineract follows this exact structure:
Pattern 4 — Event-Driven Architecture
Layman Explanation
When something important happens in a bank (loan disbursed, repayment made), many different departments need to know:
- Accounting must record a journal entry
- SMS system must notify the customer
- Audit log must record who did what
Instead of calling all of them directly, Fineract publishes an event and each department listens for the events they care about.
This is like a hospital's PA system: "Patient in Room 4 needs a doctor" — every relevant person who heard it responds.
In Code
java
QUBITS OF DPK
Event Flow
javascript
QUBITS OF DPK
Key benefit: The loan module doesn't know about accounting. Accounting doesn't know about SMS. They're completely decoupled.
Pattern 5 — Repository Pattern (Spring Data JPA)
Layman Explanation
A repository is like a filing cabinet. You ask it for a file, it gives it to you. You don't care how it's stored — magnetic disk, SSD, cloud — you just call findById().
In Code
java
QUBITS OF DPK
The Complete Request Flow — Putting It All Together
javascript
QUBITS OF DPK