High-Level Architecture

Single-vendor computer & gaming e-commerce, Bangladesh. One Laravel application, two faces: the storefront and the admin panel. Flows are in flowchart.html.

System context

Who and what talks to the system. Customers never see branches.

flowchart LR
  CUS["Customers<br/>guest and registered<br/>phone-first browser / installed web app"]
  STF["Staff<br/>Super Admin, managers, support,<br/>branch staff"]
  BOT["Search engines and<br/>social previews"]
  SYS["E-commerce system<br/>storefront + admin panel<br/>+ back end"]
  PAY["SSLCommerz<br/>cards, net banking, EMI"]
  WAL["bKash and Nagad"]
  COU["Couriers<br/>Pathao, Steadfast, RedX, more"]
  SMS["SMS gateway<br/>OTP and order SMS"]
  MAIL["Email service"]
  GOO["Google sign-in"]
  ADS["Analytics and ads<br/>GA, Search Console,<br/>Meta and TikTok pixels"]
  CUS -->|browse, buy, track| SYS
  STF -->|manage catalogue, stock, orders| SYS
  BOT -->|crawl SSR pages, sitemap, feeds| SYS
  SYS <-->|payments, refunds, IPN| PAY
  SYS <-->|payments, refunds, callbacks| WAL
  SYS <-->|book parcels, tracking webhooks| COU
  SYS -->|send| SMS
  SYS -->|send| MAIL
  SYS <-->|OAuth| GOO
  SYS -->|events, product feed| ADS
  

Containers and deployment

One codebase, one deployment. The storefront is server-rendered for SEO; the admin panel renders in the browser.

flowchart TB
  U["Browsers and bots"] --> CDN["CDN<br/>images, JS, CSS, cached pages"]
  CDN --> NG["Nginx<br/>HTTPS, compression, rate limits"]
  subgraph APP["Application server - VPS or cloud"]
    NG --> FPM["Laravel 12 on PHP-FPM<br/>storefront, admin, webhooks"]
    FPM <-->|render page| SSR["Inertia SSR<br/>Node process, storefront only"]
    HZ["Queue workers<br/>Laravel Horizon"]
    SCH["Scheduler<br/>every minute"]
  end
  subgraph DATA["Data services"]
    PG[("PostgreSQL<br/>all business data")]
    RD[("Redis<br/>cache, sessions, queues, locks")]
    MS[("Meilisearch<br/>product search and facets")]
    OS[("Object storage<br/>images, invoices, exports")]
  end
  FPM --> PG
  FPM --> RD
  FPM --> MS
  FPM --> OS
  HZ --> PG
  HZ --> RD
  HZ --> MS
  HZ --> OS
  SCH --> RD
  OS --> CDN
  HZ -->|API calls| EXT["Payment, courier, SMS,<br/>email providers"]
  EXT -->|callbacks and webhooks| NG
  BK["Daily backups<br/>off-server, restore tested"] --- PG
  

Application layers

Thin controllers; every business operation is an Action running in one database transaction.

flowchart TB
  subgraph UI["Presentation - Vue 3 + Inertia"]
    SP["Storefront pages<br/>ShopLayout, SSR, Tailwind, dark mode, bn/en"]
    AP["Admin pages<br/>AdminLayout, shared DataTable"]
  end
  subgraph HTTP["HTTP"]
    RT["Routes: storefront, admin, webhooks"]
    MW["Middleware: auth, 2-step sign-in, permission,<br/>branch scope, rate limit, idempotency, locale"]
    CT["Controllers - thin"]
    FR["Form requests - all validation"]
    PL["Policies - permission + branch checks"]
  end
  subgraph DOMAIN["Business logic"]
    AC["Actions<br/>PlaceOrder, AssignBranch, ReserveStock,<br/>RecordPayment, AllocatePreOrders,<br/>GenerateSku, ProcessRefund"]
    SV["Services<br/>Pricing, Inventory, Checkout, PreOrder,<br/>Warranty, Compatibility, Search"]
    CN["Connectors<br/>Payment, Courier, SMS, Email"]
  end
  subgraph INFRA["Data and async"]
    MD["Eloquent models<br/>decimal money, soft deletes"]
    JB["Jobs and notifications - queued"]
    EV["Events, e.g. product changed, order shipped"]
  end
  SP --> RT
  AP --> RT
  RT --> MW --> CT
  CT --> FR
  CT --> PL
  CT --> AC
  AC --> SV
  AC --> CN
  AC --> MD
  SV --> MD
  AC --> EV --> JB
  JB --> CN
  

