Ordering

A clean-architecture based ordering domain package for Dart. This package contains pure business logic for handling orders, independent of UI, frameworks, or infrastructure.

It is designed to be:

Framework-agnostic

Highly testable

Easy to integrate into any backend or Flutter app

Stable and reusable across projects

โœจ Features

Pure domain models (Order, OrderItem, Money, TimeSlot, etc.)

Clear order lifecycle (created โ†’ confirmed โ†’ completed / cancelled)

Port-based design for external dependencies (Inventory, Pricing, Loyalty)

Strong validation and rule enforcement

60+ unit tests covering domain & service behavior

No runtime dependencies

๐Ÿง  Architecture Philosophy

This package follows Clean Architecture / Hexagonal Architecture principles.

Separation of concerns:

Domain โ†’ Business rules & entities

Ports โ†’ External contracts (interfaces)

Services โ†’ Use-case orchestration

No framework, database, or API logic is included here by design.

๐Ÿ“ Project Structure lib/ โ”œโ”€โ”€ domain/ โ”‚ โ”œโ”€โ”€ order.dart โ”‚ โ”œโ”€โ”€ order_item.dart โ”‚ โ”œโ”€โ”€ order_status.dart โ”‚ โ”œโ”€โ”€ money.dart โ”‚ โ”œโ”€โ”€ subscription.dart โ”‚ โ””โ”€โ”€ time_slot.dart โ”‚ โ”œโ”€โ”€ ports/ โ”‚ โ”œโ”€โ”€ inventory_port.dart โ”‚ โ”œโ”€โ”€ pricing_port.dart โ”‚ โ””โ”€โ”€ loyalty_port.dart โ”‚ โ”œโ”€โ”€ services/ โ”‚ โ”œโ”€โ”€ order_service.dart โ”‚ โ”œโ”€โ”€ order_repo.dart โ”‚ โ””โ”€โ”€ order_req.dart โ”‚ โ””โ”€โ”€ ordering.dart // Public entry point

Consumers should import only:

import 'package:ordering/ordering.dart';

๐Ÿš€ Installation

Add the dependency:

dependencies: ordering: ^1.0.0

Then run:

dart pub get

๐Ÿงฉ Usage Example Implement required ports class InventoryAdapter implements InventoryPort { @override bool isAvailable(Order order) { return true; } }

class PricingAdapter implements PricingPort { @override Money calculatePrice(Order order) { return Money(500); } }

class LoyaltyAdapter implements LoyaltyPort { @override void reward(Order order) {} }

Create OrderService final orderService = OrderService( inventoryPort: InventoryAdapter(), pricingPort: PricingAdapter(), loyaltyPort: LoyaltyAdapter(), orderRepository: MyOrderRepository(), );

Use the service orderService.confirm(order); orderService.markDelivered(order);

Business rules are enforced automatically.

๐Ÿงช Testing

This package is heavily tested.

Run all tests:

dart test

Tests cover:

Domain invariants

Order lifecycle rules

Failure scenarios

Port interactions

๐Ÿ”’ Stability & Versioning

This package follows Semantic Versioning.

PATCH โ†’ Bug fixes

MINOR โ†’ Backward-compatible features

MAJOR โ†’ Breaking changes

Public APIs are intentionally minimal to keep them stable.

โŒ What This Package Does NOT Do

No database access

No HTTP / API logic

No Flutter UI

No framework coupling

These belong in adapter layers, not in the domain.

๐Ÿ“œ License

MIT License ยฉ 2026 Shivam Gupta

๐Ÿงญ Intended Audience

This package is ideal for:

Backend systems

Flutter apps with serious business logic

Developers practicing Clean Architecture

Teams that want long-term maintainability