Production-ready archetype for generating Spring Boot GraphQL federation gateways that aggregate multiple backend services into a unified GraphQL API for client consumption.
This archetype creates a complete, production-ready GraphQL domain gateway with:
- π GraphQL Federation: Unified GraphQL API aggregating multiple backend services
- β‘ Spring Boot Stack: Spring Boot 3+ with Spring for GraphQL
- π Service Aggregation: Connect and compose schemas from multiple gRPC or REST backend services
- π¨ Schema Stitching: Combine multiple GraphQL schemas into a single, cohesive API
- π Backend-for-Frontend (BFF): Optimized API layer tailored for client applications
- π Built-in Monitoring: Spring Boot Actuator with health checks and metrics
- π³ Container-Ready: Docker and Kubernetes deployment manifests
- π§ͺ Comprehensive Testing: Unit and integration tests for gateway logic
- π§ Local Development: Tilt integration for Kubernetes development
- π Performance Optimized: DataLoader integration for efficient batch queries
my-domain-gateway/
βββ src/
β βββ main/
β β βββ java/com/example/gateway/
β β β βββ config/ # Spring and GraphQL configuration
β β β βββ datafetchers/ # GraphQL data fetchers (resolvers)
β β β βββ model/ # GraphQL types and DTOs
β β β βββ service/ # Backend service clients
β β β βββ gateway/ # Gateway orchestration logic
β β βββ resources/
β β β βββ graphql/ # GraphQL schema definitions (.graphqls)
β β β βββ application.yml
β βββ test/
β βββ java/ # Unit and integration tests
β βββ resources/
βββ k8s/ # Kubernetes manifests
βββ .gitlab-ci.yml # GitLab CI/CD pipeline
βββ Dockerfile
βββ Tiltfile
βββ pom.xml # Maven build configuration
- Archetect CLI tool
- Java 17+ (Java 21 recommended)
- Maven 3.8+
- Docker Desktop (for containerized development)
# Using SSH
archetect render git@github.com:p6m-archetypes/java-spring-boot-graphql-domain-gateway.archetype.git
# Using HTTPS
archetect render https://github.com/p6m-archetypes/java-spring-boot-graphql-domain-gateway.archetype.git
# Example prompt answers:
# project: Shopping
# group-prefix: com.example
# team-name: Platformcd shopping-domain-gateway
# 1. Build the project
mvn clean install
# 2. Run tests
mvn test
# 3. Start the gateway
mvn spring-boot:run
# 4. Access endpoints
# - GraphQL API: http://localhost:9000/graphql
# - GraphiQL IDE: http://localhost:9000/graphiql
# - GraphQL Schema: http://localhost:9000/graphql/schema
# - Health Check: http://localhost:9001/actuator/health
# - Metrics: http://localhost:9001/actuator/metrics
# - All Actuator Endpoints: http://localhost:9001/actuatorWhen rendering the archetype, you'll be prompted for the following values:
| Property | Description | Example | Required |
|---|---|---|---|
project |
Domain name for the gateway (e.g., Shopping, Platform) | Shopping | Yes |
group-prefix |
Maven group ID prefix (reverse domain notation) | com.example | Yes |
team-name |
Owning team identifier for artifacts and documentation | Platform | Yes |
Derived Properties:
service-port: Set to 9000 for GraphQL HTTP trafficmanagement-port: Set to 9001 for Spring Boot Actuator endpointsdebug-port: Set to 9009 for remote debugging
Optional Configuration:
services: Configuration for backend services to aggregate (defined in answers file or interactively)
For complete property relationships, see archetype.yaml.
- API Gateway Pattern: Single entry point for multiple backend services
- Backend-for-Frontend (BFF): Tailored API optimized for specific client needs
- Schema Federation: Compose multiple service schemas into unified API
- Domain-Driven Design: Organize gateway by business domains
- Separation of Concerns: Clear boundaries between gateway logic and service clients
- Spring Boot 3+: Enterprise-grade framework with auto-configuration
- Spring for GraphQL: Official Spring GraphQL integration
- GraphQL Java: Robust GraphQL implementation for Java
- DataLoader: Efficient batching and caching for N+1 query prevention
- Maven: Dependency management and build automation
- gRPC/REST Clients: Connect to backend services via gRPC or REST
- Resilience4j: Circuit breakers and retry logic for fault tolerance
- Tilt: Local Kubernetes development with hot reload
- Spring Boot Actuator: Production-ready monitoring endpoints
- Health Checks: Liveness and readiness endpoints for Kubernetes probes
- GraphQL Metrics: Query performance and execution tracking
- Service Health: Aggregate health from backend services
- Metrics: Micrometer metrics with Prometheus format support
- Distributed Tracing: OpenTelemetry support for request tracing
- Unit Tests: JUnit 5 for business logic validation
- Integration Tests: End-to-end GraphQL query testing
- Schema Validation: Automated schema validation and compatibility checks
- Mock Services: Test with mocked backend service responses
- GraphQL Testing: Query and mutation testing with test harness
- Docker: Multi-stage Dockerfile for optimized production images
- Kubernetes: Complete deployment manifests with ConfigMaps and Secrets
- GitLab CI: Pre-configured CI/CD pipeline for build, test, and deploy
- Tilt: Hot-reload development in local Kubernetes clusters
- Artifactory: Docker image publication configuration
- Health Probes: Kubernetes liveness and readiness probe configuration
This archetype is ideal for:
-
API Aggregation: Combining multiple backend microservices into a unified GraphQL API
- Federate gRPC services (products, users, inventory, orders)
- Integrate REST APIs (legacy services, third-party APIs)
- Compose multiple GraphQL services (schema stitching/federation)
- Single endpoint for frontend applications to consume
-
Backend-for-Frontend (BFF): Creating client-specific APIs for different platforms
- Web BFF with desktop-optimized queries
- Mobile BFF with reduced payload sizes
- Desktop BFF with rich data models
- Each BFF tailored to specific client needs and network constraints
-
GraphQL Federation Hub: Organizing distributed GraphQL schemas
- Multiple GraphQL domain services (products, users, orders)
- Unified schema with cross-domain relationships
- Apollo Federation or schema stitching patterns
- Gradual migration from monolithic to federated GraphQL
-
Microservices Facade: Simplifying complex service meshes for client consumption
- Hide internal service complexity from frontend teams
- Handle service orchestration and data composition
- Provide consistent error handling and response formats
- Circuit breakers and fallbacks for service failures
-
Transport Translation: Converting between different API styles
- gRPC (internal) β GraphQL (frontend)
- REST (legacy) β GraphQL (modern)
- Multiple transports β Unified GraphQL interface
- Gradual migration path from REST to GraphQL
Typical Architecture:
Frontend Apps (React, Vue, Angular)
β
GraphQL Domain Gateway (this archetype)
β
Internal Services:
- gRPC Services (high-performance)
- REST Services (legacy/third-party)
- GraphQL Services (domain-specific)
- Databases (when needed)
Unified GraphQL schema composed from multiple backend services. Defines queries, mutations, and types available to clients.
Spring components that implement GraphQL resolvers. Handle field resolution, data fetching from backend services, and error handling.
HTTP or gRPC clients for communicating with backend microservices. Include connection pooling, timeout configuration, and circuit breakers.
Batching and caching layer to prevent N+1 query problems when fetching related data from multiple services.
Comprehensive monitoring endpoints including health checks, metrics, environment info, and custom gateway metrics.
- GraphiQL IDE: Interactive GraphQL query editor and documentation explorer
- Schema Introspection: Automatic schema documentation and validation
- Tilt Configuration: Auto-reload development in Kubernetes
- Maven Wrapper: Consistent Maven version across environments
- application.yml: Spring Boot configuration with profiles for dev, test, and prod
- Service Configuration: Backend service endpoints and connection settings
- GraphQL Configuration: Query complexity limits, execution timeouts, and caching
- Resilience Configuration: Circuit breaker, retry, and timeout policies
- Schema-First Development: Define schemas in
.graphqlsfiles - Type Safety: Strong typing with Java class mapping
- Custom Scalars: Support for DateTime, UUID, and custom scalar types
- Directives: Custom directives for authorization, caching, and field resolution
- Field Selection: Clients request only the fields they need
- Nested Queries: Traverse relationships across multiple services
- Fragments: Reusable query fragments for complex queries
- Aliases: Query the same field multiple times with different arguments
- Variables: Parameterized queries for dynamic inputs
- DataLoader: Automatic request batching and caching
- Query Complexity Analysis: Prevent expensive queries from overloading backend services
- Depth Limiting: Configurable query depth limits
- Pagination: Cursor-based and offset pagination support
- Subscriptions: Real-time updates via WebSocket (optional)
- Federation: GraphQL Federation 2.0 support for distributed schemas
- Field-Level Caching: Cache individual field resolutions
- Request Batching: Combine multiple backend service calls
- Connection Pooling: Reuse HTTP/gRPC connections to backend services
- Circuit Breakers: Prevent cascading failures from backend services
- Async Execution: Non-blocking request handling
Generated gateways are production-ready and include:
- β Successful Maven build with all dependencies resolved
- β All unit and integration tests pass
- β Docker image builds successfully
- β Service starts and responds to health checks
- β GraphQL schema is valid and queryable
- β Backend service connections configured
- β GraphiQL interface accessible
Validate your generated gateway:
mvn clean verify
docker build -t my-gateway .Access the GraphiQL IDE at http://localhost:9000/graphiql to:
- Explore the schema with auto-complete
- Run test queries and mutations
- View schema documentation
- Debug query execution
Example query:
query GetProduct {
product(id: "123") {
id
name
price
inventory {
quantity
warehouse
}
}
}# Execute GraphQL query
curl http://localhost:9000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ product(id: \"123\") { id name } }"}'
# Check health
curl http://localhost:9001/actuator/health
# View GraphQL metrics
curl http://localhost:9001/actuator/metrics/graphql.queryDefine backend services in application.yml:
services:
product-service:
url: http://product-service:9010
type: grpc
timeout: 5s
inventory-service:
url: http://inventory-service:8080
type: rest
timeout: 3sConfigure resilience patterns:
resilience4j:
circuitbreaker:
instances:
product-service:
failure-rate-threshold: 50
wait-duration-in-open-state: 10sPrevent resource exhaustion:
graphql:
query:
max-complexity: 200
max-depth: 10Switch between environments:
# Development profile
mvn spring-boot:run -Pdev
# Production profile
mvn spring-boot:run -Pprod- Java Spring Boot gRPC Service - Backend gRPC service for this gateway to aggregate
- .NET GraphQL Service - .NET GraphQL service alternative
- Python GraphQL Service - Python GraphQL service for comparison
- TypeScript Next.js - Frontend application that can consume this gateway
This archetype is actively maintained. For issues or enhancements:
- Check existing issues in the repository
- Create detailed bug reports or feature requests
- Follow the contribution guidelines
- Test changes with Maven verify
- Validate schema federation scenarios
This archetype is released under the MIT License. Generated gateways inherit this license but can be changed as needed for your organization.
Ready to build production-grade GraphQL gateways with Spring Boot? Generate your first gateway and start aggregating services in minutes! π