Docs / Architecture
Docs / Architecture v0.1.0-alpha.1

Architecture

Six packages, one direction of dependency, and one server endpoint that decides the price and re-checks the route.

Packages

@tenderlane/core            no dependencies, names no provider
   ├─ .                     types, rules router, catalogs, errors
   ├─ /server               createTenderlaneHandler (Web Request/Response)
   └─ /adapters             what an adapter author needs
        │
        ├── @tenderlane/client     headless checkout state machine
        │      ├── @tenderlane/react   provider, hook, form
        │      └── @tenderlane/vue     plugin and composables (experimental)
        │
        ├── @tenderlane/stripe     .  /server  /react
        └── @tenderlane/polar      .  /server
PackageOwnsDoes not own
@tenderlane/coreThe contracts every other package implements, route evaluation, price resolution, the server handlerAny provider SDK, any framework, any state
@tenderlane/clientThe checkout state machine: route selection, prepare, submit, one submit at a timeRendering, HTTP (providers do that)
@tenderlane/reactSubscribing React to the client; calling prepare at the right time for inline flowsBusiness logic, markup
@tenderlane/stripe, @tenderlane/polarTranslating between Tenderlane’s contracts and one providerRouting, pricing
@tenderlane/vueSubscribing Vue to the clientInline payment elements (hosted flows only)

Dependencies point one way: adapters and the client depend on core, bindings depend on the client. Core imports nothing.

Browser and server entries

Each adapter package has a browser entry and a server entry:

  • @tenderlane/stripe runs in the browser and never imports the stripe npm package. It holds the publishable key only.
  • @tenderlane/stripe/server imports stripe and holds the secret key.

The split is enforced by package.json subpath exports, so importing the server adapter into a client bundle is an explicit, visible import and not an accident of tree shaking.

Data flow of one checkout

1. App state changes          context = { country: 'CH' }
2. Router (browser)           route = { provider: 'stripe', flow: 'inline' }
3. Client                     status: ready
4. inline only: prepare()     POST /api/payments { provider, action, payload: { items: [{ sku, quantity }], ... } }
5. Handler (server)           validate → derive context → evaluate the same router
                              → price items from the catalog → call the server adapter
6. Server adapter             provider API call with the secret key
7. Response                   { provider, id, status, url? , clientSecret? }   nothing else
8. Browser provider           hosted: redirect to url
                              inline: mount the element, submit() confirms it
9. Client                     status: redirecting | pending | success | error

Steps 5 to 7 are described in Server and price integrity.

Extension points that exist

ExtensionHowExample in the repository
Another payment providerdefineBrowserProvider, defineServerAdapter from @tenderlane/core/adaptersexamples/react-checkout-multi-psp/app/demo-psp
Another source of pricesdefineCatalog({ resolve })packages/stripe/src/server/catalog.ts
Another routing strategyAny object with evaluate(context); it may be asyncpackages/client/__tests__/client.test.ts
Observing the lifecyclemiddleware: [{ onRouteEvaluated, onCheckoutStart, ... }]packages/core/src/types/middleware.ts
Another UI frameworkclient.subscribe and client.getSnapshotpackages/vue/src/index.ts (about 150 lines)

There is no plugin registry and no event bus. Middleware observes; it cannot change a route or a price.

Design choices

Rules are data. A rule is a JSON object, so the same rules run in the browser and on the server, and can be stored or generated. The predicates option takes functions for the cases JSON cannot express; those cannot be serialized.

The router is shared, the decision is not trusted. The browser evaluates the router to render the right UI immediately. The server evaluates it again with the context it believes and rejects a mismatch.

No amount on the wire. CheckoutInput has no price field. See Server and price integrity.

Provider ids are literals. stripeProvider() returns a provider whose id has type 'stripe'. createRulesRouter infers the union of ids its rules target, and the client and handler require that union to be registered. See Routing.

Errors from another package are matched by code. Every error extends TenderlaneError and carries a string code. Code that handles errors from another package checks hasErrorCode(error, 'CATALOG_ERROR') and not instanceof, which breaks when two copies of a package are installed.