Skip to content

Commit 06b0d19

Browse files
committed
add agents.md file
1 parent f7b1cc6 commit 06b0d19

1 file changed

Lines changed: 308 additions & 0 deletions

File tree

agents.md

Lines changed: 308 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,308 @@
1+
# Next Commerce Developer Documentation — Agent Context
2+
3+
> This file is a contextual reference for AI agents and onboarding developers. It maps the platform architecture, documentation structure, conventions, and known gaps to enable effective navigation, contribution, and refactoring of the developer docs.
4+
5+
## Platform Overview
6+
7+
Next Commerce is a multi-channel ecommerce platform. Merchants manage a single store while selling through multiple independent sales channels. All channels funnel orders, customers, and transaction data into the central store.
8+
9+
Three sales channels and three APIs form the core developer surface:
10+
11+
```
12+
┌─────────────────────────────────────────────────────────┐
13+
│ Next Commerce Store │
14+
│ (Orders, Products, Customers, Subscriptions) │
15+
├──────────────┬──────────────────┬───────────────────────┤
16+
│ Storefront │ Campaigns │ Admin API │
17+
│ Themes │ (External DTC │ (Server-to-Server) │
18+
│ (Catalog + │ Funnels) │ │
19+
│ Checkout) │ │ │
20+
├──────────────┼──────────────────┼───────────────────────┤
21+
│ Storefront │ Campaigns API │ Admin API │
22+
│ API (GraphQL)│ (REST, CORS) │ (REST, OAuth 2.0) │
23+
└──────────────┴──────────────────┴───────────────────────┘
24+
▲ ▲ ▲
25+
│ │ │
26+
Webhooks ─────── Event Backbone ──────┘
27+
(23 event types, HMAC signed, versioned)
28+
```
29+
30+
---
31+
32+
## Sales Channels
33+
34+
### 1. Storefront Themes
35+
36+
Full-featured online store with product catalog, collections, customer accounts, and built-in checkout.
37+
38+
- **Template language** — Jinja-like with custom tags, filters, and objects (products, cart, customer, etc.)
39+
- **Theme Kit CLI** — local development, watch mode, Git-based deployment
40+
- **Theme structure**`assets/`, `checkout/`, `configs/`, `layouts/`, `locales/`, `partials/`, `sass/`, `templates/`
41+
- **Settings**`settings_schema.json` defines merchant-configurable options rendered in the dashboard
42+
- **Storefront API** — GraphQL API accessible within the storefront context for cart mutations and data queries
43+
- **CDN & caching** — built-in asset CDN with cache management
44+
45+
**Primary audience:** Theme developers building branded shopping experiences.
46+
47+
### 2. Campaigns
48+
49+
Isolated external sales funnels for DTC (direct-to-consumer) marketers. Each campaign has its own packages, offers, shipping options, and API key. No backend required — campaigns run entirely client-side.
50+
51+
**Core concepts:**
52+
- **Campaign** — top-level config tying together packages, offers, shipping, payment methods, currency
53+
- **Packages** — virtual product+quantity+price bundles (not actual products; mapped to store variants)
54+
- **Offers** — automatic or code-based discounts based on package quantity
55+
- **Flow** — Landing → Checkout → Upsell(s) → Receipt
56+
57+
**Two integration approaches:**
58+
59+
| Approach | Method | Best For |
60+
|----------|--------|----------|
61+
| **Campaign Cart SDK** | Declarative HTML `data-next-*` attributes + optional JS API | Fast development, no custom JS needed |
62+
| **Campaigns API** | Headless REST API (CORS-enabled, API key auth) | Full programmatic control |
63+
64+
**Campaign Cart SDK features:**
65+
- `window.nextConfig` or meta tag configuration
66+
- Data attributes for actions, display, checkout, profiles, state
67+
- JavaScript API with methods and events (`add_to_cart`, `begin_checkout`, `purchase`)
68+
- Analytics integrations (GTM, Meta Pixel, GA4, RudderStack, custom webhooks)
69+
- Utilities: FOMO notifications, exit intent, loading states, debugger
70+
- Post-purchase upsell flows
71+
72+
**Primary audience:** DTC marketers and frontend developers building high-converting campaign funnels.
73+
74+
### 3. Admin API (as Sales Channel)
75+
76+
The Admin API supports a complete order creation flow with payment processing, enabling fully custom checkout experiences built server-side. This makes it a sales channel in its own right — not just a management API.
77+
78+
**Key capabilities as a channel:**
79+
- Create orders with payment (credit card, PayPal, Klarna, Apple Pay, Google Pay, etc.)
80+
- External checkout flow with server-side control
81+
- 3DS2 authentication support
82+
- Subscription/recurring billing creation
83+
- iFrame payment form for PCI-compliant card collection
84+
85+
**Primary audience:** Backend developers building custom commerce applications, integrations, and services.
86+
87+
---
88+
89+
## APIs
90+
91+
### Storefront API
92+
- **Type:** GraphQL
93+
- **Auth:** Accessible only within storefront context (on the store domain)
94+
- **Capabilities:** Cart management (`createCart`, `addCartLines`, `removeCartLines`), product/collection queries
95+
- **Discovery:** GraphiQL explorer available in-browser on the storefront
96+
- **Docs:** `docs/storefront/api.md` (single file)
97+
- **Note:** External access planned but not yet available
98+
99+
### Campaigns API
100+
- **Type:** REST, CORS-enabled (browser-safe)
101+
- **Auth:** Campaign API key
102+
- **Capabilities:** Cart creation, order creation, upsell creation, order retrieval, session tracking, shipping options
103+
- **OpenAPI spec:** `static/api/campaigns/v1.yaml`
104+
- **Docs:** `docs/api/campaigns.md`
105+
106+
### Admin API
107+
- **Type:** REST
108+
- **Auth:** OAuth 2.0 with permission scoping
109+
- **Rate limit:** 4 requests/second
110+
- **Versions:**
111+
- `2023-02-10` — stable
112+
- `2024-04-01` — stable, recommended
113+
- `unstable` — development
114+
- **Capabilities:** Full CRUD on all store resources (orders, products, customers, subscriptions, fulfillments, gateways, webhooks, etc.)
115+
- **OpenAPI specs:** `static/api/admin/2023-02-10.yaml`, `static/api/admin/2024-04-01.yaml`, `static/api/admin/unstable.yaml`
116+
- **Docs:** `docs/api/admin/` (overview, permissions, 15 feature guides)
117+
118+
**Admin API guides focus areas:**
119+
- Payment methods: Apple Pay, Google Pay, PayPal, Klarna, Bancontact, iDEAL, SEPA Debit, TWINT, 3DS2
120+
- Core features: External Checkout, Order Management, Subscription Management, Testing
121+
- Payment collection: iFrame Payment Form
122+
123+
---
124+
125+
## Webhooks
126+
127+
Event-driven notifications for external systems to stay synced with store activity.
128+
129+
- **23 event types** spanning: app, cart, customer, dispute, fulfillment, gateway, order, product, subscription, store, ticket, transaction
130+
- **Payload structure:** `{ object, data, event_id, event_type, webhook, api_version }`
131+
- **Verification:** HMAC SHA256 via `X-29Next-Signature` header
132+
- **Retry policy:** Up to 10 retries with exponential backoff; failing webhooks trigger admin email notifications and eventual deactivation
133+
- **Versioning:** Payload data structures align with Admin API versions
134+
- **Setup:** Dashboard (Settings > Webhooks) or Admin API
135+
- **Docs:** `docs/webhooks.md` (single comprehensive file)
136+
137+
---
138+
139+
## Apps
140+
141+
Apps extend platform functionality by combining Admin API, Webhooks, and Storefront hooks into installable packages.
142+
143+
**Two app types:**
144+
- **Server-to-Server** — backend integrations (fulfillment services, dispute management, external reporting)
145+
- **Storefront Extensions** — inject snippets, scripts, and event tracking into themes
146+
147+
**App infrastructure:**
148+
- OAuth 2.0 authorization code flow for installation
149+
- Manifest-driven configuration
150+
- Remote settings management
151+
- Asset hosting for static files
152+
- Snippet injection into storefronts
153+
- Event tracking integration
154+
- App review process for publishing
155+
156+
**Docs:** `docs/apps/` (18 files covering development flow, OAuth, manifests, settings, guides)
157+
158+
---
159+
160+
## Documentation Structure
161+
162+
```
163+
docs/
164+
├── index.md → Getting Started landing page
165+
├── api/
166+
│ ├── index.md → APIs overview
167+
│ ├── campaigns.md → Campaigns API overview + endpoints
168+
│ ├── checkout-links.md → Checkout Links feature
169+
│ └── admin/
170+
│ ├── index.md → Admin API overview + auth
171+
│ ├── permissions.md → OAuth permission scopes
172+
│ └── guides/ → 15 feature guides (payments, orders, subscriptions)
173+
├── apps/
174+
│ ├── index.md → Apps overview
175+
│ ├── app-kit.md → App development framework
176+
│ ├── app-development-flow.md → End-to-end dev process
177+
│ ├── manifest.md → App manifest spec
178+
│ ├── settings.md → Remote settings
179+
│ ├── assets.md → Asset hosting
180+
│ ├── snippets.md → Storefront code injection
181+
│ ├── event-tracking.md → Storefront event hooks
182+
│ ├── review.md → App review process
183+
│ ├── oauth/ → OAuth flows (4 files)
184+
│ └── guides/ → App pattern guides (4 files)
185+
├── campaigns/
186+
│ └── index.md → Campaign concepts + getting started
187+
├── campaign-cart/ → Campaign Cart SDK (largest section, ~48 files)
188+
│ ├── index.md → Quick start + configuration
189+
│ ├── data-attributes/ → HTML attribute reference (8 files)
190+
│ ├── javascript-api/ → JS API reference (5 files)
191+
│ ├── analytics/ → Analytics integrations (9+ files)
192+
│ ├── guides/ → Implementation guides
193+
│ ├── utilities/ → FOMO, exit intent, loading, debugger
194+
│ └── upsells/ → Post-purchase upsell flows
195+
├── storefront/
196+
│ ├── index.md → Storefront overview
197+
│ ├── api.md → Storefront GraphQL API
198+
│ ├── event-tracking.md → Event tracking
199+
│ └── themes/
200+
│ ├── index.md → Theme structure + basics
201+
│ ├── settings.md → Theme settings schema
202+
│ ├── theme-kit.md → Theme Kit CLI
203+
│ ├── cdn-and-caching.md → CDN strategies
204+
│ ├── translations.md → Multi-language
205+
│ ├── templates/ → Template language reference (5 files)
206+
│ └── guides/ → Theme how-to guides (4 files)
207+
└── webhooks.md → Webhook events + verification
208+
209+
static/api/
210+
├── admin/
211+
│ ├── 2023-02-10.yaml → Admin API v1 OpenAPI spec
212+
│ ├── 2024-04-01.yaml → Admin API v2 OpenAPI spec
213+
│ └── unstable.yaml → Admin API unstable spec
214+
└── campaigns/
215+
└── v1.yaml → Campaigns API OpenAPI spec
216+
```
217+
218+
---
219+
220+
## Documentation Conventions
221+
222+
### Tooling
223+
- **Docusaurus** with MDX support
224+
- **Stoplight Elements** for rendering OpenAPI specs inline
225+
- **Algolia** for search
226+
- **Tailwind CSS** for custom components
227+
- **Sidebar:** auto-generated from directory structure (`sidebars.js`)
228+
229+
### Content Patterns
230+
- **Frontmatter:** `title`, `sidebar_label`, `sidebar_position`
231+
- **Admonitions:** `:::tip`, `:::caution`, `:::info` for callouts
232+
- **Diagrams:** Mermaid (`graph`, `sequenceDiagram`) for flows and architecture
233+
- **Code examples:** JavaScript, Python, cURL — fenced with language + optional `title="..."`
234+
- **Tables:** Markdown tables for comparisons, event lists, attribute references
235+
- **Cross-links:** Relative markdown links (`[text](/docs/path/to/file.md)`)
236+
- **API references:** Link to Stoplight-rendered specs (`/docs/api/admin/reference/#/...`)
237+
- **MDX components:** `DocCardList`, `IntroCards` for auto-generated navigation cards
238+
239+
### URL Structure
240+
All published docs follow: `https://developers.29next.com/docs/{section}/{path}`
241+
242+
Key redirects configured in `docusaurus.config.js`:
243+
- `/api/``/docs/api`
244+
- `/api/admin``/docs/api/admin/`
245+
- `/themes``/docs/storefront/themes`
246+
- `/webhooks``/docs/webhooks`
247+
248+
---
249+
250+
## Documentation Gaps & Refactoring Opportunities
251+
252+
### High Priority
253+
254+
1. **Storefront API is underdocumented**
255+
- Currently a single brief file (`docs/storefront/api.md`) pointing to GraphiQL
256+
- Needs: query/mutation reference, authentication details, available types and fields, usage examples
257+
- Consider: auto-generated reference from GraphQL schema, tutorial-style guides for common operations
258+
259+
2. **Admin API guides skew toward payment methods**
260+
- 15 guides, most are payment-specific (Apple Pay, Google Pay, PayPal, Klarna, etc.)
261+
- Missing guides for common workflows: product CRUD, customer management, bulk operations, inventory management
262+
- Opportunity: add "Getting Started with Admin API" tutorial covering basic resource operations
263+
264+
3. **No error handling guide**
265+
- No comprehensive documentation on error response formats, common error codes, or handling strategies across APIs
266+
- Each API should document its error format and common failure scenarios
267+
268+
### Medium Priority
269+
270+
4. **Rate limiting & quotas**
271+
- Admin API mentions 4 req/s but no strategies for handling limits, queuing, or backoff
272+
- No rate limit documentation for Campaigns API or Storefront API
273+
274+
5. **No troubleshooting or FAQ sections**
275+
- Common issues (webhook delivery failures, OAuth token expiry, theme deployment problems) lack dedicated troubleshooting docs
276+
277+
6. **Security best practices**
278+
- Beyond "don't expose tokens" and webhook HMAC verification, no comprehensive security guide
279+
- Topics: API key rotation, OAuth token storage, CSP headers for campaign pages, PCI considerations
280+
281+
7. **Testing guide is isolated**
282+
- Single testing guide in Admin API section; no testing guidance for campaigns, themes, or apps
283+
- Opportunity: cross-cutting testing guide or per-section testing docs
284+
285+
### Lower Priority
286+
287+
8. **Getting Started page is thin**
288+
- `docs/index.md` relies on an `IntroCards` component — could benefit from a brief narrative overview of the platform before the cards
289+
290+
9. **Campaign Cart SDK docs could use restructuring**
291+
- At 48 files it's the largest section but has some organizational inconsistencies
292+
- Analytics subsection is thorough but could link back to concepts more clearly
293+
294+
10. **Cross-linking between related sections**
295+
- Campaigns intro (`docs/campaigns/`) could link more explicitly to both SDK and API docs
296+
- Webhook docs could link to app guides that consume webhooks (fulfillment service, dispute service)
297+
- Admin API guides could cross-reference relevant webhook events
298+
299+
---
300+
301+
## Key Repositories
302+
303+
| Repository | Purpose |
304+
|------------|---------|
305+
| `developer-docs` | This documentation site (Docusaurus) |
306+
| `campaign-cart-example` | Campaign Cart starter template |
307+
| `intro` / `intro-bootstrap` | Starter storefront themes |
308+
| Open-source example apps | Referenced in app documentation |

0 commit comments

Comments
 (0)