# mollie/demo-checkout-backend architecture

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

- Interactive diagram: https://gitdiagram.com/mollie/demo-checkout-backend
- Repository: https://github.com/mollie/demo-checkout-backend

## Overview

1. **Overall shape**
   - This is a Laravel 8/9-style PHP backend for the Mollie Checkout demo apps.
   - Its primary job is to expose API endpoints for creating and tracking payments, and to receive Mollie webhook callbacks for payment status updates.

2. **Request entry points**
   - Public traffic enters through Laravel’s HTTP kernel and routing layer.
   - `routes/api.php` is the main contract for mobile/API clients.
   - `routes/web.php` likely exists for a minimal browser-facing surface such as docs or fallback pages, but the core product is the API.

3. **API layer**
   - `app/Http/Controllers/Api/MethodsController.php` and `PaymentsController.php` are the main application endpoints.
   - `app/Http/Controllers/Api/Controller.php` is a shared base class for API controllers.
   - `app/Http/Controllers/PaymentsController.php` at the non-API level suggests there is also a web-facing payment entrypoint or callback handler outside the versioned API namespace.

4. **Payment domain**
   - `app/Models/Payment.php` is the central persisted entity.
   - `app/Models/Enums/PaymentStatus.php` defines the payment lifecycle state machine at the domain level.
   - `database/migrations/2021_07_20_104127_create_payments_table.php` defines the single core table that stores payment records.

5. **Validation and input boundaries**
   - `app/Http/Requests/PaymentRequest.php` isolates request validation for payment creation or update flows.
   - This is the main boundary preventing malformed client input from reaching the payment workflow.

6. **Response shaping**
   - The `app/Http/Resources` classes (`PaymentResource`, `MethodResource`, `IssuerResource`, `AmountResource`, `PriceResource`, `ImageResource`) indicate the API returns curated JSON representations rather than raw models.
   - This is important for architecture because the external contract is deliberately decoupled from the database schema.

7. **External Mollie integration**
   - The backend depends on Mollie as an external payments provider, configured through `config/services.php` and the `MOLLIE_KEY` environment variable described in the README.
   - The system creates payments via Mollie’s API and later updates local payment state based on webhook notifications from Mollie.
   - The webhook is a key asynchronous boundary: payment creation is synchronous, payment finalization is event-driven.

8. **Middleware and cross-cutting concerns**
   - `app/Http/Middleware/Device.php` appears to be a custom middleware, likely used to distinguish mobile clients or attach device context.
   - Standard Laravel middleware handles CSRF, cookies, proxies, signature validation, maintenance mode, and input trimming.
   - `config/cors.php` suggests the API is intended to be consumed cross-origin, which matters for client integration.

9. **Persistence and runtime environment**
   - The system uses MySQL as its primary datastore, as stated in the README and reflected by the database config and migration-driven schema.
   - `config/database.php`, `config/cache.php`, `config/session.php`, and `config/queue.php` show standard Laravel infrastructure, but the repo does not suggest a heavy queue-based architecture.
   - Persistent runtime artifacts live under `storage/`, including logs and generated API docs.

10. **Documentation and API discovery**
   - `config/l5-swagger.php` and `storage/api-docs/` indicate Swagger/OpenAPI generation is built into the backend.
   - The README points to `/api/doc`, so the API is designed to be self-describing for the mobile demo clients.

11. **Deployment and containerization**
   - `docker-compose.yml`, `docker/php/Dockerfile`, and `docker/nginx/default.conf` define a containerized stack with PHP-FPM/Laravel, Nginx, and MySQL.
   - The same app can also run locally with PHP and MySQL directly, so deployment is flexible but still centered on the Laravel app server.

12. **End-to-end data flow**
   - Client app calls the API to fetch available methods and submit a payment request.
   - Laravel validates the request, creates or persists a local `Payment` record, and interacts with Mollie.
   - Mollie handles the actual payment checkout and later calls the webhook.
   - The backend receives that callback, updates the payment status, and exposes the final state back to the client through JSON resources.

