# stripe/example-mobile-backend architecture

> Architecture diagram of the GitHub repository stripe/example-mobile-backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stripe/example-mobile-backend
- Repository: https://github.com/stripe/example-mobile-backend

## Overview

##### Project type and purpose
- This is a minimal Ruby-based example of a mobile backend for processing payments via Stripe.
- It exposes an HTTP API (web.rb) that mobile clients (iOS/Android apps) call when they need to create charges or fetch payment intent data.
- It’s deployed as a single microservice (Heroku/Glitch) and delegates all payment logic to the Stripe API.

##### File structure
- Top-level files only—no frontend code.
- web.rb – the entire Ruby HTTP service (likely Sinatra or Rack).
- Gemfile & Gemfile.lock – dependencies (stripe gem, rack/sinatra).
- Procfile & app.json – deployment configuration (Heroku or Glitch).
- .ruby-version – Ruby runtime version.
- .github/ISSUE_TEMPLATE.md, LICENSE, .gitignore – admin/config.
- No database folder or ORM config implies stateless endpoints; all state managed by Stripe.

##### README
- Notes deprecation and points to a hosted Glitch example.
- The “Accept a Payment” guide describes how mobile SDKs interact with a backend to create PaymentIntents.

##### Detailed capture of essential elements
- Call out environment variables (STRIPE_SECRET_KEY).
- If desired, show CI/CD or GitHub integration (the .github folder and where tests or templates would fit).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Clients
    subgraph "Mobile Clients"
        direction TB
        IOS["iOS App"]:::client
        Android["Android App"]:::client
    end

    %% Backend Service
    subgraph "Example Stripe Mobile Backend"
        direction TB
        Backend["web.rb (Ruby HTTP API)"]:::service
        Gemfile["Gemfile"]:::config
        GemfileLock["Gemfile.lock"]:::config
        Procfile["Procfile"]:::config
        AppJson["app.json"]:::config
        RubyVersion[".ruby-version"]:::config
        IssueTemplate[".github/ISSUE_TEMPLATE.md"]:::config
        Gitignore[".gitignore"]:::config
        License["LICENSE"]:::config
        Readme["README.md"]:::config
    end

    %% Hosting Platform
    Heroku["Heroku / Glitch Runtime"]:::platform

    %% External Service
    Stripe["Stripe API / Payment Gateway"]:::external

    %% Connections
    IOS -->|"Create Payment Intent"| Backend
    Android -->|"Create Payment Intent"| Backend
    Backend -->|"Returns client_secret / status"| IOS
    Backend -->|"Returns client_secret / status"| Android
    Backend -->|"API call using STRIPE_SECRET_KEY"| Stripe
    Stripe -->|"Webhook callback (optional)"| Backend
    Backend -.runs on.-> Heroku

    %% Click Events
    click Backend "https://github.com/stripe/example-mobile-backend/blob/master/web.rb"
    click Gemfile "https://github.com/stripe/example-mobile-backend/tree/master/Gemfile"
    click GemfileLock "https://github.com/stripe/example-mobile-backend/blob/master/Gemfile.lock"
    click Procfile "https://github.com/stripe/example-mobile-backend/tree/master/Procfile"
    click AppJson "https://github.com/stripe/example-mobile-backend/blob/master/app.json"
    click RubyVersion "https://github.com/stripe/example-mobile-backend/blob/master/.ruby-version"
    click IssueTemplate "https://github.com/stripe/example-mobile-backend/blob/master/.github/ISSUE_TEMPLATE.md"
    click Gitignore "https://github.com/stripe/example-mobile-backend/blob/master/.gitignore"
    click License "https://github.com/stripe/example-mobile-backend/tree/master/LICENSE"
    click Readme "https://github.com/stripe/example-mobile-backend/blob/master/README.md"

    %% Styles
    classDef client fill:#cce5ff,stroke:#3399ff;
    classDef service fill:#d4edda,stroke:#28a745;
    classDef external fill:#fff3cd,stroke:#ffc107;
    classDef platform fill:#e2e3e5,stroke:#6c757d;
    classDef config fill:#f8d7da,stroke:#dc3545;
```
