Domains
Domains are logical groupings of packages with shared coverage requirements. They allow you to enforce different coverage thresholds for different parts of your codebase.
Domain Configuration
Section titled “Domain Configuration”Each domain has a name, match patterns, and a minimum coverage threshold:
policy: domains: - name: core match: ["./internal/core/..."] min: 85 - name: api match: ["./internal/api/..."] min: 80Match Patterns
Section titled “Match Patterns”Match patterns use Go’s package path syntax:
| Pattern | Matches |
|---|---|
./internal/core/... | All packages under internal/core/ |
./cmd/... | All packages under cmd/ |
./pkg/utils | Only the pkg/utils package |
./internal/*/service | service packages one level deep |
Examples
Section titled “Examples”domains: # Match all subpackages - name: core match: ["./internal/core/..."] min: 85
# Match multiple paths - name: api match: - "./internal/api/..." - "./internal/handlers/..." min: 80
# Match specific packages - name: utils match: - "./pkg/utils" - "./pkg/helpers" min: 70Excluding Files
Section titled “Excluding Files”Use the exclude field to skip files from coverage analysis:
exclude: - "**/generated/**" - "**/mocks/**" - "**/*_test.go" - "**/testdata/**"Glob Patterns
Section titled “Glob Patterns”| Pattern | Matches |
|---|---|
**/generated/** | Any file under a generated directory |
**/*_mock.go | Any file ending in _mock.go |
internal/legacy/* | Files directly in internal/legacy/ |
Auto-Detection
Section titled “Auto-Detection”coverctl can automatically detect domains from your project structure:
# Preview detected domainscoverctl detect --dry-run
# Write configcoverctl detectDetection Rules
Section titled “Detection Rules”| Directory | Detected Domain |
|---|---|
cmd/ | CLI entry points |
internal/core/ | Core business logic |
internal/domain/ | Domain layer |
internal/application/ | Application services |
internal/infrastructure/ | Infrastructure adapters |
internal/api/ | API layer |
pkg/ | Public packages |
Directories named generated, mocks, testdata, or vendor are automatically excluded.
Domain Overlap
Section titled “Domain Overlap”When a file matches multiple domains, it’s assigned to the first matching domain. Order your domains from most specific to least specific:
domains: # More specific first - name: core-critical match: ["./internal/core/critical/..."] min: 95
# Less specific second - name: core match: ["./internal/core/..."] min: 85Code Annotations
Section titled “Code Annotations”With annotations.enabled: true, you can override domain assignment in code:
// coverctl:domain=criticalpackage validator
func Validate() error { // This file belongs to "critical" domain}Ignoring Files
Section titled “Ignoring Files”// coverctl:ignorepackage generated
// This file is excluded from coverageBest Practices
Section titled “Best Practices”- Start with auto-detection: Use
coverctl detect --dry-runto see suggested domains - Group by criticality: Higher thresholds for core business logic
- Use meaningful names: Domain names appear in reports
- Keep excludes minimal: Only exclude truly non-testable code
- Review overlaps: Check for unintended domain assignments