Skip to content

Latest commit

Β 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Velora Commerce Engine

Go Version License CI Status Go Report Card LinkedIn Profile

Velora is a self-hosted, headless commerce engine built in Go. It is designed as a modular monolith compiled into a single static binary that runs with zero required external services (no Redis, no message broker, no background sidecars).

Unlike enterprise commerce backends designed to scale to massive global traffic, Velora is optimized for operational economics and maintenance simplicity at scale of instances. It is built for agencies, platform teams, and independent developers who need to run and operate many isolated tenant stores on minimal infrastructure footprint (e.g., twenty client stores sharing a single modest VM).


πŸ—οΈ System Architecture

Velora implements a strict Hexagonal Architecture (Ports and Adapters) inside a Modular Monolith. Business logic is entirely decoupled from database engines, transport protocols, and third-party APIs.

graph TB
    Client[Storefront / Admin UI / API Client] -->|HTTPS| Proxy[Reverse Proxy e.g. Caddy/Nginx]
    Proxy --> API

    subgraph Binary["Single Static Go Binary"]
        API[API Layer<br/>routing Β· auth Β· validation] --> App[Application Layer<br/>use cases / orchestration]
        App --> Domain[Domain Layer<br/>Catalog Β· Customer Β· Cart<br/>Order Β· Inventory]
        
        Domain -->|emits| Events[Internal Event Bus]
        Events -->|sync dispatch| Jobs[Async Job Runner]
        Events -->|outbound| Webhooks[Webhook Dispatcher]
        
        Domain -->|Port Interfaces| Repo[Persistence Repositories]
    end

    Repo --> SQLite[("SQLite<br/>(local db file)")]
    Repo --> Postgres[("PostgreSQL<br/>(production db)")]
    Jobs --> DBJobs[("Job Queue Tables")]
    
    style Binary fill:#f9f9f9,stroke:#333,stroke-width:2px
    style Domain fill:#d4e6f1,stroke:#2980b9,stroke-width:1px
    style Repo fill:#d5f5e3,stroke:#27ae60,stroke-width:1px
Loading

Request and Event Lifecycle

sequenceDiagram
    participant Client as API Client
    participant API as API Layer (HTTP)
    participant App as Application Use Cases
    participant Domain as Domain Entities
    participant DB as DB (Postgres/SQLite)
    participant Bus as Event Bus (In-Process)
    participant Runner as Async Job Runner

    Client->>API: HTTP POST /v1/store/checkout
    API->>API: Authenticate & Validate Request
    API->>App: Invoke PlaceOrder() Use Case
    App->>Domain: Execute Checkout Business Logic
    Domain->>DB: Atomic Reserve Stock & Create Order (Transaction)
    DB-->>Domain: Success
    Domain->>Bus: Publish event "order.placed"
    Domain-->>App: Order Entity
    App-->>API: Response Payload
    API-->>Client: HTTP 201 Created (Fast Response)

    Note over Bus,Runner: Event handled asynchronously out of the request path
    Bus->>Runner: Enqueue async jobs (e.g. email, webhooks, payments)
    Runner->>DB: Persist job metadata for execution and retry
Loading

πŸ’‘ Key Architectural Decisions

  1. Zero External Runtime Dependencies: Velora replaces Redis and RabbitMQ with an in-process, memory-efficient synchronous/asynchronous Event Bus and a database-backed, transactional background Job Runner (platform/jobs) supporting exponential backoff.
  2. Strict Boundary Enforcements: The codebase contains a custom boundary checker script (scripts/check_imports.go) executed on every commit. The domain/ package has zero imports from api/ or platform/, preventing infrastructure concerns from leaking into core commerce rules.
  3. Persisted Stateless Carts: Unlike systems that store carts in session caches, Velora persists carts directly in SQLite/PostgreSQL. This ensures process crashes never lose user items and supports asynchronous abandoned-cart recovery.
  4. Dual DB Migration Engine: The platform supports both SQLite (for zero-install development/micro-stores) and PostgreSQL (for standard production environments). SQL schema migrations are embedded directly inside the binary and executed automatically at startup.

πŸ“‚ Repository Directory Structure

