Skip to main content

System Architecture — Multi-App Function Surface

Maps every external consumer of Syntropy Journals, the data they read/write, and the API routes and functions that serve them. Updated: 2026-03-27 | Companion: FUNCTION_TAXONOMY.md, INTEGRATION_SURFACES.md

Consumer Matrix

ConsumerAuthProtocolsCheck-insHealth ProfileDiet/ScoringChat/AITokens
Shopify AppBearer split-tokenPull: adherence, feedbackPull: aggregate
OpenClaw MCPClerk JWT (OAuth 2.1)Pull: subscriptionsPush+PullPullPull: score, gapPush+Pull: chatPairing verify
Chrome Extensionsh_* API keyPullPush: food, Pull: scoreKey exchange
Mobile (planned)Clerk JWTPull: subscriptionsPush+PullPullPull: scorePairing code
Web AppClerk sessionFull CRUDFull CRUDFull CRUDFullFullFull

1. Shopify Protocols App

Routes: /api/v1/* | Auth: Bearer split-token | Rate: 60 read, 20 write/min
MethodRouteDirFunction
GET/api/v1/analytics/summaryPullget_partner_summary_sync
GET/api/v1/analytics/protocols/{id}/adherencePullget_protocol_adherence_sync
GET/api/v1/analytics/protocols/{id}/feedbackPullget_protocol_feedback_sync
GET/api/v1/analytics/protocols/{id}/retentionPullget_protocol_retention_sync
POST/api/v1/protocolsPushcreate_protocol_sync
PUT/api/v1/protocols/{id}Pushupdate_protocol_sync
DELETE/api/v1/protocols/{id}Pushupdate_protocol_sync(status=archived)
Client: shopify-protocols/app/lib/journals-api.ts

2. OpenClaw MCP Server (PRD-20, Planned)

Mount: /mcp | Auth: Clerk JWT via MCP OAuth 2.1
MCP ToolDirService MethodFunction
chat_with_shrinePush+PullChatService.invoke_agentShrineAgent.invoke
log_foodPushCheckinService.log_foodcreate_food_log_sync
log_checkinPushCheckinService.create_checkinintake_and_process_checkin
get_diet_scorePullDietService.get_scorecompute_diet_fulfillment_score
get_health_profilePullProfileService.get_health_profileget_health_profile_sync
get_health_snapshotPullDietService.get_snapshotbuild_health_snapshot
get_diet_gapPullDietService.get_gapcompute_diet_gap
get_my_protocolsPullProfileService.get_user_protocolsget_user_protocols_sync
analyze_foodPullDietService.analyze_foodanalyze_food_text
get_my_checkinsPullCheckinService.get_checkinsget_checkins_for_user_sync

3. Chrome Shrine Extension

Routes: /api/ext/*, /api/diet/* | Auth: sh_* API key
MethodRouteDirFunctionClient
GET/api/ext/profilePullget_health_profile_syncJournalApiClient.getHealthProfile()
POST/api/ext/food-logPushcreate_food_log_syncJournalApiClient.logFood()
POST/api/ext/api-key-exchangePushProfile provisioningJournalApiClient.exchangeClerkTokenForApiKey()
POST/api/ext/diet/analyzePullanalyze_food_textvia diet-api.ts
GET/api/ext/diet/scorePullcompute_diet_fulfillment_scorevia diet-api.ts
POST/api/diet/score-foodPullDietAgent.score_foodDietApiClient.scoreFoodFit()
Contract: docs/api/openapi.json (CI-enforced via make openapi-check)

4. Syntropy Mobile (Planned)

Routes: /api/ext/* | Auth: Clerk JWT Reuses extension endpoints. Needs new: POST /api/ext/checkin, GET /api/ext/checkins.

Service Layer Mapping

Every MCP tool maps to a service method which maps to a function:
MCP Tool → Service.method() → functions/*.py → DB
ServiceMethodsConsumers
ChatServiceinvoke_agent, get_chat_sessionsMCP
DietServiceget_score, get_gap, get_snapshot, analyze_food, recommend_targetsMCP, Chrome, Mobile
CheckinServiceget_checkins, create_checkin, log_food, get_food_logsMCP, Mobile
ProfileServiceget_user_profile, get_health_profile, ensure_profile_records, get_user_protocolsMCP, Chrome, Mobile

MCP Deployment Decision

Decision: MCP server is embedded in the main Reflex/FastAPI app, mounted at /mcp. Rationale: All functions/db_utils/ use rx.session() (Reflex’s SQLAlchemy session factory). Extracting to a standalone app would require replacing ~40 session calls — high effort, high regression risk, zero user value. Extraction trigger: If MCP traffic exceeds 30% of total requests, or independent scaling is needed, extract functions/ + services/ + mcp/ into a separate syntropy-mcp Railway service. The service layer boundary already enables this — replace rx.session() with a standalone SessionLocal factory. Current coupling point: functions/db_utils/*.pyrx.session() (Reflex session factory)

Pending Gaps

GapConsumerPriority
POST /api/ext/checkinMobile, MCPHigh
GET /api/ext/checkinsMobile, MCPHigh
MCP server mount at /mcpMCPPhase 4
Symptom reporting endpointChromeLow
Product search endpointChromeLow