Commercio Docs

Quick Start

Get up and running with Commercio in minutes.

Basic Setup

Initialize services and start using Commercio

import {
  initDatabase,
  createServices,
} from "commercio";

// Initialize database connection
initDatabase({
  connectionString: process.env.DATABASE_URL,
  runMigrations: true,
});

// Create all services at once - no need to manually inject repositories!
const {
  categoryService,
  productService,
  customerService,
  warehouseService,
  stockService,
  orderService,
  reservationService,
  inventoryTransactionService,
} = createServices();

Quick Start Flow

Visual overview of the setup process

Setup Process

100%
Loading diagram...
1

Create a Category

// Create a category
const category = await categoryService.createCategory(
  "Electronics",
  "Electronic devices and accessories"
);

console.log(`Category created: ${category.id}`);
2

Create a Product

// Create a product (categoryId is required)
const product = await productService.createProduct(
  "Laptop Dell XPS 15",
  "SKU-LAPTOP-001",
  category.id
);

console.log(`Product created: ${product.id}`);
3

Create a Warehouse

// Create a warehouse
const warehouse = await warehouseService.createWarehouse(
  "Main Warehouse Berlin"
);

console.log(`Warehouse created: ${warehouse.id}`);
4

Create a Customer

// Create a customer (required for orders)
const customer = await customerService.createCustomer(
  "John Doe",
  {
    street: "123 Main St",
    city: "Berlin",
    postalCode: "10115",
    country: "Germany",
  },
  { email: "john.doe@example.com" }
);

console.log(`Customer created: ${customer.id}`);
5

Set Stock

// Set initial stock
await stockService.setStock(product.id, warehouse.id, 100);

// Get stock
const stock = await stockService.getStock(product.id, warehouse.id);
console.log(`Current stock: ${stock?.quantity}`);
6

Create an Order

// Create order (customerId is required)
const order = await orderService.createOrder(customer.id, [
  {
    productId: product.id,
    quantity: 5,
    unitPrice: 1999, // €19.99 in cents
  },
]);

console.log(`Order created: ${order.id}`);
console.log(`Total amount: €${(order.totalAmount / 100).toFixed(2)}`);

// Confirm order (creates reservations)
const confirmedOrder = await orderService.confirmOrder(order.id, warehouse.id);

// Mark as paid
const paidOrder = await orderService.markOrderAsPaid(order.id);

// Ship order
const shippedOrder = await orderService.shipOrder(order.id, warehouse.id);

// Complete order
const completedOrder = await orderService.completeOrder(order.id);