-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Description
Problem
The FireflyClient in clients/firefly.py is currently handling too many responsibilities:
- ✅ HTTP communication (appropriate)
- ✅ Request/response serialization (appropriate)
- ❌ Business logic - aggregations, calculations (should be elsewhere)
- ❌ Multi-call orchestration - making multiple API calls and combining results (should be elsewhere)
- 🤔 Model conversion (debatable)
Examples of business logic in the client:
get_budget_spending(): Aggregates data from multiple limit entries, calculates percentagesget_budget_summary(): Orchestrates multiple API calls and combines resultscreate_bulk_transactions(): Orchestrates multiple individual creates
This violates the Single Responsibility Principle and makes the client harder to test and maintain.
Proposed Solution
Introduce a services layer between the MCP tools and the Firefly client:
MCP Tools → Services → Firefly Client → Firefly API
New Structure
src/lampyrid/
├── tools/ # MCP interface layer (thin)
│ ├── accounts.py # MCP tool definitions only
│ ├── transactions.py
│ └── budgets.py
├── services/ # NEW: Business logic layer
│ ├── __init__.py
│ ├── accounts.py # AccountService - orchestration, aggregation
│ ├── transactions.py # TransactionService
│ └── budgets.py # BudgetService
├── clients/ # API client layer (thin)
│ └── firefly.py # Pure HTTP client, returns raw Firefly models
├── models/
│ ├── firefly_models.py
│ └── lampyrid_models.py
└── config.py
Responsibility Distribution
Tools Layer (MCP interface):
- Register MCP tools
- Input validation (Pydantic)
- Call service methods
- Return results directly
Services Layer (Business logic):
- Orchestrate multiple client calls
- Business logic (aggregations, calculations)
- Model conversion (Firefly → LamPyrid)
- Return LamPyrid models
Client Layer (HTTP only):
- HTTP communication
- Request parameter formatting
- Response parsing to Firefly models
- Error handling (HTTP status)
- Return raw Firefly models