β”œβ”€β”€ api/             # HTTP transport layer (router, middleware, response serializers)
β”‚   └── handler/     # Controller handlers (separated by /admin and /customer concerns)
β”œβ”€β”€ application/     # Orchestration layer coordinating domain use cases and infrastructure ports
β”œβ”€β”€ cmd/
β”‚   β”œβ”€β”€ server/      # Main entry point for the HTTP commerce server
β”‚   └── cli/         # Command-line utility for administrative tasks and diagnostics
β”œβ”€β”€ docs/            # Architecture blueprints, vision document, and 10 detailed ADRs
β”œβ”€β”€ domain/          # Pure business logic, aggregates, and DB repository Port interfaces
β”‚   β”œβ”€β”€ catalog/     # Product entities, variants, catalog repository definitions
β”‚   β”œβ”€β”€ customer/    # User accounts, addresses, hashing logic (Argon2id)
β”‚   β”œβ”€β”€ cart/        # Cart aggregations and mutations
β”‚   β”œβ”€β”€ order/       # Checkout flow and Order state machines
β”‚   └── inventory/   # Stock levels and atomic reservations
β”œβ”€β”€ events/          # Standardized event formats and structures
β”œβ”€β”€ platform/        # Adapter implementations for database, cryptography, jobs, and mailers
β”‚   β”œβ”€β”€ sqlite/      # SQLite repository implementations and local schema migrations
β”‚   β”œβ”€β”€ postgres/    # PostgreSQL repository implementations and production schema migrations
β”‚   β”œβ”€β”€ jobs/        # Background queue execution engine
β”‚   └── auth/        # JWT issuing and token verification
└── tests/           # Full-stack integration and concurrency race test suites

πŸš€ Quick Start (Local Development)

1. Prerequisites

  • Go: 1.25.x or higher installed.

2. Setup Configuration

Copy the default environment configuration:

cp .env.example .env

3. Run the Server

Start the HTTP server. It will compile, run database schema migrations automatically, start the background job runner, and listen on the configured port:

make run

You should see output similar to:

Starting Velora Headless Commerce Engine...
Configuration loaded {"port": "8080", "db_driver": "sqlite"}
Database connection established
Migrations executed successfully
Background job runner started
Server listening {"port": "8080"}

πŸ§ͺ Testing Pyramid

Velora is built with a heavy emphasis on test reliability, validating entire business flows rather than mocking everything at the layer boundary.

       β•±  Integration (tests/integration)  β•²  β€” Full API flows using in-memory SQLite
      β•±  Repository (platform/sqlite)        β•² β€” SQL query verification on real db schema
     β•±  Application (application)             β•² β€” Use case orchestration with in-memory mocks
    β•±  Domain Unit (domain)                    β•² β€” Pure business rule invariants (no IO)

To run all tests including integration flow suites:

make test

Concurrency and Transaction Safety

Velora includes explicit tests designed to detect race conditions in inventory allocations (e.g. two users checking out the last available item simultaneously). You can run tests under the Go race detector:

go test -race -v ./...

πŸ”Œ API Quick Reference

Velora splits its endpoints into public-facing storefront endpoints (/v1/store) and credentialed admin endpoints (/v1/admin).

Documentation: The complete formal API specification is available in the OpenAPI 3.0 Document.

1. Storefront Authentication (Public)

Register a new customer account (passwords are hashed using resource-bounded Argon2id):

curl -X POST http://localhost:8080/v1/store/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "shopper@example.com",
    "password": "strongPassword123",
    "name": "Mohamed Kamal"
  }'

2. Admin Authentication (Machine-to-Machine)

Admin endpoints support authentication via JWT bearer tokens or secure machine-to-machine API keys using X-API-Key headers (tokens are verified using high-performance bcrypt).

To list products as an admin:

curl -H "X-API-Key: <your-api-key>" http://localhost:8080/v1/admin/products

πŸ‘¨β€πŸ’» Author and Portfolio Information

Velora was designed and built by Mohamed Kamal as a showcase of Go modular monolith architecture, domain-driven design principles, and strict software craftsmanship.

  • LinkedIn: Mohamed Kamal
  • Design Philosophy: Boring, predictable, highly testable code that runs on minimal infrastructure.

If you are an engineer or recruiter evaluating this project, check out:

About

velora

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages