How wushidong125/sharding-db works
Main Components
• Application Entry Point: The Spring Boot application (ShardingDbApplication.java) initializes the application.
• Configuration Layer: DataSourceConfig.java configures the data sources, establishes the Druid connection pool, and integrates the Sharding-JDBC properties.
• Sharding Strategy: The classes in the “base” package (ModuloDatabaseShardingAlgorithm.java and ModuloTableShardingAlgorithm.java) contain the logic for determining which database and table to use.
• API Layer: The “controller” package (OrderController.java) exposes endpoints (e.g., for order operations) to the external world.
• Persistence Layer: The “repository” (OrderRepository.java) and “entity” (Order.java) represent the data-access components using JPA/Hibernate and map the Order domain.
• Testing: Though not part of the runtime architecture, the “test” folder is for unit and integration tests.
• External Resources: The Sharding-JDBC library (from dangdangdotcom) and the Druid connection pool are key external technologies that should be represented.
Relationships and Data Flow
• Clients (could be a web interface or another external service) send HTTP requests to the OrderController.
• The OrderController handles these requests by interacting with the repository layer.
• The OrderRepository interacts with the database using JPA, while the DataSourceConfig ensures that requests are directed toward the appropriate shard.
• The sharding algorithm (comprising both database and table strategies) is invoked during data source selection by the underlying Sharding-JDBC mechanism.
• The connection to the database is managed via the Druid connection pool.
Key Architectural Patterns and Patterns to Emphasize
• Layered Architecture: Clearly separate the Controller, Configuration, and Persistence layers.
• Database Sharding: Visibly represent how the modulo-based algorithms are used to distribute data across multiple database and table shards.
• Integration with External Libraries: Indicate where the Sharding-JDBC and Druid components integrate with the core application.
Clarity and Detail
• All blocks must be clearly labeled with their names and roles.
• To annotate integration points with external libraries like the Sharding-JDBC and Druid connection pool if space allows.