---
title: "Architecture"
description: "How EdgeCart's Workers, bindings, and commerce packages fit together."
---

> Documentation Index
> Fetch the complete documentation index at: https://edgecart.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

EdgeCart deploys as a small set of Cloudflare Workers that share one D1
database. The main Worker serves the storefront, the admin, and the API; the
plugin and outbox Workers handle work that should not run in the request path.

## Workers

| Worker | Responsibility |
|---|---|
| `edgecart` | Storefront, admin, Hono API, Better Auth, D1 access, image uploads. |
| `edgecart-plugins` | Plugin kernel: releases, installs, settings, and Dynamic Worker execution. |
| `edgecart-plugin-assets` | Serves plugin assets from R2 with strict content and framing rules. |
| `edgecart-outbox` | Queue consumer for webhooks, email, and async plugin hooks; runs a one-minute cron. |

## Bindings on the main Worker

| Binding | Type | Use |
|---|---|---|
| `DB` | D1 | Commerce, auth, plugin control-plane, and outbox data. |
| `UPLOADS` | R2 | Product and store images. |
| `OUTBOX_QUEUE` | Queue producer | Writes events for the outbox worker. |
| `PLUGIN_KERNEL` | Service binding | Calls the plugin kernel over RPC. |
| Rate limiters | Cloudflare rate limiting | Basic (100/min) and strict (3/min) route limits. |

The plugin kernel has its own `DB` (the same D1 database), an R2 bucket for
plugin bundles, and a `LOADER` binding for Dynamic Workers. Dynamic Workers
require the Workers Paid plan in production.

## Request flow

```text
Browser
  │
  ├─ /            → storefront shell → Storefront API → D1
  ├─ /admin       → admin console  → Admin API     → D1
  └─ /api/*       → Hono routes    → commerce packages → D1
                                      │
                                      ├─ R2 (uploads)
                                      ├─ Queue (outbox)
                                      └─ Service binding (plugin kernel)
```

- The storefront loads `/api/storefront-config` first to get the store profile,
  locale, region, and publishable key, then calls the keyed Store API.
- Admin requests carry the Better Auth session cookie and an `x-store-id`
  header.
- Mutations write audit and outbox rows in the same transaction; the outbox
  worker delivers webhooks, email, and plugin hooks asynchronously.

## Commerce packages

Commerce behavior is split into narrow packages with an enforced dependency
direction:

```text
commerce-core
  ├─ commerce-sales, commerce-catalog
  ├─ commerce-cart, commerce-storefront
  ├─ commerce-orders
  ├─ commerce-payments
  ├─ commerce-order-changes
  └─ commerce-observability
```

The public [Commerce modules](https://edgecart.dev/modules/) section explains each domain; the
[package boundaries](https://edgecart.dev/developers/packages) page covers the implementation
rules. `packages/commerce` is a compatibility facade for existing imports.

## What runs where

- **Request path** — the main Worker and the commerce packages. No plugin code
  runs in the main Worker.
- **Plugin execution** — the plugin kernel invokes a plugin bundle in a Dynamic
  Worker; the host validates and applies the result.
- **Background work** — the outbox worker consumes the queue on a one-minute
  cron and on queue delivery.

## Related

- [Local development](https://edgecart.dev/developers/local-development)
- [Deployment](https://edgecart.dev/developers/deployment)
- [Commerce modules](https://edgecart.dev/modules/)

Source: https://edgecart.dev/developers/architecture/index.mdx
