- Docker Compose: Local Mailing, Mocked Remotes
pre-commit installExport realm:
# Create a Docker volume to share Keycloak data
docker volume create keycloak_data
# Run Keycloak with this volume
docker run -d --name keycloak \
-v keycloak_data:/opt/keycloak/data \
-p 8888:8080 \
-p 9000:9000 \
-e KEYCLOAK_ADMIN=admin \
-e KEYCLOAK_ADMIN_PASSWORD=admin \
-e KC_DB=dev-file \
-e KC_HEALTH_ENABLED=true \
quay.io/keycloak/keycloak:26.1 \
start-dev
# Configure your realm through the UI...
# Then stop that container
docker stop keycloak
# Run a new container just for export using the same volume
docker run --rm -it \
-v keycloak_data:/opt/keycloak/data \
-v $(pwd):/export \
quay.io/keycloak/keycloak:26.1 \
export --dir /export --realm spring --users realm_file
MockShelf is a comprehensive library management system designed for testing and development purposes. It demonstrates modern Spring Boot application architecture with a focus on testing techniques and microservice principles.
C4Context
title System Context Diagram for MockShelf Library Management System
Person(librarian, "Librarian", "Manages library resources and user accounts")
Person(reader, "Library User", "Browses and borrows books")
System(mockshelf, "MockShelf", "Library management system for book lending and tracking")
Rel(librarian, mockshelf, "Manages")
Rel(reader, mockshelf, "Uses")
C4Container
title Container Diagram for MockShelf
Person(reader, "Library User")
Person(librarian, "Librarian")
System_Boundary(mockshelf, "MockShelf") {
Container(web_app, "Web Application", "Spring Boot, Thymeleaf, HTMX", "Provides user interfaces for book browsing, borrowing, and management")
Container(auth_service, "Authentication Service", "Keycloak", "Handles user authentication and authorization")
Container(book_service, "Book Service", "Spring Boot", "Manages book catalog and inventory")
Container(loan_service, "Loan Service", "Spring Boot", "Manages book loans and returns")
Container(notification_service, "Notification Service", "Spring Boot", "Handles email and SMS notifications")
ContainerDb(postgres, "Database", "PostgreSQL", "Stores library data")
ContainerDb(activemq, "Message Broker", "ActiveMQ", "Handles asynchronous messaging")
}
System_Ext(email_system, "Email System")
System_Ext(isbn_lookup, "ISBN Lookup Service")
Rel(reader, web_app, "Interacts with")
Rel(librarian, web_app, "Manages")
Rel(web_app, auth_service, "Authenticates")
Rel(web_app, book_service, "Manages books")
Rel(web_app, loan_service, "Manages loans")
Rel(book_service, postgres, "Reads/Writes")
Rel(loan_service, postgres, "Reads/Writes")
Rel(notification_service, activemq, "Consumes/Publishes messages")
Rel(notification_service, email_system, "Sends emails")
Rel(book_service, isbn_lookup, "Looks up book details")
C4Component
title Component Diagram for Book Service
Container(book_service, "Book Service", "Spring Boot", "Manages book catalog and inventory")
Component(book_controller, "Book Controller", "REST Controller", "Handles HTTP requests for book operations")
Component(book_service_component, "Book Service", "Service Layer", "Business logic for book management")
Component(book_repository, "Book Repository", "JPA Repository", "Handles database interactions")
Component(isbn_lookup_service, "ISBN Lookup Service", "External Service Integration", "Fetches book details from external API")
Rel(book_controller, book_service_component, "Uses")
Rel(book_service_component, book_repository, "Persists")
Rel(book_service_component, isbn_lookup_service, "Retrieves book details")
- Testability
- Modularity
- Security
- Performance
- Backend: Spring Boot 3.4.3
- Authentication: Keycloak
- Database: PostgreSQL
- ORM: Spring Data JPA
- Messaging: ActiveMQ
- Frontend: Thymeleaf, HTMX, Alpine.js
- Testing: JUnit 5, Testcontainers
- Microservices-like architecture
- Repository pattern
- Event-driven notifications
- Resource server authentication
MockShelf uses Docker Compose for local development, spinning up:
- Application container
- PostgreSQL database
- Keycloak authentication
- ActiveMQ message broker
- MailDev for email testing
- WireMock for external service mocking
- Unit Tests: Extensive coverage of service and repository layers
- Integration Tests: Using Testcontainers for realistic environment
- Web Tests: HTMX and Thymeleaf rendering checks
- End-to-End Tests: Simulated user journeys
- JUnit 5
- Testcontainers
- Selenium
- Mockito
- Spring Boot Test
- OAuth 2.0 Resource Server
- Role-based access control
- JWT token authentication
- CSRF protection
- HTTPS enforcement
- Spring Boot Actuator
- JobRunr for background job tracking
- Logging with SLF4J
- Potential integration with Prometheus/Grafana
- Microservices decomposition
- Enhanced caching strategies
- More granular authorization
- Enhanced monitoring
graph TD
subgraph "External Services & Infrastructure"
KC[" π Keycloak\nAuthentication & Authorization"]
PG[" π PostgreSQL\nPersistent Data Storage"]
AMQ[" π¬ ActiveMQ\nMessage Queuing"]
MD[" π§ MailDev\nEmail Testing"]
WM[" π WireMock\nExternal API Simulation"]
JR[" π JobRunr\nBackground Job Processing"]
ISBN[" π Open Library API\nISBN Book Lookup"]
end
subgraph "MockShelf Application"
APP[" π Spring Boot App\nCore Application Logic"]
end
subgraph "Development & CI/CD"
GH[" π GitHub\nSource Control"]
DC[" π³ Docker Compose\nLocal Environment"]
PC[" π§ͺ Pre-commit\nCode Quality Checks"]
MVN[" π Maven\nDependency Management"]
end
subgraph "Monitoring & Observability"
ACT[" π Spring Actuator\nSystem Monitoring"]
LOG[" π SLF4J Logging\nApplication Logs"]
end
APP <-->|Authentication| KC
APP <-->|Persistent Storage| PG
APP <-->|Messaging| AMQ
APP <-->|Job Processing| JR
APP <-->|Book Lookup| ISBN
DC <-->|Manages| KC
DC <-->|Manages| PG
DC <-->|Manages| AMQ
DC <-->|Manages| MD
DC <-->|Manages| WM
GH <-->|CI/CD| APP
MVN <-->|Dependency Management| APP
APP <-->|Monitoring| ACT
APP <-->|Logging| LOG
- Keycloak π
- Open-source identity and access management
- Provides OAuth 2.0 and OpenID Connect
- Handles user authentication, authorization, and user management
- PostgreSQL π
- Robust, open-source relational database
- Stores books, loans, users, and other library-related data
- Supports complex queries and transactions
- ActiveMQ π¬
- Message broker for asynchronous communication
- Enables event-driven notifications
- Supports complex messaging patterns
- MailDev π§
- SMTP testing server
- Captures and displays outgoing emails
- Helps in development and testing email functionality
- WireMock π
- Lightweight API mocking tool
- Simulates external service responses
- Enables predictable testing of external integrations
- JobRunr π
- Distributed background job processing
- Manages and monitors long-running tasks
- Provides job scheduling and retry mechanisms
- Open Library API π
- Free, open-source book information API
- Provides book details based on ISBN
- Enriches book catalog with external metadata
-
GitHub π
- Source code management
- Workflow automation
- Continuous integration
-
Docker Compose π³
- Local environment orchestration
- Simplifies service dependencies
- Ensures consistent development setup
-
Pre-commit π§ͺ
- Code quality checks
- Enforces coding standards
- Runs linters and formatters before commits
-
Maven π
- Dependency management
- Build automation
- Project structure and plugin management
-
Spring Actuator π
- Provides production-ready features
- Health checks and metrics
- Exposes operational information
-
SLF4J Logging π
- Standardized logging facade
- Configurable log levels
- Supports multiple logging implementations
- Modularity: Each component has a clear, focused responsibility
- Testability: Easy to mock and test individual components
- Scalability: Loosely coupled services
- Developer Experience: Tools that enhance productivity
- Local development with Docker Compose
- Potential Kubernetes deployment for scaling
- Stateless design for horizontal scaling
- Centralized configuration management