# rsusik/stripe-fastapi-demo architecture

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

- Interactive diagram: https://gitdiagram.com/rsusik/stripe-fastapi-demo
- Repository: https://github.com/rsusik/stripe-fastapi-demo

## Overview

##### Project type and purpose
- This is a lightweight full-stack sample application demonstrating how to integrate Stripe’s prebuilt checkout page using FastAPI on the backend and static HTML/JavaScript on the frontend.
- The goal is to accept payments via Stripe Checkout with minimal custom code.

##### File structure
Top-level files and folders:
- .env.example, .gitignore, README.md, etc. – project-wide configuration and metadata
- client/ – static frontend assets (HTML, CSS, JS) for user interaction
- server/ – backend API powered by FastAPI, responsible for creating Stripe Checkout sessions
Key observations:
- The server directory contains server.py and requirements.txt, indicating a single service.
- No database folder—persistent state is managed by Stripe.
- Environment files (.env.example) on both root and server levels for API keys and configuration.

##### README for additional insights
- Confirms the use of FastAPI and Stripe’s Python SDK.
- Emphasizes this is the “prebuilt checkout page” flow: redirect user to Stripe’s hosted checkout.
- No custom payment logic beyond session creation—no multiple microservices or complex orchestration.

##### Components
a. Main components
- Client UI (Static website)
– index.html, success.html, canceled.html
– CSS modules (global.css, normalize.css)
– success.js for post-checkout logic
- Backend API (FastAPI service)
– server.py – exposes endpoints to create a Stripe Checkout session
– requirements.txt – dependencies including fastapi, stripe
- Stripe External Service
– Stripe Checkout hosted page
– Webhook callbacks (if implemented or future extension)
- Configuration
– Environment variables (.env) for Stripe secret key, webhook signing secret
b. Relationships and data flow
1. User visits client/index.html (served by static host or directly opened).
2. Frontend JavaScript calls backend (e.g., POST /create-checkout-session) with purchase details.
3. FastAPI endpoint uses Stripe SDK to create a Checkout Session and returns session ID.
4. Frontend redirects the browser to Stripe’s hosted URL.
5. User completes payment on Stripe.
6. Stripe redirects user back to success.html or canceled.html.
c. Architectural patterns and design principles
- Separation of concerns: static assets (client) vs. business logic (server)
- Minimal backend: no local database, delegating state to Stripe
- Environment-driven configuration for keys and secrets
d. Key technologies and frameworks
- FastAPI for backend routing and JSON responses
- Stripe Python SDK for session creation
- Plain HTML/CSS/JavaScript for frontend
- Environment variables for secret management

##### Additional details
- Notes on where to place .env files and how secrets flow into the backend.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Actors
    User["User"]:::external

    %% Frontend Layer
    subgraph "Frontend – Static Assets"
        direction TB
        Index["index.html"]:::frontend
        Canceled["canceled.html"]:::frontend
        SuccessPage["success.html"]:::frontend
        CSSGlobal["global.css"]:::frontend
        CSSNormalize["normalize.css"]:::frontend
        SuccessJS["success.js"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend – FastAPI Service"
        direction TB
        ServerPY["server.py"]:::backend
        Requirements["requirements.txt"]:::backend
        EnvServer[".env.example"]:::config
    end

    %% Configuration
    ConfigRoot[".env.example"]:::config

    %% Documentation
    ReadmeRoot["README.md"]:::config
    ReadmeServer["server/README.md"]:::config

    %% External Service
    Stripe["Stripe Checkout Service"]:::external

    %% Relationships
    User -->|"opens index.html"| Index
    Index -->|"POST /create-checkout-session"| ServerPY
    ServerPY -->|"uses Stripe SDK to create session"| Stripe
    Stripe -->|"redirects to hosted checkout"| User
    Stripe -->|"redirects to success/canceled page"| SuccessPage
    SuccessPage -->|"loads success.js"| SuccessJS

    ServerPY -->|".env variables"| EnvServer
    User -->|"views documentation"| ReadmeRoot
    ServerPY -->|"views service docs"| ReadmeServer
    ConfigRoot -.-> ServerPY

    %% Click Events
    click Index "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/index.html"
    click Canceled "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/canceled.html"
    click SuccessPage "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/success.html"
    click CSSGlobal "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/css/global.css"
    click CSSNormalize "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/css/normalize.css"
    click SuccessJS "https://github.com/rsusik/stripe-fastapi-demo/blob/master/client/success.js"
    click ServerPY "https://github.com/rsusik/stripe-fastapi-demo/blob/master/server/server.py"
    click Requirements "https://github.com/rsusik/stripe-fastapi-demo/blob/master/server/requirements.txt"
    click EnvServer "https://github.com/rsusik/stripe-fastapi-demo/blob/master/server/.env.example"
    click ConfigRoot "https://github.com/rsusik/stripe-fastapi-demo/blob/master/.env.example"
    click ReadmeRoot "https://github.com/rsusik/stripe-fastapi-demo/blob/master/README.md"
    click ReadmeServer "https://github.com/rsusik/stripe-fastapi-demo/blob/master/server/README.md"

    %% Styles
    classDef frontend fill:#D2E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#DFFFE0,stroke:#28a745,color:#28a745;
    classDef external fill:#FFE4B5,stroke:#FF8C00,color:#FF8C00;
    classDef config fill:#F0F0F0,stroke:#999999,color:#333333;
```