Domain modules

Arrows show which module depends on which.

flowchart LR
  ACC["Access<br/>users, roles, permissions,<br/>branches scope, audit"]
  CAT["Catalogue<br/>categories, spec templates, brands,<br/>attributes, products, variants, SKU"]
  INV["Inventory<br/>branches, stock ledger, reservations,<br/>serials, purchases, transfers"]
  PRC["Pricing and promotions<br/>price resolver, coupons, flash deals,<br/>offers, collections, loyalty"]
  CUS["Customers<br/>accounts, OTP, addresses,<br/>COD risk, wishlist, alerts"]
  CHK["Cart and checkout<br/>cart, PlaceOrder, branch choice"]
  PAY["Payments<br/>gateways, COD, EMI,<br/>refunds, reconciliation"]
  ORD["Orders<br/>lifecycle, edits, invoices,<br/>pre-orders"]
  DLV["Delivery<br/>zones, rates, couriers,<br/>shipments, COD settlement"]
  AFT["After-sale<br/>returns, warranty claims,<br/>reviews, questions"]
  PCB["PC Builder<br/>slots, compatibility rules,<br/>saved builds"]
  CMS["Content and SEO<br/>pages, banners, blog,<br/>sitemap, feeds"]
  NOT["Notifications<br/>templates, SMS, email, push"]
  REP["Reports and dashboard"]
  CAT --> INV
  CAT --> PRC
  CAT --> PCB
  INV --> CHK
  PRC --> CHK
  CUS --> CHK
  CHK --> ORD
  CHK --> PAY
  ORD --> DLV
  ORD --> AFT
  PAY --> AFT
  ORD --> NOT
  AFT --> NOT
  DLV --> NOT
  ORD --> REP
  INV --> REP
  PAY --> REP
  ACC --> CAT
  ACC --> INV
  ACC --> ORD
  CAT --> CMS
  

Storefront request

How a product page reaches a phone or Google fast, as complete HTML.

sequenceDiagram
  autonumber
  participant B as Browser or Googlebot
  participant C as CDN
  participant L as Laravel
  participant R as Redis cache
  participant D as PostgreSQL
  participant N as SSR Node
  B->>C: GET /product/lenovo-legion-5
  alt Page cached at the CDN
    C-->>B: HTML
  else Not cached
    C->>L: Forward request
    L->>R: Product data cached?
    alt Cache hit
      R-->>L: Product, variants, total stock
    else Cache miss
      L->>D: Load product, variants, specs, total stock
      L->>R: Store until the product changes
    end
    L->>N: Render page with this data
    N-->>L: HTML with meta tags and structured data
    L-->>C: HTML
    C-->>B: HTML
  end
  Note over B: Vue takes over in the browser, later pages load as JSON
  

Order and payment

Order, branch choice, stock reservation and payment record are created together, or not at all.

sequenceDiagram
  autonumber
  participant B as Customer
  participant L as Laravel
  participant D as PostgreSQL
  participant G as Gateway
  participant Q as Queue
  B->>L: Place order
  L->>D: BEGIN transaction
  L->>L: Recalculate totals with the price resolver
  L->>D: Choose branch, lock stock rows, check availability
  L->>D: Create order, lines, reservation, payment record
  L->>D: COMMIT
  L-->>B: Redirect to gateway
  B->>G: Pay
  G->>L: Callback
  L->>G: Validate server to server
  L->>D: Payment paid, order confirmed - once per transaction id
  L->>Q: Order confirmed event
  Q->>Q: SMS, email, search stock update, staff alert
  

Courier updates

