# rushikeshmore/shopify-partner-agent architecture

> Architecture diagram of the GitHub repository rushikeshmore/shopify-partner-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rushikeshmore/shopify-partner-agent
- Repository: https://github.com/rushikeshmore/shopify-partner-agent

## Overview

1. **Project shape**
   - This is a small Python 3.11+ package that ships as an **MCP server** called `shopify-partner-agent`.
   - It is not a hosted service: the server runs locally inside the user’s MCP client environment and talks directly to Shopify’s **Partner API**.

2. **Primary runtime boundary**
   - The main architectural boundary is:
     **LLM/MCP client → local MCP server → Shopify Partner API**
   - There is no database, queue, web frontend, or intermediate backend operated by this repo.
   - Credentials and configuration stay on the user’s machine via environment variables.

3. **Server layer**
   - `src/shopify_partner_agent/server.py` is the entry point for the MCP server.
   - It is responsible for exposing the 25 tools described in the README and wiring tool names to handler functions.
   - This is the outward-facing interface that Claude Desktop, Claude Code, Cursor, or Windsurf connect to.

4. **API access layer**
   - `src/shopify_partner_agent/client.py` is the Shopify API boundary.
   - It centralizes authenticated requests using `SHOPIFY_ORG_ID`, `SHOPIFY_ACCESS_TOKEN`, and `SHOPIFY_APP_IDS`.
   - This layer likely handles GraphQL transport, pagination, and error handling so the analytics layer doesn’t need to know HTTP details.

5. **Query definition layer**
   - `src/shopify_partner_agent/queries.py` holds the raw Partner API query documents.
   - This isolates Shopify-specific field selection and makes the rest of the code work with structured responses rather than hardcoded GraphQL strings scattered across the app.

6. **Analytics and metric computation**
   - `src/shopify_partner_agent/analytics.py` is the core business-logic engine.
   - It turns raw Partner API data into computed SaaS metrics like MRR, churn, cohorts, health scores, churn risk, forecasts, and merchant digests.
   - The README’s formulas imply this module is where the repo’s main intellectual value lives: it converts event/transaction history into derived metrics the API does not provide directly.

7. **Data model and flow**
   - The main data flow is:
     1. MCP tool call arrives from the client.
     2. Server selects the appropriate analytics function.
     3. Analytics function asks the client layer for Shopify data.
     4. Query layer supplies the GraphQL shape.
     5. Results are transformed into business metrics and returned to the MCP client.
   - Many tools appear to share the same underlying event, transaction, and merchant records, then diverge into different summaries.

8. **Tool grouping suggests shared internal pipelines**
   - The README’s 25 tools cluster into five reusable domains:
     - core data retrieval,
     - revenue analytics,
     - customer analytics,
     - growth/forecasting,
     - merchant intelligence,
     - multi-app comparison.
   - That implies the repo is built around a few canonical datasets: apps, merchants, events, transactions, and churn/retention derived from them.

9. **Multi-app support**
   - The presence of app comparison and revenue anomalies indicates the code can aggregate across multiple apps from `SHOPIFY_APP_IDS`.
   - The architecture therefore supports both per-app and portfolio-level analysis, with app ID as a key partitioning dimension.

10. **Operational model**
   - The package is intended to be launched via `uvx shopify-partner-agent` or installed with `pip`.
   - The MCP client owns process startup, so this repo must expose a clean command-line/server entrypoint and read configuration from the environment at launch time.

11. **Testing boundary**
   - `tests/test_analytics.py` suggests the main automated coverage is on metric computations rather than network integration.
   - That means the highest-value test boundary is the analytics layer, where correctness of formulas and edge cases matter most.

12. **CI/CD and release flow**
   - `.github/workflows/ci.yml` and `publish.yml` indicate standard GitHub Actions automation for validation and PyPI publishing.
   - The repo is distributed as a package, so the build/release boundary is “source code → packaged Python artifact → PyPI → `uvx`/pip consumers.”

13. **Privacy and deployment implications**
   - The README explicitly states there is no telemetry and no cloud relay.
   - Architecturally, that means all sensitive business data only transits between the local machine and Shopify, then from the MCP server to the user’s chosen LLM provider through the MCP client.

14. **Diagram takeaway**
   - If drawing this system, model it as a **local analytics adapter**:
     the MCP client invokes tools, the server orchestrates calls, the client/query modules fetch Partner API data, and the analytics module computes higher-level SaaS metrics before returning structured responses.

Main entry points: [`src/shopify_partner_agent/client.py`](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/client.py) (API client), [`src/shopify_partner_agent/analytics.py`](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py) (Analytics), [`src/shopify_partner_agent/server.py`](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/server.py) (Server), [`.env.example`](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.env.example) (Env vars)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Local runtime"]
  node_mcp_client(("MCP client<br/>local host"))
  node_partner_api[("Partner API<br/>external api")]
  node_env_config["Env vars<br/>config<br/>[.env.example]"]
end

subgraph group_package["Python package"]
  node_server_entry["Server<br/>mcp entrypoint<br/>[server.py]"]
  node_tool_registry["Tool map<br/>handler wiring<br/>[server.py]"]
  node_analytics_core["Analytics<br/>metrics engine<br/>[analytics.py]"]
  node_api_client["API client<br/>shopify boundary<br/>[client.py]"]
  node_query_docs["Queries<br/>graphql docs<br/>[queries.py]"]
  node_tool_outputs["Metric results<br/>structured output"]
  node_app_scope{{"App scope<br/>partitioning"}}
  node_merchant_data[("Merchant data<br/>domain data")]
  node_revenue_models["Revenue models<br/>derived metrics<br/>[analytics.py]"]
  node_customer_models["Customer models<br/>derived metrics<br/>[analytics.py]"]
