-
-
Notifications
You must be signed in to change notification settings - Fork 11
Federation
Federation enables cross-repository queries and unified visibility across multiple codebases. Transform CKB from a single-repo tool into an organizational code intelligence platform.
A federation is a named collection of repositories that can be queried together. Instead of analyzing each repo in isolation, federation lets you:
- Search for modules across all your microservices
- Find ownership patterns across the organization
- Identify hotspots spanning multiple repositories
- Track architectural decisions at the org level
# Create a federation
ckb federation create platform --description "Our microservices platform"
# Add repositories
ckb federation add platform --repo-id=api --path=/code/api-service
ckb federation add platform --repo-id=auth --path=/code/auth-service
ckb federation add platform --repo-id=web --path=/code/web-app
# Sync the federation index
ckb federation sync platform
# Check status
ckb federation status platformEach repository in a federation has two identifiers:
| Identifier | Description | Mutable? |
|---|---|---|
| repo_uid | UUID generated on first add | No - permanent |
| repo_id | Human-readable alias | Yes - can rename |
The UUID ensures stable references even if you rename repositories:
# Rename without breaking references
ckb federation rename platform old-api apiWhen you sync a federation, CKB extracts summaries from each repository's database and stores them in a unified index:
- Modules - Name, responsibility, owner, tags
- Ownership - Path patterns and owners
- Hotspots - Top 20 per repo by score
- Decisions - ADRs with status and affected modules
This index enables fast cross-repo queries without opening each database.
Federation requires repositories with schema version 6 or higher. Check compatibility:
ckb federation status platform
# Shows: Compatible: 3/4
# See details
ckb federation repos platform --jsonFor incompatible repos, the fix is:
cd /path/to/repo
ckb refresh --migrateFederation staleness follows "weakest link" semantics - a federation is only as fresh as its stalest repository.
| Level | Meaning |
|---|---|
| fresh | All repos synced within 24 hours |
| aging | Some repos 1-7 days old |
| stale | Some repos 7-30 days old |
| obsolete | Some repos over 30 days old |
Query results include staleness information so you know when to refresh.
ckb federation create <name> [--description "..."]Creates a new federation with the given name. Federations are stored in ~/.ckb/federation/<name>/.
ckb federation delete <name> [--force]Deletes a federation and its index. Use --force to skip confirmation.
ckb federation list [--json]Lists all available federations.
ckb federation status <name> [--json]Shows federation details:
- Name and description
- Creation date
- Number of repositories
- Compatibility status
- Per-repo sync status
ckb federation add <federation> --repo-id=<id> --path=<path> [--tags=tag1,tag2]Adds a repository to the federation. The path must be an absolute path to a CKB-initialized repository.
ckb federation remove <federation> <repo-id>Removes a repository from the federation.
ckb federation rename <federation> <old-id> <new-id>Changes a repository's alias. The UUID remains unchanged.
ckb federation repos <name> [--json]Lists all repositories in a federation with their paths, tags, and add dates.
ckb federation sync <name> [--force] [--dry-run] [--json]Syncs repository data to the federation index:
-
--force- Sync even if data appears fresh -
--dry-run- Preview what would be synced -
--json- Output results as JSON
GET /federations
Returns all available federations.
curl http://localhost:8080/federations{
"federations": ["platform", "infrastructure"],
"count": 2
}GET /federations/:name/status
Returns detailed federation status.
curl http://localhost:8080/federations/platform/status{
"name": "platform",
"description": "Our microservices platform",
"createdAt": "2024-12-18T10:00:00Z",
"repoCount": 4,
"repos": [...],
"compatibility": {
"compatible": 3,
"incompatible": 1
}
}GET /federations/:name/repos[?includeCompatibility=true]
Returns repositories in the federation.
curl http://localhost:8080/federations/platform/repos?includeCompatibility=trueGET /federations/:name/modules?q=<query>&repos=<id1,id2>&tags=<tag1,tag2>&limit=50
Search for modules across all repositories.
# Find all authentication modules
curl "http://localhost:8080/federations/platform/modules?q=auth"
# Search within specific repos
curl "http://localhost:8080/federations/platform/modules?q=handler&repos=api,web"Response includes staleness information:
{
"modules": [
{
"repoId": "api",
"moduleId": "internal/auth",
"name": "auth",
"responsibility": "User authentication and session management",
"ownerRef": "@security-team"
}
],
"total": 1,
"staleness": {
"overallStaleness": "fresh",
"refreshRecommended": false
}
}GET /federations/:name/ownership?path=<glob>&repos=<id1,id2>&limit=50
Search for ownership patterns across repositories.
# Find all API ownership
curl "http://localhost:8080/federations/platform/ownership?path=**/api/**"GET /federations/:name/hotspots?repos=<id1,id2>&top=20&minScore=0.3
Returns merged hotspots across all repositories.
curl "http://localhost:8080/federations/platform/hotspots?top=10"GET /federations/:name/decisions?q=<query>&status=accepted&repos=<id1,id2>&module=<module>&limit=50
Search for architectural decisions (ADRs) across repositories.
# Find all accepted authentication decisions
curl "http://localhost:8080/federations/platform/decisions?q=authentication&status=accepted"POST /federations/:name/sync
Content-Type: application/json
{
"force": false,
"dryRun": false,
"repoIds": ["api", "auth"] // optional, default: all
}
Syncs repository data to the federation index.
curl -X POST http://localhost:8080/federations/platform/sync \
-H "Content-Type: application/json" \
-d '{"force": true}'Federation adds 8 new MCP tools for AI assistant integration.
List all available federations.
{
"name": "listFederations",
"arguments": {}
}Get detailed status of a federation.
{
"name": "federationStatus",
"arguments": {
"federation": "platform"
}
}List repositories in a federation.
{
"name": "federationRepos",
"arguments": {
"federation": "platform",
"includeCompatibility": true
}
}Search for modules across all repositories.
{
"name": "federationSearchModules",
"arguments": {
"federation": "platform",
"query": "authentication",
"repos": ["api", "auth"],
"limit": 20
}
}Search for ownership patterns across repositories.
{
"name": "federationSearchOwnership",
"arguments": {
"federation": "platform",
"path": "**/api/**",
"limit": 50
}
}Get merged hotspots across all repositories.
{
"name": "federationGetHotspots",
"arguments": {
"federation": "platform",
"top": 20,
"minScore": 0.3
}
}Search for architectural decisions across repositories.
{
"name": "federationSearchDecisions",
"arguments": {
"federation": "platform",
"query": "database",
"status": ["accepted"],
"module": "persistence"
}
}Sync federation index from repository data.
{
"name": "federationSync",
"arguments": {
"federation": "platform",
"force": true,
"dryRun": false,
"repos": ["api"]
}
}Federation data is stored in ~/.ckb/federation/<name>/:
~/.ckb/federation/
└── platform/
├── config.toml # Federation configuration
└── index.db # SQLite index database
name = "platform"
description = "Our microservices platform"
created_at = "2024-12-18T10:00:00Z"
updated_at = "2024-12-18T14:30:00Z"
[[repos]]
repo_uid = "550e8400-e29b-41d4-a716-446655440001"
repo_id = "api"
path = "/code/api-service"
tags = ["backend", "core"]
added_at = "2024-12-18T10:05:00Z"
[[repos]]
repo_uid = "550e8400-e29b-41d4-a716-446655440002"
repo_id = "auth"
path = "/code/auth-service"
tags = ["backend", "security"]
added_at = "2024-12-18T10:06:00Z"Find all "authentication" modules across your organization:
# CLI
ckb federation sync platform
# Then use HTTP/MCP to search
# HTTP
curl "http://localhost:8080/federations/platform/modules?q=auth"Identify the most volatile code across all services:
curl "http://localhost:8080/federations/platform/hotspots?top=20"Find who owns API code across the organization:
curl "http://localhost:8080/federations/platform/ownership?path=**/api/**"Find all decisions related to databases:
curl "http://localhost:8080/federations/platform/decisions?q=database&status=accepted"When reviewing changes that span multiple repositories:
User: "Who should review changes to the auth system?"
AI (using federationSearchOwnership):
Based on the federation data:
- api-service: @security-team, @api-team
- auth-service: @security-team (primary), @platform-team
- web-app: @frontend-team (for auth UI)
Recommended reviewers: @security-team (owns auth across all repos)
Run sync regularly or after significant changes:
# In CI/CD after deployment
ckb federation sync platformTag repositories by domain for focused queries:
ckb federation add platform --repo-id=api --path=/code/api --tags=backend,core
ckb federation add platform --repo-id=web --path=/code/web --tags=frontendThen filter:
curl "http://localhost:8080/federations/platform/modules?tags=backend"Always check staleness in query results:
result = query_federation_modules("platform", "auth")
if result["staleness"]["refreshRecommended"]:
sync_federation("platform")
result = query_federation_modules("platform", "auth")Before critical operations, verify all repos are compatible:
ckb federation status platform
# Ensure Compatible: N/NUse consistent, descriptive repo IDs:
# Good
--repo-id=user-api
--repo-id=payment-service
--repo-id=admin-dashboard
# Avoid
--repo-id=repo1
--repo-id=backend
--repo-id=newWarning: Schema version 2 is below minimum 6
Action: Run: cd /path/to/repo && ckb refresh --migrate
Run the suggested command to upgrade the schema.
REPO ID STATUS MODULES OWNERSHIP HOTSPOTS DECISIONS DURATION
api skipped 0 0 0 0 0ms
Check repo compatibility:
ckb federation repos platform --json | jq '.compatibility'Error: federation "platform" not found
List available federations:
ckb federation listError: path does not exist: /code/old-location
Update the repo path or remove and re-add:
ckb federation remove platform old-api
ckb federation add platform --repo-id=api --path=/code/new-location- Local only - Federation currently works with local filesystem paths only
- Schema v6+ - Requires all repos to have CKB schema version 6 or higher
- Manual sync - Index must be explicitly synced (no automatic watching)
- No cross-repo symbols - Symbol navigation stays within a single repo
- Top 20 hotspots - Only top 20 hotspots per repo are indexed
- Cross-repo dependency tracking
- Remote federation (HTTPS endpoints)
- Team dashboards
- Automatic sync triggers
- Symbol resolution across repos