Production-ready archetype for generating modular .NET GraphQL services with Entity Framework Core, flexible persistence options, and modern observability.
This archetype creates a complete, production-ready GraphQL service with:
- 🏗️ Modular Architecture: Namespace-organized, service-oriented design with separate API, Core, and Persistence layers
- ⚡ Modern .NET Stack: .NET 8+ with Entity Framework Core
- 🔌 GraphQL API: Type-safe GraphQL APIs with Hot Chocolate framework for queries, mutations, and subscriptions
- 💾 Flexible Persistence: Choose from PostgreSQL, MySQL, MSSQL, or no database
- 🐳 Container-Ready: Docker and Kubernetes deployment manifests
- 📊 Built-in Monitoring: Health checks and metrics endpoints
- 🧪 Comprehensive Testing: Unit and integration tests with Testcontainers
- 🔧 Local Development: Tilt integration for Kubernetes development
my-shopping-cart-service/
├── src/
│ ├── ShoppingCart.Api/ # GraphQL schema and type definitions
│ ├── ShoppingCart.Core/ # Business logic and domain models
│ ├── ShoppingCart.Persistence/ # Entity Framework data layer
│ └── ShoppingCart.Server/ # GraphQL server implementation
├── tests/
│ ├── ShoppingCart.UnitTests/
│ └── ShoppingCart.IntegrationTests/
├── k8s/ # Kubernetes manifests
├── Dockerfile
└── docker-compose.yml
- Archetect CLI tool
- .NET 8 SDK or later
- Docker Desktop (for containerized development and testing)
# Using SSH
archetect render git@github.com:p6m-archetypes/dotnet-graphql-service-basic.archetype.git
# Using HTTPS
archetect render https://github.com/p6m-archetypes/dotnet-graphql-service-basic.archetype.git
# Example prompt answers:
# project: Shopping Cart
# suffix: Service
# group-prefix: com.example
# team-name: Platform
# persistence: PostgreSQL
# service-port: 5030cd shopping-cart-service
# 1. Restore dependencies
dotnet restore
# 2. Run tests
dotnet test
# 3. Start the service
dotnet run --project src/ShoppingCart.Server
# 4. Access endpoints
# - GraphQL Playground: http://localhost:5030/graphql
# - GraphQL API: http://localhost:5030/graphql
# - Health Check: http://localhost:5031/health
# - Metrics: http://localhost:5031/metricsWhen rendering the archetype, you'll be prompted for the following values:
| Property | Description | Example | Required |
|---|---|---|---|
project |
Service domain name used for namespaces and entities | Shopping Cart | Yes |
suffix |
Appended to project name for package naming | Service | Yes |
group-prefix |
Namespace prefix (reverse domain notation) | com.example | Yes |
team-name |
Owning team identifier for artifacts and documentation | Platform | Yes |
persistence |
Database type for data persistence | PostgreSQL | Yes |
service-port |
Port for GraphQL HTTP traffic | 5030 | Yes |
Derived Properties:
management-port: Automatically set toservice-port + 1for health/metrics endpointsdatabase-port: Set to 5432 for PostgreSQL-based servicesdebug-port: Set toservice-port + 9for debugging
For complete property relationships, see archetype.yaml.
- Modular Structure: Clean separation of API, Core, Persistence, and Server concerns
- Domain-Driven Design: Entity-centric business logic organization
- Dependency Injection: Built-in .NET DI container configuration
- Clean Architecture: Dependencies flow toward domain core
- .NET 8+: Latest LTS framework with performance improvements
- Hot Chocolate: Modern, high-performance GraphQL server for .NET
- Entity Framework Core: Modern ORM with migration support and async operations
- Testcontainers: Containerized integration testing with real databases
- Tilt: Local Kubernetes development workflow with hot reload
- Health Checks: Liveness and readiness endpoints for Kubernetes probes
- Metrics: Prometheus-compatible metrics endpoint
- Structured Logging: Configurable log levels and structured output
- GraphQL Metrics: Query performance tracking and monitoring
- Unit Tests: xUnit test projects for business logic validation
- Integration Tests: Full service testing with Testcontainers and real databases
- GraphQL Testing: Query and mutation testing with in-memory server
- Test Coverage: Configured coverage reporting
- Docker: Multi-stage Dockerfile for optimized production images
- Kubernetes: Complete deployment manifests with ConfigMaps and Secrets
- Tilt: Hot-reload development in local Kubernetes clusters
- Artifactory: Docker image publication configuration included
This archetype is ideal for:
-
Domain Services: GraphQL services focused on specific business domains
- Products service, Users service, Orders service
- Can be federated into a larger GraphQL gateway (schema stitching)
- Provides flexible querying within a single domain
- Alternative to REST for client-driven data fetching
-
Data Aggregation Services: Services combining data from multiple sources
- Fetch from databases, REST APIs, gRPC services, message queues
- DataLoader for efficient batching and caching
- Resolve complex data graphs across multiple backends
- Transform and optimize data for client consumption
-
Backend-for-Frontend (BFF): Tailored APIs for specific client types
- Web BFF, Mobile BFF, Desktop BFF with optimized schemas
- Client-specific field selection and pagination strategies
- Reduce over-fetching by letting clients query exactly what they need
- Version-free APIs through schema evolution
-
Customer-Facing APIs: Public GraphQL APIs with flexible querying
- Self-documenting schema with introspection
- Query complexity limits and depth restrictions
- Batched queries reduce network round-trips
- Modern alternative to versioned REST APIs
Architectural Note: GraphQL services can be:
- Standalone: Complete domain service with its own database
- Federated: Part of a larger GraphQL gateway (schema federation)
- Aggregator: Combines REST/gRPC services into a unified GraphQL API
- Hybrid: Mix of direct data access and service delegation
Hot Chocolate-based GraphQL schema with queries, mutations, and type definitions. Includes automatic schema generation from C# classes and resolver configuration.
Database access layer with migrations, connection pooling, and async operations. Supports PostgreSQL, MySQL, MSSQL, or no persistence for stateless services.
Built-in health check endpoints for Kubernetes liveness/readiness probes and Prometheus metrics for monitoring query performance and resource usage.
- Tilt Configuration: Auto-reload development in Kubernetes with live updates
- Docker Compose: Local development stack with database services
- GraphQL Playground: Interactive API exploration and testing
- appsettings.json: Environment-specific configuration files
- Environment Variables: 12-factor app configuration support
- CLI Arguments: Runtime configuration overrides
- Connection Strings: Secure database connection management
- Schema-First or Code-First: Support for both GraphQL development approaches
- Type Safety: Strong typing with automatic C# to GraphQL type mapping
- Custom Scalars: Support for custom scalar types (DateTime, Decimal, etc.)
- Documentation: Automatic API documentation from code comments
- Queries & Mutations: Full CRUD operations over GraphQL
- Filtering & Sorting: Built-in support for filtering and sorting collections
- Pagination: Relay-style cursor pagination and offset pagination
- DataLoader: Automatic batching and caching to prevent N+1 queries
- Subscriptions: Real-time updates with GraphQL subscriptions (WebSocket support)
- Error Handling: Structured error responses with custom error codes
- Query Complexity Analysis: Prevent expensive queries from overloading the service
- Depth Limiting: Configurable query depth limits
- Persisted Queries: Support for persisted/stored queries for security and performance
- Response Caching: Configurable caching strategies
Generated services are production-ready and include:
- ✅ Successful .NET build and compilation
- ✅ All unit and integration tests pass
- ✅ Docker image builds successfully
- ✅ Service starts and responds to health checks
- ✅ GraphQL schema is valid and queryable
- ✅ Database migrations execute successfully
Validate your generated service:
dotnet build
dotnet test
docker build -t my-service .- .NET gRPC Service - For high-performance RPC communication
- .NET REST Service - For traditional REST APIs
- Python GraphQL Service - Python alternative with FastAPI and Strawberry
- Java GraphQL Gateway - Java-based GraphQL federation 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 thoroughly with all persistence options
This archetype is released under the MIT License. Generated services inherit this license but can be changed as needed for your organization.
Ready to build production-grade GraphQL services with .NET? Generate your first service and start building in minutes! 🚀