→ Cerrada

Entry 001 - Definicion de bounded contexts

dddarchitectureinventorysales

Contextos identificados

Se identificaron dos bounded contexts iniciales para el sistema POS:

Inventory — Gestiona el catalogo de productos, precios y control de stock. El agregado principal es Product, que protege invariantes de negocio como la no-negatividad del stock y la coherencia entre stock disponible y reservado.

Sales — Gestiona el ciclo de vida de las ordenes de venta. El agregado Sale compone SaleItem como entidades internas y mantiene la consistencia del total calculado.

Comunicacion entre contextos

El contexto Sales depende de Inventory a traves de ports (interfaces) definidos en su capa de aplicacion: GetProductInfo y ReserveStock. La implementacion concreta vive en la capa de infraestructura de Sales, siguiendo el patron de puertos y adaptadores.

Decisiones de arquitectura

Decisiones de diseño

Naturaleza evolutiva

Estos contextos son una primera aproximacion. Conforme el proyecto evolucione e itere con analisis mas profundo, los limites pueden cambiar, nuevos contextos pueden emerger, y las reglas de negocio se refinaran.

Test Results

Inventory

Registro de productos, consulta por ID y reserva de stock

5 passed
✓
Registers a product and retrieves it by id
✓
Stores product with correct price
✓
Reserves stock successfully for valid quantity
✓
Fails when reserving more than available stock
✓
returns error for nonexistent product

Sales

Creacion de ventas, agregar/remover items, cancelar y confirmar ventas

6 passed
✓
Creates an empty order
✓
Adds item to order
✓
Accumulates quantity and calculates correct total
✓
Removes quantity from order and calculates correct total
✓
Cancels order and releases stock
✓
Registers order and confirms stock

Shared

Value Objects compartidos: PriceVO, validaciones de dominio

4 passed
✓
Price Value Object: Setting price as int (10) should be 10.00
✓
Price Value Object: Setting price as float (10.0) with one decimal should be 10.00
✓
Price Value Object: Setting price as float (10.01) with two decimals should be 10.01
✓
Price Value Object: Setting price with negative value (-10) in construction should throw error

DDD Artifacts

Inventory

Product

Aggregate Root Inventory

Properties

id UuidVO
name NameVO
price PriceVO
stock number
reservedStock number

Methods

reserveStock()releaseStock()getStock()canReserveStock()

Invariants

◆ Stock no puede ser negativo ◆ Cantidad reservada no puede exceder stock disponible ✓ Name debe tener minimo 3 caracteres

NameVO

Value Object
Non-empty Min 3 characters

Sales

Sale

Aggregate Root Sales

Properties

id string
items SaleItem[]
total PriceVO
state OrdersStates
createdAt Date

Methods

create()addItem()removeItem()findItemById()calculateTotal()

Invariants

⟳ Total se recalcula al agregar/remover items ◆ Estado inicial siempre es PENDING

Shared Domain

PriceVO

Value Object Shared
Non-negative Max 2 decimal places Stored as cents

UuidVO

Value Object Shared
Non-empty UUID format

Ports & Adapters

Port
GetProductInfo
Obtiene nombre y precio de un producto del contexto Inventory
Adapter
GetProductInfo (infrastructure)
Port
ReserveStock
Reserva stock de un producto en el contexto Inventory
Adapter
ReserveStock (infrastructure)