Carrier integration and shipment tracking service with DDD, hexagonal architecture, CloudEvents, and transactional outbox pattern.
The Shipment & Transportation Service manages shipment creation, carrier integration, and tracking within the Paklog fulfillment platform. This bounded context handles carrier selection, load tendering, shipping label generation, and real-time tracking updates. It integrates with external carrier APIs (FedEx, UPS, etc.) and provides shipment visibility across the fulfillment lifecycle.
Shipment & Transportation Management - Manages shipments, carrier integrations, load tendering, and tracking throughout the delivery journey.
- Shipment - Root aggregate representing a shipment with tracking and carrier information
- Load - Aggregate representing a tender/booking with a carrier
- TrackingEvent - Individual tracking update in shipment journey
- Tender - Carrier tender/booking request
- Pickup - Pickup schedule information
- ShipmentId - Unique shipment identifier
- LoadId - Unique load identifier
- OrderId - Reference to fulfillment order
- TrackingNumber - Carrier tracking number
- CarrierName - Carrier identifier
- CarrierInfo - Carrier details and capabilities
- Package - Package dimensions and weight
- Location - Geographic location information
- ShippingCost - Cost and currency
- TrackingUpdate - Tracking status update details
- ShipmentStatus - Shipment lifecycle status
- LoadStatus - Load processing status
- TenderStatus - Tender response status
- PackagePackedEvent - Package packed and ready for shipment (consumed)
- LoadCreatedEvent - Load tender created
- ShipmentDispatchedEvent - Shipment dispatched with carrier
- ShipmentDeliveredEvent - Shipment delivered to customer
- CarrierSelectionService - Selects optimal carrier based on strategy
- DefaultCarrierSelectionStrategy - Default carrier selection logic
- Shipment: Package or set of packages being transported
- Load: Tender or booking with a carrier
- Carrier: Third-party logistics provider (FedEx, UPS, etc.)
- Tender: Request to carrier for shipment service
- Tracking Number: Carrier-provided shipment identifier
- Tracking Event: Status update in shipment journey
- Dispatch: Handover of shipment to carrier
- BOL (Bill of Lading): Shipping document
- Manifest: List of shipments in a load
src/main/java/com/paklog/shipment/
├── domain/ # Core business logic
│ ├── Shipment.java # Main aggregate root
│ ├── Load.java # Load aggregate
│ ├── TrackingEvent.java # Entity
│ ├── Package.java # Value object
│ ├── CarrierName.java # Value object
│ ├── repository/ # Repository interfaces (ports)
│ ├── services/ # Domain services
│ └── events/ # Domain events
├── application/ # Use cases & orchestration
│ ├── service/ # Application services
│ ├── port/ # Application ports
│ └── dto/ # Application DTOs
└── infrastructure/ # External adapters
├── persistence/ # MongoDB repositories
├── carrier/ # Carrier API adapters
├── messaging/ # Kafka consumers/publishers
├── outbox/ # Outbox scheduler
├── job/ # Scheduled tracking jobs
└── configuration/ # Configuration
- Hexagonal Architecture - Clean separation of domain and infrastructure
- Domain-Driven Design - Rich domain model with business invariants
- Event-Driven Architecture - Integration via domain events
- Transactional Outbox Pattern - Guaranteed event delivery
- Adapter Pattern - Unified interface for multiple carriers
- Strategy Pattern - Pluggable carrier selection strategies
- Repository Pattern - Data access abstraction
- SOLID Principles - Maintainable and extensible code
- Java 21 - Programming language
- Spring Boot 3.2+ - Application framework
- Maven - Build and dependency management
- MongoDB - Document database for aggregates
- Spring Data MongoDB - Data access layer
- Apache Kafka - Event streaming platform
- Spring Kafka - Kafka integration
- CloudEvents - Standardized event format
- FedEx API - FedEx carrier integration
- UPS API - UPS carrier integration
- WireMock - API mocking for testing
- Spring Web MVC - REST API framework
- SpringDoc OpenAPI - API documentation
- Bean Validation - Input validation
- Spring Boot Actuator - Health checks and metrics
- Micrometer - Metrics collection
- OpenTelemetry - Distributed tracing
- Prometheus - Metrics aggregation
- Loki - Log aggregation
- JUnit 5 - Unit testing framework
- Testcontainers - Integration testing
- WireMock - Carrier API mocking
- Mockito - Mocking framework
- AssertJ - Fluent assertions
- Docker - Containerization
- Docker Compose - Local development environment
- ✅ Hexagonal Architecture (Ports and Adapters)
- ✅ Domain-Driven Design tactical patterns
- ✅ Event-Driven Architecture
- ✅ Microservices architecture
- ✅ RESTful API design
- ✅ Anti-Corruption Layer for external APIs
- ✅ SOLID principles
- ✅ Clean Code practices
- ✅ Comprehensive unit and integration testing
- ✅ Domain-driven design patterns
- ✅ Immutable value objects
- ✅ Rich domain models with business logic
- ✅ CloudEvents specification v1.0
- ✅ Transactional Outbox Pattern
- ✅ At-least-once delivery semantics
- ✅ Event versioning strategy
- ✅ Idempotent event consumers
- ✅ Structured logging (JSON)
- ✅ Distributed tracing (OpenTelemetry)
- ✅ Health check endpoints
- ✅ Prometheus metrics
- ✅ Correlation ID propagation
- ✅ Custom business metrics
- Java 21+
- Maven 3.8+
- Docker & Docker Compose
-
Clone the repository
git clone https://github.com/paklog/shipment-transportation.git cd shipment-transportation -
Start infrastructure services
docker-compose up -d mongodb kafka
-
Build and run the application
mvn spring-boot:run
-
Verify the service is running
curl http://localhost:8080/api/management/health
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop all services
docker-compose downOnce running, access the interactive API documentation:
- Swagger UI: http://localhost:8080/api/swagger-ui.html
- OpenAPI Spec: http://localhost:8080/api/api-docs
GET /api/v1/shipments/{shipmentId}/tracking- Get shipment tracking detailsGET /api/management/health- Health check with carrier statusGET /api/management/metrics- Application metricsGET /api/management/prometheus- Prometheus metrics
# Run unit tests
mvn test
# Run integration tests
mvn verify
# Run tests with coverage
mvn clean verify jacoco:report
# View coverage report
open target/site/jacoco/index.htmlKey configuration properties:
spring:
data:
mongodb:
uri: ${MONGODB_URI:mongodb://localhost:27017/shipment_transport}
kafka:
bootstrap-servers: ${KAFKA_BROKERS:localhost:9092}
carriers:
fedex:
api-url: ${FEDEX_API_URL}
api-key: ${FEDEX_API_KEY}
account-number: ${FEDEX_ACCOUNT_NUMBER}
ups:
api-url: ${UPS_API_URL}
api-key: ${UPS_API_KEY}
account-number: ${UPS_ACCOUNT_NUMBER}
tracking:
job:
enabled: ${TRACKING_JOB_ENABLED:true}
interval: ${TRACKING_JOB_INTERVAL:3600000}com.paklog.warehouse.package.packed- From Warehouse Operations
com.paklog.shipment.dispatched.v1com.paklog.shipment.delivered.v1com.paklog.shipment.load.created.v1
All events follow the CloudEvents specification v1.0 and are published via the transactional outbox pattern.
- FedEx - Full integration with rate shopping and tracking
- UPS - Full integration with rate shopping and tracking
- Create carrier adapter implementing
ICarrierAdapter - Add carrier configuration
- Register adapter in Spring context
- Add integration tests with WireMock
- Purpose: Polls carrier APIs for shipment updates
- Frequency: Configurable (default: 1 hour)
- Metrics:
tracking.jobs.succeeded,tracking.jobs.failed
- Health: http://localhost:8080/api/management/health
- MongoDB connectivity
- Kafka connectivity
- Carrier API availability
- Outbox event status
- Metrics: http://localhost:8080/api/management/metrics
- Prometheus: http://localhost:8080/api/management/prometheus
- Info: http://localhost:8080/api/management/info
shipments.created- Shipments createdloads.tendered- Load tenders sentloads.booked- Load bookings confirmedcarrier.api.calls- Carrier API invocationscarrier.api.latency- Carrier API response timestracking.jobs.succeeded- Successful tracking updatestracking.jobs.failed- Failed tracking updates
- Follow hexagonal architecture principles
- Implement domain logic in domain layer
- Use carrier adapters for external integrations
- Maintain aggregate consistency boundaries
- Use transactional outbox for event publishing
- Write comprehensive tests including contract tests
- Document domain concepts using ubiquitous language
- Follow existing code style and conventions
Copyright © 2024 Paklog. All rights reserved.