Status: Implemented and Locked (CORE-QUERY-1 Phase 4-6) Last Updated: 2025-09-29 Maintainers: Architecture Team
The Router Pattern provides a unified abstraction layer over external integrations, enabling feature flag control and spatial intelligence capabilities while maintaining backward compatibility. This architecture was established during CORE-QUERY-1 to address direct adapter coupling and enable feature-driven integration control.
Three integration routers provide complete abstraction with 100% method compatibility:
USE_SPATIAL_CALENDAR, ALLOW_LEGACY_CALENDARservices/integrations/calendar/calendar_integration_router.pyUSE_SPATIAL_NOTION, ALLOW_LEGACY_NOTIONservices/integrations/notion/notion_integration_router.pyUSE_SPATIAL_SLACK, ALLOW_LEGACY_SLACKservices/integrations/slack/slack_integration_router.pyEach router respects environment-based feature flags for spatial intelligence control:
| Integration | Spatial Flag | Legacy Flag | Default Behavior |
|---|---|---|---|
| Calendar | USE_SPATIAL_CALENDAR |
ALLOW_LEGACY_CALENDAR |
Spatial enabled |
| Notion | USE_SPATIAL_NOTION |
ALLOW_LEGACY_NOTION |
Spatial enabled |
| Slack | USE_SPATIAL_SLACK |
ALLOW_LEGACY_SLACK |
Spatial enabled |
Flag Values: true, 1, yes, on, enabled (case-insensitive)
from services.infrastructure.config.feature_flags import FeatureFlags
class IntegrationRouter(BaseSpatialAdapter):
"""Base pattern for integration routers"""
def __init__(self, config_service=None):
super().__init__(config_service)
self.use_spatial = FeatureFlags.should_use_spatial_[integration]()
self.allow_legacy = FeatureFlags.is_legacy_[integration]_allowed()
# Initialize spatial integration
if self.use_spatial:
self.spatial_integration = SpatialAdapter()
# Initialize legacy integration if allowed
if self.allow_legacy:
self.legacy_integration = LegacyAdapter()
def _get_preferred_integration(self, operation: str) -> Tuple[Optional[Any], bool]:
"""Get preferred integration based on feature flags"""
# Try spatial first
if self.use_spatial and self.spatial_integration:
return self.spatial_integration, False
# Fall back to legacy if allowed
elif self.allow_legacy and self.legacy_integration:
return self.legacy_integration, True
# No integration available
else:
return None, False
async def method_name(self, *args, **kwargs):
"""Delegate method calls to preferred integration"""
integration, is_legacy = self._get_preferred_integration("method_name")
if integration:
self._warn_deprecation_if_needed("method_name", is_legacy)
return await integration.method_name(*args, **kwargs)
else:
raise RuntimeError(f"No integration available for method_name")
from services.mcp.consumer.google_calendar_adapter import GoogleCalendarMCPAdapter
class SomeService:
def __init__(self):
self.calendar = GoogleCalendarMCPAdapter()
async def get_events(self):
return await self.calendar.get_events()
from services.integrations.calendar.calendar_integration_router import CalendarIntegrationRouter
class SomeService:
def __init__(self):
self.calendar = CalendarIntegrationRouter()
async def get_events(self):
# Same method call - router handles delegation transparently
return await self.calendar.get_events()
Key Point: Method calls remain identical. The router provides a drop-in replacement with transparent delegation.
Hook: prevent-direct-adapter-imports
scripts/check_direct_imports.pyProhibited Patterns:
from services.mcp.consumer.google_calendar_adapter importfrom services.integrations.mcp.notion_adapter importfrom services.integrations.slack.spatial_adapter importfrom services.integrations.slack.slack_client importGitHub Actions Workflow: .github/workflows/router-enforcement.yml
Jobs:
The architecture is protected at three levels:
Enable or disable spatial intelligence per integration without code changes:
# Enable spatial calendar
export USE_SPATIAL_CALENDAR=true
# Disable spatial notion
export USE_SPATIAL_NOTION=false
# Enable legacy slack fallback
export ALLOW_LEGACY_SLACK=true
Legacy mode support where needed, with deprecation warnings to guide migration.
Consistent API across all integrations simplifies service development:
# All routers follow same pattern
calendar = CalendarIntegrationRouter()
notion = NotionIntegrationRouter()
slack = SlackIntegrationRouter()
# Same method patterns
await calendar.get_events()
await notion.get_database(db_id)
await slack.send_message(channel, text)
Built-in spatial adapter coordination for 8-dimensional spatial analysis:
Automated enforcement prevents regression to direct imports:
All routers tested with multiple flag combinations:
Results: 100% pass rate across all routers
All routers verified for 100% method compatibility:
Results: 49/49 total methods (100% complete)
All migrated services verified clean:
Results: 6/6 services clean (0 violations)
Cause: All integration modes disabled via feature flags Solution: Enable at least one mode:
export USE_SPATIAL_CALENDAR=true
# or
export ALLOW_LEGACY_CALENDAR=true
Cause: Using direct adapter import instead of router Solution: Replace with router import:
# ❌ Wrong
from services.mcp.consumer.google_calendar_adapter import GoogleCalendarMCPAdapter
# ✅ Correct
from services.integrations.calendar.calendar_integration_router import CalendarIntegrationRouter
Cause: Direct adapter import in staged files Solution: Migrate service to router pattern (see migration guide)
The router pattern can be extended for:
Review Frequency: Quarterly Owner: Architecture Team Last Review: 2025-09-29 Next Review: 2025-12-29
When extending this pattern:
Version: 1.0 Established: 2025-09-29 (CORE-QUERY-1 Phase 6) Status: Locked with automated enforcement