end

subgraph group_ops["Automation"]
  node_tests["Analytics tests<br/>pytest suite<br/>[test_analytics.py]"]
  node_ci["CI workflow<br/>github actions<br/>[ci.yml]"]
  node_publish["Publish workflow<br/>github actions<br/>[publish.yml]"]
end

node_mcp_client -->|"tool calls"| node_server_entry
node_server_entry -->|"dispatches"| node_tool_registry
node_tool_registry -->|"invokes"| node_analytics_core
node_analytics_core -->|"fetches data"| node_api_client
node_api_client -->|"uses queries"| node_query_docs
node_api_client -->|"requests"| node_partner_api
node_env_config -->|"auth/config"| node_api_client
node_env_config -->|"launch config"| node_server_entry
node_api_client -->|"retrieves"| node_merchant_data
node_merchant_data -->|"partitions by app"| node_app_scope
node_app_scope -->|"feeds"| node_revenue_models
node_app_scope -->|"feeds"| node_customer_models
node_revenue_models -->|"returns"| node_tool_outputs
node_customer_models -->|"returns"| node_tool_outputs
node_analytics_core -->|"emits"| node_tool_outputs
node_tests -->|"verifies"| node_analytics_core
node_ci -->|"runs"| node_tests
node_publish -->|"packages"| node_server_entry

click node_server_entry "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/server.py"
click node_tool_registry "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/server.py"
click node_analytics_core "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py"
click node_api_client "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/client.py"
click node_query_docs "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/queries.py"
click node_env_config "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.env.example"
click node_revenue_models "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py"
click node_customer_models "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py"
click node_tests "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/tests/test_analytics.py"
click node_ci "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.github/workflows/ci.yml"
click node_publish "https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.github/workflows/publish.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mcp_client,node_partner_api,node_env_config toneBlue
class node_server_entry,node_tool_registry,node_analytics_core,node_api_client,node_query_docs,node_tool_outputs,node_app_scope,node_merchant_data,node_revenue_models,node_customer_models toneAmber
class node_tests,node_ci,node_publish toneMint
```

## Components

### Local runtime

MCP client, server, and Shopify API boundary

- **MCP client**: local host · Claude Desktop, Claude Code, Cursor, or Windsurf that starts and calls the server
- **Partner API**: external api · Shopify Partner API data source
- [Env vars](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.env.example): config · SHOPIFY_ORG_ID, SHOPIFY_ACCESS_TOKEN, and SHOPIFY_APP_IDS · `.env.example`

### Python package

Source modules that implement tool orchestration and analytics

- [Server](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/server.py): mcp entrypoint · Exposes tools and routes MCP requests to handlers · `src/shopify_partner_agent/server.py`
- [Tool map](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/server.py): handler wiring · Maps tool names to the underlying analytics functions · `src/shopify_partner_agent/server.py`
- [Analytics](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py): metrics engine · Computes revenue, retention, cohort, forecast, and merchant intelligence metrics · `src/shopify_partner_agent/analytics.py`
- [API client](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/client.py): shopify boundary · Handles authenticated Partner API requests, pagination, and errors · `src/shopify_partner_agent/client.py`
- [Queries](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/queries.py): graphql docs · Reusable Partner API query documents and field selections · `src/shopify_partner_agent/queries.py`
- **Metric results**: structured output · Computed SaaS metrics returned to the MCP client
- **App scope**: partitioning · Per-app and portfolio-level aggregation keyed by app IDs
- **Merchant data**: domain data · Apps, merchants, events, and transactions pulled from Shopify
- [Revenue models](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py): derived metrics · MRR, churn, revenue anomalies, and forecast inputs · `src/shopify_partner_agent/analytics.py`
- [Customer models](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/src/shopify_partner_agent/analytics.py): derived metrics · Cohorts, health scores, churn risk, and retention views · `src/shopify_partner_agent/analytics.py`

### Automation

Tests and release workflows

- [Analytics tests](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/tests/test_analytics.py): pytest suite · Validates metric formulas and edge cases · `tests/test_analytics.py`
- [CI workflow](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.github/workflows/ci.yml): github actions · Runs validation for the package · `.github/workflows/ci.yml`
- [Publish workflow](https://github.com/rushikeshmore/shopify-partner-agent/blob/main/.github/workflows/publish.yml): github actions · Builds and releases the package to PyPI · `.github/workflows/publish.yml`

## Connections

- MCP client → Server: tool calls · Client invokes MCP tools on the local server
- Server → Tool map: dispatches · Server resolves each tool name to a handler
- Tool map → Analytics: invokes · Handlers call the analytics layer for computation
- Analytics → API client: fetches data · Analytics requests Shopify data through the API boundary
- API client → Queries: uses queries · Client applies query documents when calling Partner API
- API client → Partner API: requests · Authenticated GraphQL requests to Shopify
- Env vars → API client: auth/config · Environment variables configure access and app scope
- Env vars → Server: launch config · Server reads local configuration at startup
- API client → Merchant data: retrieves · Pulls apps, merchants, events, and transactions
- Merchant data → App scope: partitions by app · Shared datasets are grouped by app ID
- App scope → Revenue models: feeds · Partitioned data drives revenue calculations
- App scope → Customer models: feeds · Partitioned data drives customer analytics
- Revenue models → Metric results: returns · Revenue-derived results are formatted for MCP clients
- Customer models → Metric results: returns · Customer-derived results are formatted for MCP clients
- Analytics → Metric results: emits · Analytics functions produce structured responses
- Analytics tests → Analytics: verifies · Test coverage focuses on metric computation correctness
- CI workflow → Analytics tests: runs · CI executes the test suite
- Publish workflow → Server: packages · Release workflow publishes the installable server package
