This document provides a comprehensive view of the Lettuce project's architecture and structure, highlighting the key components and their relationships.
lettuce/
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ └── lettuce/
│ │ │ ├── domain/ # Domain Layer
│ │ │ │ ├── carbonfootprint/ # Carbon Footprint Domain
│ │ │ │ │ ├── aggregate/ # Aggregate Roots
│ │ │ │ │ ├── event/ # Domain Events
│ │ │ │ │ ├── repository/ # Repositories
│ │ │ │ │ └── service/ # Domain Services
│ │ │ │ ├── reward/ # Reward Domain
│ │ │ │ │ ├── aggregate/ # Aggregate Roots
│ │ │ │ │ ├── engine/ # Reward Rule Engine
│ │ │ │ │ ├── event/ # Domain Events
│ │ │ │ │ ├── repository/ # Repositories
│ │ │ │ │ ├── service/ # Domain Services
│ │ │ │ │ └── specification/ # Specifications
│ │ │ │ └── user/ # User Domain
│ │ │ │ ├── aggregate/ # Aggregate Roots
│ │ │ │ ├── repository/ # Repositories
│ │ │ │ └── service/ # Domain Services
│ │ │ ├── global/ # Global Components
│ │ │ │ ├── config/ # Configuration Classes
│ │ │ │ ├── framework/ # Framework Components
│ │ │ │ │ ├── event/ # Event Framework
│ │ │ │ │ ├── exception/ # Exception Handling
│ │ │ │ │ └── security/ # Security Framework
│ │ │ │ └── infrastructure/ # Infrastructure Components
│ │ │ │ ├── ai/ # AI Services
│ │ │ │ └── storage/ # Storage Services
│ │ │ ├── interfaces/ # Application Layer
│ │ │ │ ├── api/ # REST API Controllers
│ │ │ │ ├── dto/ # Data Transfer Objects
│ │ │ │ └── mapper/ # DTO-Entity Mappers
│ │ │ └── application/ # Application Services
│ │ │ ├── carbonfootprint/ # Carbon Footprint Application Services
│ │ │ ├── reward/ # Reward Application Services
│ │ │ └── user/ # User Application Services
│ │ └── resources/
│ │ ├── application.yml # Main Configuration
│ │ ├── rules/ # Drools Rules
│ │ │ └── reward-rules.drl # Reward Calculation Rules
│ │ ├── db/ # Database Migration Scripts
│ │ │ └── migration/ # Flyway Migrations
│ │ └── static/ # Static Resources
│ └── test/
│ ├── java/ # Test Classes
│ │ └── com/
│ │ └── example/
│ │ └── lettuce/
│ │ ├── domain/ # Domain Tests
│ │ ├── interfaces/ # Interface Tests
│ │ └── application/ # Application Tests
│ └── resources/ # Test Resources
├── build.gradle # Gradle Build Configuration
├── settings.gradle # Gradle Settings
├── README.md # Project Documentation
├── LICENSE # MIT License
└── .gitignore # Git Ignore Configuration
┌─────────────────────────────────────────────────────────────────┐
│ Presentation Layer │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ REST API │ │ DTO │ │ Mappers │ │
│ │ Controllers │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Application Layer │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Carbon │ │ Reward │ │ User │ │
│ │ Footprint │ │ Application │ │ Application │ │
│ │ Application │ │ Services │ │ Services │ │
│ │ Services │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Domain Layer │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Carbon │ │ Reward │ │ User │ │
│ │ Footprint │ │ Domain │ │ Domain │ │
│ │ Domain │ │ │ │ │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Aggregates │ │ Domain Events │ │ Specifications │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Infrastructure Layer │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Event Store │ │ Rule Engine │ │ Repositories │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
│ │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Disruptor │ │ OpenCV │ │ Columnar │ │
│ │ Event Queue │ │ Image │ │ Storage │ │
│ │ │ │ Processing │ │ Service │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
-
Carbon Footprint Domain
CarbonFootprint(Aggregate Root): Tracks carbon footprint calculationsFootprintCalculatedEvent: Published when a carbon footprint is calculatedImageProcessingService: Processes images for carbon footprint calculation
-
Reward Domain
RewardWallet(Aggregate Root): Manages user rewards and transactionsRewardTransaction: Records reward transactionsRewardGrantedEvent: Published when a reward is granted to a userRewardRuleEngine: Calculates rewards based on configurable rulesEligibleForRewardSpec: Determines if a carbon footprint is eligible for rewardsCarbonNeutralSpec: Determines if a user has achieved carbon neutrality
-
User Domain
User(Aggregate Root): Manages user profile and authentication
-
Event Framework
JpaEventStore: Stores domain events in a databaseDisruptorEventQueue: High-performance inter-thread messagingEventEntity: JPA entity for storing events
-
Storage Services
ColumnarStorageService: Efficient storage and querying of large datasetsCarbonFootprintAnalytics: Analytics for carbon footprint data
-
Configuration
OpenCVConfig: Configuration for OpenCV image processingDroolsConfig: Configuration for Drools rule engineDisruptorConfig: Configuration for Disruptor event queueHadoopConfig: Configuration for Hadoop and Parquet
-
Carbon Footprint Calculation Flow
User uploads image → ImageProcessingService preprocesses image → AI analyzes image → CarbonFootprint created → FootprintCalculatedEvent published → DisruptorEventQueue processes event → RewardRuleEngine calculates reward → RewardWallet updated → RewardGrantedEvent published -
Analytics Flow
User requests analytics → CarbonFootprint data retrieved → ColumnarStorageService processes data → CarbonFootprintAnalytics generated → Results returned to user
-
Lock-Free Queue Design
- Disruptor Pattern for high-performance inter-thread messaging
- Capable of processing 150,000 events per second
-
Columnar Storage
- Apache Parquet + S3 Select for efficient storage and querying
- 70% faster analytics compared to row-based storage
-
JVM Tuning
- ZGC for low-latency garbage collection
- Maximum 10ms pause times