You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor: move shared orchestration into basic_memory/app/ services; keep adapters thin
Why
API routers and MCP tools often duplicate orchestration: resolve project → call services/repos → format response. Domain-ish orchestration should live in reusable application services.
This issue proposes a significant architectural improvement to reduce code duplication between MCP tools and API routers by introducing a new application service layer (basic_memory/app/).
Current State
After reviewing the codebase, I can confirm there is significant duplication between MCP tools and API routers:
The project already has basic_memory/services/ with:
entity_service.py
search_service.py
context_service.py
project_service.py
directory_service.py
file_service.py
These are domain services that work with repositories and models. The proposed app/ layer would sit above these, orchestrating multiple services and handling cross-cutting concerns like:
Project resolution
Entity resolution
Pagination
Result formatting (typed objects, not strings)
Benefits
Reduced duplication - Orchestration logic written once
Activity
claude commentedon Dec 31, 2025
Claude finished @phernandez's task in 2m 12s —— View job
Issue Triage Complete
Todo List
Classification
Type: Enhancement (Architectural Refactoring)
Priority: Medium
Complexity: Complex
Components: API, MCP, Services, Architecture
Label added:
enhancementAnalysis
This issue proposes a significant architectural improvement to reduce code duplication between MCP tools and API routers by introducing a new application service layer (
basic_memory/app/).Current State
After reviewing the codebase, I can confirm there is significant duplication between MCP tools and API routers:
Example from search functionality:
MCP tool (
src/basic_memory/mcp/tools/search.py): ~380 linesAPI router (
src/basic_memory/api/routers/search_router.py): ~35 linesExample from read_note:
MCP tool (
src/basic_memory/mcp/tools/read_note.py): ~270 linesAPI router (
src/basic_memory/api/routers/memory_router.py): ~90 linesThe duplication is particularly evident in:
Proposed Architecture
The issue proposes creating
basic_memory/app/services that:Example architecture:
Dependencies & Related Work
This refactoring has explicit dependencies on:
These issues form a cohesive refactoring plan to improve architecture:
Existing Services Layer
The project already has
basic_memory/services/with:entity_service.pysearch_service.pycontext_service.pyproject_service.pydirectory_service.pyfile_service.pyThese are domain services that work with repositories and models. The proposed
app/layer would sit above these, orchestrating multiple services and handling cross-cutting concerns like:Benefits
Challenges
services/(domain) andapp/(application orchestration)Recommendation
This is a well-considered architectural improvement that addresses real duplication in the codebase. However:
services/andapp/Next Steps
phernandez commentedon Jan 3, 2026
Closing as no longer needed
After implementing #494 (typed API clients), the architecture now cleanly separates concerns:
The original problem this issue aimed to solve was:
With typed API clients, MCP tools are now thin adapters that delegate to the API. The duplication is eliminated because:
Adding an
app/services layer would:The typed API clients achieve the same goal more elegantly. Closing as superseded by #494.