spring-maven-modular

mduongvandinh's avatarfrom mduongvandinh

Maven Modular Architecture with profiles for optional components.Enable/disable modules like Redis, Kafka, RabbitMQ dynamically.

⭐0stars🔀0forks📁View on GitHub🕐Updated Dec 26, 2025

When & Why to Use This Skill

This Claude skill provides a robust Maven Modular Architecture template specifically designed for Spring Boot applications. It enables developers to dynamically manage optional infrastructure components—such as Redis, Kafka, and RabbitMQ—using Maven profiles and custom properties. By implementing conditional bean loading and modular dependencies, it facilitates the creation of scalable, maintainable, and resource-efficient enterprise systems.

Use Cases

  • Microservices Foundation: Establishing a standardized, modular base for a microservices ecosystem where different services can selectively enable shared modules like OAuth2 or messaging queues.
  • Environment-Specific Optimization: Utilizing the 'minimal' profile to disable heavy infrastructure components during local development to speed up build times and reduce memory consumption.
  • Customizable Enterprise Software: Building a core product where specific features (e.g., Kafka for event streaming or RabbitMQ for task queues) can be toggled on or off at build time based on specific client requirements or deployment tiers.
  • Cloud-Native Deployment: Streamlining CI/CD pipelines by using Maven profiles to package only the necessary modules for specific cloud environments, optimizing the final artifact size.
namespring-maven-modular
version1.0.0
description|

Maven Modular Architecture

Module Flags

Module Default Property
PostgreSQL ON module.postgresql.enabled
Redis OFF module.redis.enabled
Kafka OFF module.kafka.enabled
RabbitMQ OFF module.rabbitmq.enabled
OAuth2 OFF module.oauth2.enabled

Usage

# Minimal (PostgreSQL only)
mvn clean install -Pminimal

# With Redis
mvn clean install -Dmodule.redis.enabled=true

# With Kafka
mvn clean install -Dmodule.kafka.enabled=true

# Full stack
mvn clean install -Pfull-stack

# Custom combination
mvn clean install -Dmodule.redis.enabled=true -Dmodule.kafka.enabled=true

Profiles

Minimal Profile

  • PostgreSQL (always)
  • JWT Authentication

Full Stack Profile

  • PostgreSQL
  • Redis
  • Kafka
  • OAuth2

Spring Configuration

Use @ConditionalOnModuleEnabled to conditionally load beans:

@Configuration
@ConditionalOnModuleEnabled("redis")
public class RedisConfig {
    // Only loaded when modules.redis.enabled=true
}

application.yml

modules:
  postgresql:
    enabled: true
  redis:
    enabled: ${MODULE_REDIS_ENABLED:false}
  kafka:
    enabled: ${MODULE_KAFKA_ENABLED:false}
  rabbitmq:
    enabled: ${MODULE_RABBITMQ_ENABLED:false}
  oauth2:
    enabled: ${MODULE_OAUTH2_ENABLED:false}