# cybermaitre/market-square architecture

> Architecture diagram of the GitHub repository cybermaitre/market-square, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cybermaitre/market-square
- Repository: https://github.com/cybermaitre/market-square

## Overview

This is a Laravel multi-vendor marketplace API. Buyers register, browse public stores and products, manage a cart, and check out into orders; vendors manage a store and products, fulfil vendor orders, and view earnings. The map separates API routing, marketplace operations, and persisted domain state. Source excerpts substantiate checkout, cart, authentication, store management, and vendor-order behavior; other documented or indexed capabilities are included, but their internal steps are not inferred where source detail is unavailable.

Main entry points: [`routes/api.php`](https://github.com/cybermaitre/market-square/blob/main/routes/api.php) (API routes), [`app/Services/CheckoutService.php`](https://github.com/cybermaitre/market-square/blob/main/app/Services/CheckoutService.php) (Order checkout), [`app/Models/User.php`](https://github.com/cybermaitre/market-square/blob/main/app/Models/User.php) (Users), [`app/Models/Store.php`](https://github.com/cybermaitre/market-square/blob/main/app/Models/Store.php) (Stores)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and access"]
  node_api_routes["API routes<br/>[api.php]"]
  node_auth["Authentication<br/>[AuthController.php]"]
  node_role_gate["Role middleware"]
end

subgraph group_catalog["Stores and catalog"]
  node_public_stores["Public stores"]
  node_public_products["Product browsing"]
  node_store_management["Store management"]
  node_product_management["Product management"]
end

subgraph group_commerce["Buyer commerce"]
  node_cart_api["Cart API<br/>[CartController.php]"]
  node_cart_service["Cart operations<br/>[CartService.php]"]
  node_checkout_api["Checkout API"]
  node_checkout["Order checkout"]
  node_buyer_orders[("Buyer orders<br/>[Order.php]")]
end

subgraph group_vendor["Vendor operations"]
  node_vendor_orders_api["Vendor order API"]
  node_vendor_order_ops["Order fulfilment"]
  node_earnings_api["Earnings API"]
  node_earnings_ops["Earnings calculations"]
end

subgraph group_state["Marketplace state"]
  node_users[("Users<br/>[User.php]")]
  node_stores[("Stores<br/>[Store.php]")]
  node_products[("Products<br/>[Product.php]")]
  node_carts[("Carts and items<br/>[Cart.php]")]
  node_order_items[("Order items<br/>[OrderItem.php]")]
  node_vendor_order_state[("Vendor order state<br/>[VendorOrder.php]")]
  node_earnings_state[("Vendor earnings<br/>[Earnings.php]")]
  node_order_status["Order statuses<br/>[OrderStatus.php]"]
end

node_buyer(("Buyer"))
node_vendor_actor(("Vendor"))

node_buyer -->|"sends requests"| node_api_routes
node_vendor_actor -->|"sends requests"| node_api_routes
node_api_routes -->|"routes auth"| node_auth
node_api_routes -->|"routes public stores"| node_public_stores
node_api_routes -->|"routes product browsing"| node_public_products
node_api_routes -->|"routes vendor stores"| node_store_management
node_api_routes -->|"routes vendor products"| node_product_management
node_api_routes -->|"routes cart"| node_cart_api
node_api_routes -->|"routes orders"| node_checkout_api
node_api_routes -->|"routes fulfilment"| node_vendor_orders_api
node_api_routes -->|"routes earnings"| node_earnings_api
node_auth -->|"creates and checks"| node_users
node_auth -->|"creates buyer cart"| node_carts
node_api_routes -->|"applies role checks"| node_role_gate
node_public_stores -->|"reads"| node_stores
node_public_products -->|"reads"| node_products
node_store_management -->|"creates and updates"| node_stores
node_product_management -->|"manages"| node_products
node_cart_api -->|"calls"| node_cart_service
node_cart_service -->|"reads and writes"| node_carts
node_checkout_api -->|"calls"| node_checkout
node_checkout -->|"reads and clears"| node_carts
node_checkout -->|"checks stock and decrements"| node_products
node_checkout -->|"creates order"| node_buyer_orders
node_checkout -->|"creates items"| node_order_items
node_checkout -->|"creates fulfilment records"| node_vendor_order_state
node_vendor_orders_api -->|"updates status through"| node_vendor_order_ops
node_vendor_order_ops -->|"updates"| node_vendor_order_state
node_vendor_orders_api -->|"parses status"| node_order_status
node_vendor_order_ops -->|"updates earnings"| node_earnings_state
node_earnings_api -->|"calls"| node_earnings_ops
node_earnings_ops -->|"reads"| node_earnings_state
node_users -->|"owns"| node_stores
node_users -->|"owns"| node_carts
node_stores -->|"has products"| node_products
node_order_items -->|"has fulfilment record"| node_vendor_order_state
node_users -->|"has earnings"| node_earnings_state

click node_api_routes "https://github.com/cybermaitre/market-square/blob/main/routes/api.php"
click node_auth "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/AuthController.php"
click node_role_gate "https://github.com/cybermaitre/market-square/blob/main/app/Http/Middleware/EnsureUserHasRole.php"
click node_public_stores "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/PublicStoreController.php"
click node_public_products "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/PublicProductController.php"
click node_store_management "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/StoreController.php"
click node_product_management "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/ProductController.php"
click node_cart_api "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/CartController.php"
click node_cart_service "https://github.com/cybermaitre/market-square/blob/main/app/Services/CartService.php"
click node_checkout_api "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/OrderController.php"
click node_checkout "https://github.com/cybermaitre/market-square/blob/main/app/Services/CheckoutService.php"
click node_buyer_orders "https://github.com/cybermaitre/market-square/blob/main/app/Models/Order.php"
click node_vendor_orders_api "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/VendorOrderController.php"
click node_vendor_order_ops "https://github.com/cybermaitre/market-square/blob/main/app/Services/VendorOrderService.php"
click node_earnings_api "https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/EarningsController.php"
click node_earnings_ops "https://github.com/cybermaitre/market-square/blob/main/app/Services/EarningsService.php"
click node_users "https://github.com/cybermaitre/market-square/blob/main/app/Models/User.php"
click node_stores "https://github.com/cybermaitre/market-square/blob/main/app/Models/Store.php"
click node_products "https://github.com/cybermaitre/market-square/blob/main/app/Models/Product.php"
click node_carts "https://github.com/cybermaitre/market-square/blob/main/app/Models/Cart.php"
click node_order_items "https://github.com/cybermaitre/market-square/blob/main/app/Models/OrderItem.php"
click node_vendor_order_state "https://github.com/cybermaitre/market-square/blob/main/app/Models/VendorOrder.php"
click node_earnings_state "https://github.com/cybermaitre/market-square/blob/main/app/Models/Earnings.php"
click node_order_status "https://github.com/cybermaitre/market-square/blob/main/app/Enums/OrderStatus.php"

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_api_routes,node_auth,node_role_gate toneBlue
class node_public_stores,node_public_products,node_store_management,node_product_management toneAmber
class node_cart_api,node_cart_service,node_checkout_api,node_checkout,node_buyer_orders toneMint
class node_vendor_orders_api,node_vendor_order_ops,node_earnings_api,node_earnings_ops toneRose
class node_users,node_stores,node_products,node_carts,node_order_items,node_vendor_order_state,node_earnings_state,node_order_status,node_buyer,node_vendor_actor toneIndigo
```

## Components

### API and access

- [API routes](https://github.com/cybermaitre/market-square/blob/main/routes/api.php): `routes/api.php`
- [Authentication](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/AuthController.php): `app/Http/Controllers/Api/AuthController.php`
- [Role middleware](https://github.com/cybermaitre/market-square/blob/main/app/Http/Middleware/EnsureUserHasRole.php): `app/Http/Middleware/EnsureUserHasRole.php`

### Stores and catalog

- [Public stores](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/PublicStoreController.php): `app/Http/Controllers/Api/PublicStoreController.php`
- [Product browsing](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/PublicProductController.php): `app/Http/Controllers/Api/PublicProductController.php`
- [Store management](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/StoreController.php): `app/Http/Controllers/Api/StoreController.php`
- [Product management](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/ProductController.php): `app/Http/Controllers/Api/ProductController.php`

### Buyer commerce

- [Cart API](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/CartController.php): `app/Http/Controllers/Api/CartController.php`
- [Cart operations](https://github.com/cybermaitre/market-square/blob/main/app/Services/CartService.php): `app/Services/CartService.php`
- [Checkout API](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/OrderController.php): `app/Http/Controllers/Api/OrderController.php`
- [Order checkout](https://github.com/cybermaitre/market-square/blob/main/app/Services/CheckoutService.php): `app/Services/CheckoutService.php`
- [Buyer orders](https://github.com/cybermaitre/market-square/blob/main/app/Models/Order.php): `app/Models/Order.php`

### Vendor operations

- [Vendor order API](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/VendorOrderController.php): `app/Http/Controllers/Api/VendorOrderController.php`
- [Order fulfilment](https://github.com/cybermaitre/market-square/blob/main/app/Services/VendorOrderService.php): `app/Services/VendorOrderService.php`
- [Earnings API](https://github.com/cybermaitre/market-square/blob/main/app/Http/Controllers/Api/EarningsController.php): `app/Http/Controllers/Api/EarningsController.php`
- [Earnings calculations](https://github.com/cybermaitre/market-square/blob/main/app/Services/EarningsService.php): `app/Services/EarningsService.php`

### Marketplace state

- [Users](https://github.com/cybermaitre/market-square/blob/main/app/Models/User.php): `app/Models/User.php`
- [Stores](https://github.com/cybermaitre/market-square/blob/main/app/Models/Store.php): `app/Models/Store.php`
- [Products](https://github.com/cybermaitre/market-square/blob/main/app/Models/Product.php): `app/Models/Product.php`
- [Carts and items](https://github.com/cybermaitre/market-square/blob/main/app/Models/Cart.php): `app/Models/Cart.php`
- [Order items](https://github.com/cybermaitre/market-square/blob/main/app/Models/OrderItem.php): `app/Models/OrderItem.php`
- [Vendor order state](https://github.com/cybermaitre/market-square/blob/main/app/Models/VendorOrder.php): `app/Models/VendorOrder.php`
- [Vendor earnings](https://github.com/cybermaitre/market-square/blob/main/app/Models/Earnings.php): `app/Models/Earnings.php`
- [Order statuses](https://github.com/cybermaitre/market-square/blob/main/app/Enums/OrderStatus.php): `app/Enums/OrderStatus.php`

### Other components

- **Buyer**
- **Vendor**

## Connections

- Buyer → API routes: sends requests (evidence: `README.md`)
- Vendor → API routes: sends requests (evidence: `README.md`)
- API routes → Authentication: routes auth (evidence: `routes/api.php`)
- API routes → Public stores: routes public stores (evidence: `routes/api.php`)
- API routes → Product browsing: routes product browsing (evidence: `routes/api.php`)
- API routes → Store management: routes vendor stores (evidence: `routes/api.php`)
- API routes → Product management: routes vendor products (evidence: `routes/api.php`)
- API routes → Cart API: routes cart (evidence: `routes/api.php`)
- API routes → Checkout API: routes orders (evidence: `routes/api.php`)
- API routes → Vendor order API: routes fulfilment (evidence: `routes/api.php`)
- API routes → Earnings API: routes earnings (evidence: `routes/api.php`)
- Authentication → Users: creates and checks
- Authentication → Carts and items: creates buyer cart
- API routes → Role middleware: applies role checks
- Public stores → Stores: reads (evidence: `app/Http/Controllers/Api/PublicStoreController.php`)
- Product browsing → Products: reads (evidence: `app/Http/Controllers/Api/PublicProductController.php`)
- Store management → Stores: creates and updates (evidence: `app/Http/Controllers/Api/StoreController.php`)
- Product management → Products: manages (evidence: `app/Http/Controllers/Api/ProductController.php`)
- Cart API → Cart operations: calls (evidence: `app/Http/Controllers/Api/CartController.php`)
- Cart operations → Carts and items: reads and writes (evidence: `app/Services/CartService.php`)
- Checkout API → Order checkout: calls (evidence: `app/Http/Controllers/Api/OrderController.php`)
- Order checkout → Carts and items: reads and clears (evidence: `app/Services/CheckoutService.php`)
- Order checkout → Products: checks stock and decrements (evidence: `app/Services/CheckoutService.php`)
- Order checkout → Buyer orders: creates order (evidence: `app/Services/CheckoutService.php`)
- Order checkout → Order items: creates items (evidence: `app/Services/CheckoutService.php`)
- Order checkout → Vendor order state: creates fulfilment records (evidence: `app/Services/CheckoutService.php`)
- Vendor order API → Order fulfilment: updates status through (evidence: `app/Http/Controllers/Api/VendorOrderController.php`)
- Order fulfilment → Vendor order state: updates (evidence: `app/Services/VendorOrderService.php`)
- Vendor order API → Order statuses: parses status (evidence: `app/Http/Controllers/Api/VendorOrderController.php`)
- Order fulfilment → Vendor earnings: updates earnings (evidence: `app/Services/VendorOrderService.php`)
- Earnings API → Earnings calculations: calls (evidence: `app/Http/Controllers/Api/EarningsController.php`)
- Earnings calculations → Vendor earnings: reads (evidence: `app/Services/EarningsService.php`)
- Users → Stores: owns (evidence: `app/Models/User.php`)
- Users → Carts and items: owns (evidence: `app/Models/User.php`)
- Stores → Products: has products (evidence: `app/Models/Store.php`)
- Order items → Vendor order state: has fulfilment record (evidence: `app/Models/VendorOrder.php`)
- Users → Vendor earnings: has earnings (evidence: `app/Models/User.php`)