13. **Key architectural boundaries to draw**
   - **Client boundary:** mobile apps or other API consumers.
   - **Application boundary:** Laravel controllers, requests, and resources.
   - **Domain boundary:** payment model and status enum.
   - **External service boundary:** Mollie API and webhook callbacks.
   - **Infrastructure boundary:** MySQL, Docker/Nginx/PHP, and Swagger-generated docs.

Main entry points: [`app/Http/Controllers/Api/PaymentsController.php`](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/PaymentsController.php) (API payments), [`app/Models/Payment.php`](https://github.com/mollie/demo-checkout-backend/blob/main/app/Models/Payment.php) (Payment), [`app/Http/Controllers/Api/MethodsController.php`](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/MethodsController.php) (Methods), [`routes/api.php`](https://github.com/mollie/demo-checkout-backend/blob/main/routes/api.php) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry & HTTP"]
  node_routes_api["API routes<br/>[api.php]"]
  node_routes_web["Web routes<br/>[web.php]"]
  node_http_kernel["HTTP kernel<br/>middleware stack<br/>[Kernel.php]"]
  node_device_middleware["Device<br/>custom middleware<br/>[Device.php]"]
  node_api_base_controller["API base<br/>controller base<br/>[Controller.php]"]
  node_methods_controller["Methods<br/>API controller"]
  node_api_payments_controller["API payments<br/>API controller"]
  node_web_payments_controller["Web payments<br/>web controller"]
end

subgraph group_domain["Payment Domain"]
  node_payment_model[("Payment<br/>Eloquent model<br/>[Payment.php]")]
  node_payment_status{{"Status enum<br/>domain enum<br/>[PaymentStatus.php]"}}
  node_payments_migration["Payments table<br/>migration"]
end

subgraph group_presentation["API Presentation"]
  node_payment_request["Payment request<br/>form request<br/>[PaymentRequest.php]"]
  node_payment_resource["Payment JSON<br/>resource"]
  node_method_resource["Method JSON<br/>resource<br/>[MethodResource.php]"]
  node_aux_resources["Aux resources<br/>resource set<br/>[AmountResource.php]"]
end

subgraph group_integration["Mollie & Docs"]
  node_services_config["Services config<br/>[services.php]"]
  node_cors_config["CORS config<br/>[cors.php]"]
  node_swagger_config["Swagger config<br/>[l5-swagger.php]"]
  node_api_docs["API docs<br/>generated docs"]
end

subgraph group_infra["Infrastructure"]
  node_database_config["Database config<br/>[database.php]"]
  node_docker_stack["Docker stack<br/>container stack<br/>[docker-compose.yml]"]
  node_php_dockerfile["PHP image<br/>container build"]
  node_nginx_conf["Nginx config<br/>reverse proxy<br/>[default.conf]"]
end

node_routes_api -->|"routes to"| node_methods_controller
node_routes_api -->|"routes to"| node_api_payments_controller
node_routes_web -->|"routes to"| node_web_payments_controller
node_http_kernel -->|"includes"| node_device_middleware
node_api_payments_controller -->|"extends"| node_api_base_controller
node_methods_controller -->|"extends"| node_api_base_controller
node_api_payments_controller -->|"validates with"| node_payment_request
node_api_payments_controller -->|"returns"| node_payment_resource
node_methods_controller -->|"returns"| node_method_resource
node_api_payments_controller -->|"uses"| node_aux_resources
node_api_payments_controller -->|"persists"| node_payment_model
node_web_payments_controller -->|"persists"| node_payment_model
node_payment_model -->|"uses"| node_payment_status
node_payment_model -.->|"stored by"| node_payments_migration
node_api_payments_controller -->|"calls Mollie"| node_services_config
node_services_config -.->|"exposed through"| node_cors_config
node_swagger_config -->|"generates"| node_api_docs
node_routes_api -.->|"documented by"| node_swagger_config
node_payment_resource -->|"shapes"| node_payment_model
node_method_resource -->|"shapes"| node_methods_controller
node_database_config -.->|"backed by"| node_payments_migration
node_docker_stack -->|"builds"| node_php_dockerfile
node_docker_stack -->|"serves with"| node_nginx_conf
node_docker_stack -->|"connects to"| node_database_config

click node_routes_api "https://github.com/mollie/demo-checkout-backend/blob/main/routes/api.php"
click node_routes_web "https://github.com/mollie/demo-checkout-backend/blob/main/routes/web.php"
click node_http_kernel "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Kernel.php"
click node_device_middleware "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Middleware/Device.php"
click node_api_base_controller "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/Controller.php"
click node_methods_controller "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/MethodsController.php"
click node_api_payments_controller "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/PaymentsController.php"
click node_web_payments_controller "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/PaymentsController.php"
click node_payment_request "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Requests/PaymentRequest.php"
click node_payment_resource "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/PaymentResource.php"
click node_method_resource "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/MethodResource.php"
click node_aux_resources "https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/AmountResource.php"
click node_payment_model "https://github.com/mollie/demo-checkout-backend/blob/main/app/Models/Payment.php"
click node_payment_status "https://github.com/mollie/demo-checkout-backend/blob/main/app/Models/Enums/PaymentStatus.php"
click node_payments_migration "https://github.com/mollie/demo-checkout-backend/blob/main/database/migrations/2021_07_20_104127_create_payments_table.php"
click node_services_config "https://github.com/mollie/demo-checkout-backend/blob/main/config/services.php"
click node_cors_config "https://github.com/mollie/demo-checkout-backend/blob/main/config/cors.php"
click node_swagger_config "https://github.com/mollie/demo-checkout-backend/blob/main/config/l5-swagger.php"
click node_api_docs "https://github.com/mollie/demo-checkout-backend/tree/main/storage/api-docs"
click node_database_config "https://github.com/mollie/demo-checkout-backend/blob/main/config/database.php"
click node_docker_stack "https://github.com/mollie/demo-checkout-backend/blob/main/docker-compose.yml"
click node_php_dockerfile "https://github.com/mollie/demo-checkout-backend/tree/main/docker/php/Dockerfile"
click node_nginx_conf "https://github.com/mollie/demo-checkout-backend/blob/main/docker/nginx/default.conf"

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_routes_api,node_routes_web,node_http_kernel,node_device_middleware,node_api_base_controller,node_methods_controller,node_api_payments_controller,node_web_payments_controller toneBlue
class node_payment_model,node_payment_status,node_payments_migration toneAmber
class node_payment_request,node_payment_resource,node_method_resource,node_aux_resources toneMint
class node_services_config,node_cors_config,node_swagger_config,node_api_docs toneRose
class node_database_config,node_docker_stack,node_php_dockerfile,node_nginx_conf toneIndigo
```

## Components

### Entry & HTTP

Request routing, middleware, and controller entrypoints

- [API routes](https://github.com/mollie/demo-checkout-backend/blob/main/routes/api.php): routes · Main public API contract for clients · `routes/api.php`
- [Web routes](https://github.com/mollie/demo-checkout-backend/blob/main/routes/web.php): routes · Secondary browser-facing surface · `routes/web.php`
- [HTTP kernel](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Kernel.php): middleware stack · Registers global and route middleware · `app/Http/Kernel.php`
- [Device](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Middleware/Device.php): custom middleware · Adds device/client context to requests · `app/Http/Middleware/Device.php`
- [API base](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/Controller.php): controller base · Shared base controller for API endpoints · `app/Http/Controllers/Api/Controller.php`
- [Methods](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/MethodsController.php): API controller · Lists available payment methods · `app/Http/Controllers/Api/MethodsController.php`
- [API payments](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/Api/PaymentsController.php): API controller · Creates and tracks payments via the API · `app/Http/Controllers/Api/PaymentsController.php`
- [Web payments](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Controllers/PaymentsController.php): web controller · Non-API payment entrypoint or callback handler · `app/Http/Controllers/PaymentsController.php`

### Payment Domain

Core payment entity, lifecycle, and persistence

- [Payment](https://github.com/mollie/demo-checkout-backend/blob/main/app/Models/Payment.php): Eloquent model · Persistent payment record and state holder · `app/Models/Payment.php`
- [Status enum](https://github.com/mollie/demo-checkout-backend/blob/main/app/Models/Enums/PaymentStatus.php): domain enum · Payment lifecycle states · `app/Models/Enums/PaymentStatus.php`
- [Payments table](https://github.com/mollie/demo-checkout-backend/blob/main/database/migrations/2021_07_20_104127_create_payments_table.php): migration · Database schema for stored payments · `database/migrations/2021_07_20_104127_create_payments_table.php`

### API Presentation

Validation and JSON response shaping

- [Payment request](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Requests/PaymentRequest.php): form request · Validates payment input before processing · `app/Http/Requests/PaymentRequest.php`
- [Payment JSON](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/PaymentResource.php): resource · API view of payment state · `app/Http/Resources/PaymentResource.php`
- [Method JSON](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/MethodResource.php): resource · API view of payment methods · `app/Http/Resources/MethodResource.php`
- [Aux resources](https://github.com/mollie/demo-checkout-backend/blob/main/app/Http/Resources/AmountResource.php): resource set · Supporting JSON wrappers for amounts, prices, issuers, and images · `app/Http/Resources/AmountResource.php`

### Mollie & Docs

External payment provider integration and API documentation

- [Services config](https://github.com/mollie/demo-checkout-backend/blob/main/config/services.php): config · Mollie client configuration and secrets wiring · `config/services.php`
- [CORS config](https://github.com/mollie/demo-checkout-backend/blob/main/config/cors.php): config · Cross-origin API access policy · `config/cors.php`
- [Swagger config](https://github.com/mollie/demo-checkout-backend/blob/main/config/l5-swagger.php): config · OpenAPI generation setup · `config/l5-swagger.php`
- [API docs](https://github.com/mollie/demo-checkout-backend/tree/main/storage/api-docs): generated docs · Generated Swagger/OpenAPI output · `storage/api-docs`

### Infrastructure

Database, container, and runtime support

- [Database config](https://github.com/mollie/demo-checkout-backend/blob/main/config/database.php): config · MySQL-backed persistence settings · `config/database.php`
- [Docker stack](https://github.com/mollie/demo-checkout-backend/blob/main/docker-compose.yml): container stack · PHP, Nginx, and MySQL runtime composition · `docker-compose.yml`
- [PHP image](https://github.com/mollie/demo-checkout-backend/tree/main/docker/php/Dockerfile): container build · PHP-FPM application image definition · `docker/php/Dockerfile`
- [Nginx config](https://github.com/mollie/demo-checkout-backend/blob/main/docker/nginx/default.conf): reverse proxy · Web server configuration for Laravel · `docker/nginx/default.conf`

## Connections

- API routes → Methods: routes to · API routes dispatch to method discovery
- API routes → API payments: routes to · API routes dispatch to payment workflows
- Web routes → Web payments: routes to · Web routes expose browser-facing payment handling
- HTTP kernel → Device: includes · Kernel registers custom request context middleware
- API payments → API base: extends · API payment controller shares base behavior
- Methods → API base: extends · Methods controller shares API base behavior
- API payments → Payment request: validates with · Payment creation is guarded by request validation
- API payments → Payment JSON: returns · Payment state is serialized as JSON resource
- Methods → Method JSON: returns · Method discovery is serialized as JSON resource
- API payments → Aux resources: uses · Payment responses include amount/price/image/issuer wrappers
- API payments → Payment: persists · Controller reads and updates payment records
- Web payments → Payment: persists · Web-side flow also touches payment records
- Payment → Status enum: uses · Stored payment state follows domain enum
- Payment → Payments table: stored by · Migration defines the payment table schema
- API payments → Services config: calls Mollie · Controller is wired to the external payments provider
- Services config → CORS config: exposed through · API is intended for cross-origin clients
- Swagger config → API docs: generates · Swagger configuration produces published docs
- API routes → Swagger config: documented by · API routes are discoverable in generated docs
- Payment JSON → Payment: shapes · Resource presents payment model state
- Method JSON → Methods: shapes · Resource supports method listing responses
- Database config → Payments table: backed by · Payments are stored in the configured database
- Docker stack → PHP image: builds · Container stack includes the PHP app image
- Docker stack → Nginx config: serves with · Nginx is part of the runtime stack
- Docker stack → Database config: connects to · Stack includes the MySQL-backed app database