sequenceDiagram
  autonumber
  participant S as Staff
  participant L as Laravel
  participant K as Courier API
  participant D as PostgreSQL
  participant Q as Queue
  S->>L: Book parcel for a packed order
  L->>K: Create shipment with the branch's pickup account
  K-->>L: Tracking number and label
  L->>D: Shipment saved, order shipped, stock leaves on-hand
  K->>L: Webhook - delivered or failed
  L->>L: Verify signature, ignore repeats
  L->>D: Update shipment and order status
  L->>Q: Notify customer, add points or count COD refusal
  Note over L,K: Scheduled polling covers missed webhooks
  

Background work

WhenJob
Every minuteRelease expired 15-minute payment holds and cancel those orders
Every few minutesPoll courier tracking for open shipments; start and end flash deals
On changeUpdate the search index; clear page caches; resize uploaded images; send notifications; storefront change events
HourlyPre-order balance reminders and deadlines; stock and price-drop alerts; abandoned-cart reminders
DailyGateway settlement reconciliation; sitemap and product feeds; loyalty point expiry; database backup; stock ledger check
On requestExcel and PDF exports; bulk product imports with a validation report

Data

Main table groups and how they connect. Full list in spec.md section 20.

erDiagram
  CATEGORY ||--o{ PRODUCT : contains
  BRAND ||--o{ PRODUCT : makes
  PRODUCT ||--|{ VARIANT : has
  VARIANT ||--o{ PRODUCT_STOCK : "stocked at"
  BRANCH ||--o{ PRODUCT_STOCK : holds
  VARIANT ||--o{ STOCK_MOVEMENT : "moved by"
  BRANCH ||--o{ STOCK_MOVEMENT : records
  VARIANT ||--o{ SERIAL : "tracked as"
  CUSTOMER ||--o{ ORDER : places
  ORDER ||--|{ ORDER_ITEM : contains
  VARIANT ||--o{ ORDER_ITEM : "sold as"
  BRANCH ||--o{ ORDER : fulfils
  ORDER ||--o{ PAYMENT : "paid by"
  ORDER ||--o{ SHIPMENT : "shipped in"
  ORDER ||--o{ RETURN : "returned in"
  SERIAL ||--o{ WARRANTY_CLAIM : "claimed in"
  USER }o--o{ ROLE : has
  USER }o--o{ BRANCH : "assigned to"
  ROLE }o--o{ PERMISSION : grants
  

Stack

LayerChoiceWhy
Back endLaravel 12, PHP 8.3Same stack as the reference ERP; mature queues, auth and validation
Front endInertia v2 + Vue 3, Tailwind CSSOne codebase for storefront and admin; modern UI and dark mode
SEOInertia SSR (Node) for storefront routesComplete HTML for Google; structured data, sitemap, clean URLs
DatabasePostgreSQLReliable transactions and row locks for stock and money
Cache, sessions, queuesRedis + HorizonSpeed under flash-sale load; visible queue monitoring
SearchMeilisearch via Laravel ScoutInstant, typo-tolerant search with spec filters
FilesObject storage + CDN, WebP/AVIFFast images on phones
PDF / ExcelDomPDF, Laravel Excel (queued)Invoices, quotations, reports
HostingVPS or cloud serverMust run PHP and a Node process for SSR

Security and non-negotiable rules

AreaRule
MoneyExact decimals in BDT, never floating point; prices VAT-inclusive
StockAppend-only ledger; row locks on every change; available = on hand minus reserved
TransactionsOrder, reservation and payment record written together
PaymentsPaid only after server-to-server validation; callbacks and webhooks are idempotent; no card data stored
TotalsAlways recalculated on the server; browser prices are ignored
AccessEvery admin route behind a policy; branch scope on branch-owned data; 2-step sign-in for powerful roles
PrivacyStorefront never exposes branch data, cost prices or staff details
AbuseRate limits on sign-in, OTP and checkout; HTTPS everywhere; protection against common web attacks
AuditPrice, stock, refund, role, settings and SKU-setting changes logged with old and new values
RecoveryDaily off-server backups with tested restores