3. Logistics Service‐MongoDB Edition‐ Project structure - Wiz-DevTech/prettygirllz GitHub Wiki

Here's an optimized project structure for your Java/Maven/MongoDB Logistics Service with clear separation of concerns and enhanced testability:

logistics-service/
├── .github/                          # CI/CD workflows
│   └── workflows/
│       ├── ci.yml                    # Test on PR
│       └── release.yml               # Deployment
│
├── src/
│   ├── main/
│   │   ├── java/com/company/logistics/
│   │   │   ├── application/          # Main app config
│   │   │   │   └── LogisticsApp.java
│   │   │   │
│   │   │   ├── api/                  # Presentation layer
│   │   │   │   ├── v1/               # Versioned APIs
│   │   │   │   │   ├── DeliveryApi.java
│   │   │   │   │   └── FraudApi.java
│   │   │   │   ├── dto/              # Data transfer objects
│   │   │   │   │   ├── request/
│   │   │   │   │   └── response/
│   │   │   │   └── exception/        # Exception handlers
│   │   │   │
│   │   │   ├── core/                 # Domain layer
│   │   │   │   ├── model/
│   │   │   │   ├── service/
│   │   │   │   └── event/
│   │   │   │
│   │   │   ├── infrastructure/       # Infrastructure layer
│   │   │   │   ├── config/
│   │   │   │   ├── mongodb/
│   │   │   │   ├── kafka/
│   │   │   │   └── redis/
│   │   │   │
│   │   │   └── orchestration/        # Specialized packages
│   │   │       ├── hds/              # Home Delivery System
│   │   │       ├── dzn/              # Drop Zone Network
│   │   │       │   ├── qr/
│   │   │       │   ├── location/
│   │   │       │   └── cache/
│   │   │       └── fraud/            # Fraud Detection
│   │   │
│   │   └── resources/
│   │       ├── config/
│   │       │   ├── application.yml
│   │       │   ├── application-dev.yml
│   │       │   └── application-prod.yml
│   │       ├── db/
│   │       │   └── migration/        # MongoDB migrations
│   │       └── kafka/
│   │           └── schemas/          # Avro schemas
│   │
│   └── test/                         # Mirror main structure
│       ├── java/
│       └── resources/
│           ├── test-config.yml
│           └── fixtures/             # Test data
│
├── docker/                           # Containerization
│   ├── compose/
│   │   ├── local/
│   │   └── test/
│   └── scripts/
│
├── docs/
│   ├── api/                          # OpenAPI specs
│   ├── architecture/                 # Diagrams
│   └── adr/                          # Architecture decisions
│
├── libs/                             # Shared libraries
│   └── common-model/                 # Cross-service DTOs
│
├── .env.example                      # Env template
├── Dockerfile
├── pom.xml
├── Makefile                          # Build shortcuts
└── README.md

Key Improvements:

  1. Clean Architecture:

    • Clear separation between api/core/infrastructure
    • Domain logic isolated from delivery mechanisms
  2. Enhanced Testability:

    • Test packages mirror main structure
    • Dedicated test fixtures
    • Separate test configuration
  3. Delivery System Specialization:

    • Dedicated packages for HDS/DZN
    • Explicit fraud detection module
  4. Infrastructure Ready:

    • Versioned API endpoints
    • Containerization support
    • Database migrations
  5. Cross-Cutting Concerns:

    • Centralized exception handling
    • Shared DTO definitions
    • Event schemas management

Implementation Notes:

  1. For MongoDB Operations:

    // infrastructure/mongodb/
    @Document(collection = "deliveries")
    public class DeliveryDocument {
        @Id private String id;
        private DeliveryStatus status;
        // MongoDB-specific fields
    }
    
  2. Kafka Integration:

    // infrastructure/kafka/
    @Configuration
    public class KafkaConfig {
        @Bean
        public ProducerFactory<String, DeliveryEvent> producerFactory() {
            // Avro serializer config
        }
    }
    
  3. DZN Components:

    // orchestration/dzn/qr/
    @Service
    public class QrService {
        public String generateQr(Delivery delivery) {
            // QR generation logic
        }
    }
    

This structure supports:

  • Easy onboarding with clear package boundaries
  • Independent development of delivery systems
  • Straightforward test automation
  • Gradual migration from monolithic systems
  • Clear upgrade paths for components

The libs/common-model folder is particularly important for ensuring compatibility with other services by sharing:

  • Event schemas
  • Common DTOs
  • Enum definitions
  • Exception types