Tech document - https://docs.google.com/document/d/1fJ9lx5mGoJiABqKFJyHyQTEyb1nfzKH6KmDHBPPuEDA/edit?tab=t.uekqbnmu1p47#heading=h.dwe1y898d5oz
Generated Prompt
PROJECT SETUP
The project structure will follow a modular approach to enhance maintainability and scalability. Below is the recommended file organization:
```
/src
/components
/Transaction
TransactionEntity.js
TransactionService.js
TransactionController.js
/Balance
BalanceEntity.js
BalanceService.js
BalanceController.js
/events
EventListener.js
/utils
Logger.js
Validator.js
/config
DatabaseConfig.js
RetentionPolicyConfig.js
/tests
/Transaction
TransactionService.test.js
/Balance
BalanceService.test.js
index.js
```
DESIGN REQUIREMENTS
- Visual Style: minimalist - Clean, simple design with plenty of white space, minimal color palette, and focus on typography
- Color Mode: Light theme with dark text on light backgrounds
- Primary Color: #1978E5 (accent for buttons, links, highlights)
- Typography: Use Inter from Google Fonts for headings, Inter for body text and UI elements
- Border Radius: 8px (moderately rounded) for buttons, cards, and inputs
CORE COMPONENTS
1. **TransactionEntity**: Defines the schema for transactions with fields such as id, eventName, type, amount, currency, source, target, timestamp, valueDate, and metadata.
2. **TransactionService**: Handles the business logic for capturing and persisting transaction events. It listens for events and processes them accordingly.
3. **TransactionController**: Provides the API endpoints for interacting with transactions.
4. **BalanceEntity**: Maintains the current balance per virtual ledger with fields for virtualLedgerId and the total amount.
5. **BalanceService**: Implements the logic for updating balances based on incoming transactions and ensuring accurate recalculations.
6. **EventListener**: Listens to domain events and triggers the appropriate services.
7. **Logger**: Utility for logging system events for debugging and monitoring.
8. **Validator**: Utility for validating incoming data before processing.
IMPLEMENTATION APPROACH
1. **Set up Event Listeners**:
Create an `EventListener.js` that subscribes to `BROKER-SAVINGS-DomainEvents` and captures relevant events.
```javascript
import { PersonalSavingsVirtualLedgerCredited, PersonalSavingsVirtualLedgerDebited } from 'events';
import TransactionService from 'components/Transaction/TransactionService';
const eventListener = () => {
PersonalSavingsVirtualLedgerCredited.on('event', TransactionService.captureCredit);
PersonalSavingsVirtualLedgerDebited.on('event', TransactionService.captureDebit);
};
export default eventListener;
```
2. **Transaction Entity**:
Define the schema in `TransactionEntity.js` using an ORM model.
```javascript
import { Schema, model } from 'mongoose';
const transactionSchema = new Schema({
id: String,
eventName: String,
type: { type: String, enum: ['CREDIT', 'DEBIT'] },
amount: Number,
currency: String,
source: String,
target: String,
timestamp: Date,
valueDate: Date,
metadata: Object
});
export const Transaction = model('Transaction', transactionSchema);
```
3. **Balance Calculation Logic**:
Implement the core calculation logic in `BalanceService.js` to update balances based on transactions.
```javascript
class BalanceService {
static async updateBalance(transaction) {
const balance = await this.getBalance(transaction.virtualLedgerId);
balance.total += transaction.type === 'CREDIT' ? transaction.amount : -transaction.amount;
await balance.save();
}
}
```
ARCHITECTURE CONSIDERATIONS
The architecture will be event-driven to ensure that each transaction is processed asynchronously. This design allows for high scalability and better performance under load. Utilizing a microservices approach can also be considered if the system needs to handle a larger scale of operations in the future.
ERROR HANDLING
Implement try-catch blocks in service methods to handle potential errors during database operations. Use the Logger utility to log errors for monitoring and debugging purposes.
```javascript
try {
await this.updateBalance(transaction);
} catch (error) {
Logger.error('Error updating balance:', error);
}
```
TESTING STRATEGY
Utilize Jest for unit testing. Each service will have dedicated test files in the `/tests` directory. Mock external dependencies and focus on testing the business logic of each service.
```javascript
describe('TransactionService', () => {
test('should capture a credit transaction', async () => {
const result = await TransactionService.captureCredit(mockTransaction);
expect(result).toBeTruthy();
});
});
```
Please provide detailed, production-ready code that follows best practices for Cursor.Loved by thousands of makers from
From early prototypes to real products, they started here.







































Generate optimized prompts for your vibe coding projects
Generate prompt
Enter a brief description of the app you want to build and get an optimized prompt
Review and use your prompt
Review (and edit if necessary) the generated prompt, then copy it or open it directly in your chosen platform
Get inspired with new ideas
Get AI-generated suggestions to expand your product with features that will surprise your users
Frequently Asked Questions
Everything you need to know about creating better prompts for your Lovable projects
Still have questions?
Can't find what you're looking for? We're here to help!
