# stellar-sub/stellar-subscriptions-contracts architecture

> Architecture diagram of the GitHub repository stellar-sub/stellar-subscriptions-contracts, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stellar-sub/stellar-subscriptions-contracts
- Repository: https://github.com/stellar-sub/stellar-subscriptions-contracts

## Overview

This repository provides three Soroban contracts for recurring Stellar payments: merchants publish reusable plans, subscribers authorize bounded and revocable subscriptions, and a registry indexes contract activity for dashboards and indexers. The main workflow is subscription authorization followed by merchant-initiated periodic charges, with token transfers and optional registry reporting. The subscription contract also supports pause, resume, cancel, allowance repair, and lookup; plans can be deactivated. Edges reflect the README and excerpted sources; unsampled implementation details are not inferred.

Main entry points: [`contracts/subscription/src/lib.rs`](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/lib.rs) (Subscription contract), [`contracts/plan/src/lib.rs`](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/plan/src/lib.rs) (Plan contract), [`contracts/registry/src/lib.rs`](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/registry/src/lib.rs) (Registry contract), [`contracts/subscription/src/allowance.rs`](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/allowance.rs) (Allowance manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plans["Billing plans"]
  node_plan_contract["Plan contract<br/>[lib.rs]"]
  node_plan_storage[("Plan storage<br/>[storage.rs]")]
end

subgraph group_subscriptions["Subscription payments"]
  node_subscription_contract["Subscription contract<br/>[lib.rs]"]
  node_subscription_storage[("Subscription storage<br/>[storage.rs]")]
  node_allowance["Allowance manager<br/>[allowance.rs]"]
  node_contract_clients["Cross-contract clients<br/>[interfaces.rs]"]
  node_subscription_events["Subscription events<br/>[events.rs]"]
end

subgraph group_registry["Registry and reporting"]
  node_registry_contract["Registry contract<br/>[lib.rs]"]
  node_registry_storage[("Registry storage<br/>[storage.rs]")]
end

node_subscriber(("Subscriber"))
node_merchant(("Merchant"))
node_admin(("Admin"))
node_token[("Stellar token")]

node_merchant -->|"creates plans"| node_plan_contract
node_merchant -->|"charges"| node_subscription_contract
node_subscriber -->|"authorizes and manages"| node_subscription_contract
node_admin -->|"links registry"| node_plan_contract
node_admin -->|"links contracts"| node_subscription_contract
node_admin -->|"sets writers"| node_registry_contract
node_plan_contract -->|"reads and writes"| node_plan_storage
node_merchant -.->|"queries indexes"| node_registry_contract
node_subscription_contract -->|"reads and writes"| node_subscription_storage
node_subscription_contract -->|"syncs allowance"| node_allowance
node_allowance -->|"approves spending"| node_token
node_subscription_contract -->|"transfers charges"| node_token
node_subscription_contract -->|"uses clients"| node_contract_clients
node_subscription_contract -->|"validates plan"| node_plan_contract
node_subscription_contract -->|"registers and reports"| node_registry_contract
node_plan_contract -->|"registers plans"| node_registry_contract
node_subscription_contract -->|"publishes events"| node_subscription_events
node_registry_contract -->|"reads and writes"| node_registry_storage

click node_plan_contract "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/plan/src/lib.rs"
click node_plan_storage "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/plan/src/storage.rs"
click node_subscription_contract "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/lib.rs"
click node_subscription_storage "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/storage.rs"
click node_allowance "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/allowance.rs"
click node_contract_clients "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/interfaces.rs"
click node_subscription_events "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/events.rs"
click node_registry_contract "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/registry/src/lib.rs"
click node_registry_storage "https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/registry/src/storage.rs"

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_plan_contract,node_plan_storage toneBlue
class node_subscription_contract,node_subscription_storage,node_allowance,node_contract_clients,node_subscription_events,node_token toneAmber
class node_registry_contract,node_registry_storage toneMint
class node_subscriber,node_merchant,node_admin toneIndigo
```

## Components

### Billing plans

- [Plan contract](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/plan/src/lib.rs): `contracts/plan/src/lib.rs`
- [Plan storage](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/plan/src/storage.rs): `contracts/plan/src/storage.rs`

### Subscription payments

- [Subscription contract](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/lib.rs): `contracts/subscription/src/lib.rs`
- [Subscription storage](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/storage.rs): `contracts/subscription/src/storage.rs`
- [Allowance manager](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/allowance.rs): `contracts/subscription/src/allowance.rs`
- [Cross-contract clients](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/interfaces.rs): `contracts/subscription/src/interfaces.rs`
- [Subscription events](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/subscription/src/events.rs): `contracts/subscription/src/events.rs`

### Registry and reporting

- [Registry contract](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/registry/src/lib.rs): `contracts/registry/src/lib.rs`
- [Registry storage](https://github.com/stellar-sub/stellar-subscriptions-contracts/blob/main/contracts/registry/src/storage.rs): `contracts/registry/src/storage.rs`

### Other components

- **Subscriber**
- **Merchant**
- **Admin**
- **Stellar token**

## Connections

- Merchant → Plan contract: creates plans (evidence: `README.md`)
- Merchant → Subscription contract: charges (evidence: `README.md`)
- Subscriber → Subscription contract: authorizes and manages (evidence: `README.md`)
- Admin → Plan contract: links registry (evidence: `contracts/plan/src/lib.rs`)
- Admin → Subscription contract: links contracts (evidence: `contracts/subscription/src/lib.rs`)
- Admin → Registry contract: sets writers (evidence: `README.md`)
- Plan contract → Plan storage: reads and writes (evidence: `contracts/plan/src/lib.rs`)
- Merchant → Registry contract: queries indexes
- Subscription contract → Subscription storage: reads and writes (evidence: `contracts/subscription/src/lib.rs`)
- Subscription contract → Allowance manager: syncs allowance (evidence: `contracts/subscription/src/lib.rs`)
- Allowance manager → Stellar token: approves spending (evidence: `contracts/subscription/src/allowance.rs`)
- Subscription contract → Stellar token: transfers charges (evidence: `README.md`)
- Subscription contract → Cross-contract clients: uses clients (evidence: `contracts/subscription/src/lib.rs`)
- Subscription contract → Plan contract: validates plan (evidence: `contracts/subscription/src/lib.rs`)
- Subscription contract → Registry contract: registers and reports (evidence: `README.md`)
- Plan contract → Registry contract: registers plans (evidence: `contracts/plan/src/lib.rs`)
- Subscription contract → Subscription events: publishes events (evidence: `contracts/subscription/src/lib.rs`)
- Registry contract → Registry storage: reads and writes (evidence: `contracts/registry/src/lib.rs`)
