This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
infrahub-ops-cli is a Go-based toolset for managing and maintaining Infrahub instances. The project provides three specialized CLI binaries:
- infrahub-backup - Backup/restore operations and environment detection
- infrahub-taskmanager - Task manager (Prefect) maintenance operations
- infrahub-collect - Troubleshooting-bundle collection (read-only diagnostics) for support
All three tools share common internal application logic but expose different commands through their respective main entry points.
make build- Build all three binaries tobin/infrahub-backup,bin/infrahub-taskmanager, andbin/infrahub-collectmake build-all- Cross-compile all three binaries for Linux, Darwin, and Windows (amd64/arm64)make install- Build and install all three binaries to$GOPATH/binmake clean- Remove build artifacts
make test- Run all testsmake test-coverage- Generate coverage report (outputs coverage.html)make lint- Run golangci-lint (note: errcheck is disabled in .golangci.yaml)make fmt- Format code with go fmtmake vet- Run go vet
make dev-setup- Install development dependencies including golangci-lintmake deps- Download and tidy dependenciesmake deps-update- Update all dependencies
The changelog is assembled by towncrier from news fragments in
changelog/, so changes included in release notes carry their own entries instead of editing
CHANGELOG.md. The changelog covers only the product itself: the three binaries and the
container image. Never add a fragment for a change that does not affect the product, such as a CI
or release workflow, tests, linters, or other repository tooling; label those PRs
ci/skip-changelog instead. Internal work that changes the product goes under housekeeping.
The pull-request fragment check is currently muted, in line with the other ecosystem repositories.
Add a fragment in the same PR as the change when it belongs in the release notes:
uv run towncrier create -c "Fixed the thing" 42.fixed.md- one fragment per change, named<issue>.<type>.md. Without an issue or PR number, use a descriptive slug prefixed with+, e.g.+retention-dry-run.added.md.- Types:
security,removed,deprecated,added,changed,fixed,housekeeping. uv run towncrier build --draft --version X.Y.Z- preview the rendered changelog.- Run
auto-bump.ymlonmainto prepare a release pull request. It assemblesCHANGELOG.mdfrom the fragments and uses the latest Git tag, not the helperpyproject.tomlversion, to choose the next release version. - Review and merge the release pull request to publish.
release-publish.ymlcreates the GitHub Release, which starts the existing binary, image, and Homebrew publishing workflow.
Whenever Go modules change (any modification to go.mod or go.sum — adding, removing, or updating dependencies), ALWAYS run scripts/update-vendor-hash.sh to update the vendorHash in flake.nix. Do not compute or edit the vendor hash manually.
The codebase follows a command-pattern architecture using Cobra for CLI structure, with three separate binary entry points sharing common internal logic:
-
src/cmd/infrahub-backup/main.go - Backup tool entry point
- Defines root command with backup/restore subcommands
- Commands:
create,restore,environment detect,environment list,version - Uses shared application logic from
src/internal/app
-
src/cmd/infrahub-taskmanager/main.go - Task manager tool entry point
- Defines root command with task management subcommands
- Commands:
flush flow-runs,flush stale-runs,environment detect,environment list,version - Uses shared application logic from
src/internal/app
-
src/cmd/infrahub-collect/main.go - Troubleshooting-bundle tool entry point
- Defines root command with troubleshooting-bundle collection
- Commands:
create,environment detect,environment list,version - Uses shared application logic from
src/internal/app
-
src/internal/app/app.go - Core application logic
InfrahubOpsstruct - Main application controllerCommandExecutor- Handles Docker Compose and system command execution- Environment detection (Docker vs Kubernetes)
- Docker project discovery and validation
- Shared by all three CLI tools
-
src/internal/app/backup.go - Backup and restore operations
- Creates tar.gz backups with metadata JSON
- Backs up Neo4j database, PostgreSQL (task-manager), and artifacts
- Implements safe backup with container stopping/starting
- Restore validates metadata and handles version compatibility
-
src/internal/app/taskmanager.go - Task management operations
- PostgreSQL database connection management
- Flow run cleanup operations (completed/failed/cancelled)
- Stale run cancellation (stuck in running state)
- Uses embedded Python scripts for Prefect API operations
-
src/internal/app/collect.go* - Troubleshooting-bundle collection
collect.go- Orchestrator (CollectBundle), collector run plan, staging/archive lifecyclecollect_manifest.go-bundle_information.jsonmanifest and per-collector resultscollect_logs.go- Per-replica service log collector (backend-agnostic)collect_diagnostics.go- Database, message-queue, cache, task-worker, task-manager, and server collectorscollect_metrics.go- Container resource metrics collectorcollect_extras.go- Opt-in--include-backupand--benchmarkcollectorsmasking.go- Key-name secret masking for env and config dumps
-
src/internal/app/utils.go - Utility functions
- File operations, checksum validation
- Environment variable handling
- Version detection and comparison
-
src/internal/app/cli.go - Shared CLI configuration
ConfigureRootCommand()- Sets up common flags and configurationAttachEnvironmentCommands()- Adds environment detection commands- Shared between all three binaries
- Split Binary Architecture: Three specialized binaries sharing common internal logic for focused functionality
- Embedded Scripts: Python scripts are embedded using Go's embed package (src/internal/app/scripts directory)
- Docker Compose Integration: All operations work through Docker Compose commands
- Project-based Operations: Can target specific Docker Compose projects with
--projectflag - Streaming Output: Commands stream output in real-time for user feedback
- Shared Configuration: All binaries use the same configuration system and environment variables
All tools assume Infrahub is deployed using Docker Compose with these service names:
database(Neo4j) - Used by infrahub-backup and infrahub-collecttask-manager-db(PostgreSQL) - Used by infrahub-backup and infrahub-taskmanagerinfrahub-server,task-worker,task-manager,task-manager-background-svc- Application containerscache,message-queue- Infrastructure services
The codebase uses explicit error wrapping with fmt.Errorf for context. All commands return errors up to the Cobra command handlers which handle display to users.
Documentation Purpose:
- Guide users through installing, configuring, and using Infrahub in real-world workflows
- Explain concepts and system architecture clearly, including new paradigms introduced by Infrahub
- Support troubleshooting and advanced use cases with actionable, well-organized content
- Enable adoption by offering approachable examples and hands-on guides that lower the learning curve
Structure: Follows Diataxis framework
- Tutorials (learning-oriented)
- How-to guides (task-oriented)
- Explanation (understanding-oriented)
- Reference (information-oriented)
Tone and Style:
- Professional but approachable: Avoid jargon unless well defined. Use plain language with technical precision
- Concise and direct: Prefer short, active sentences. Reduce fluff
- Informative over promotional: Focus on explaining how and why, not on marketing
- Consistent and structured: Follow a predictable pattern across sections and documents
For Guides:
- Use conditional imperatives: "If you want X, do Y. To achieve W, do Z."
- Focus on practical tasks and problems, not the tools themselves
- Address the user directly using imperative verbs: "Configure...", "Create...", "Deploy..."
- Maintain focus on the specific goal without digressing into explanations
- Use clear titles that state exactly what the guide shows how to accomplish
For Topics:
- Use a more discursive, reflective tone that invites understanding
- Include context, background, and rationale behind design decisions
- Make connections between concepts and to users' existing knowledge
- Present alternative perspectives and approaches where appropriate
- Use illustrative analogies and examples to deepen understanding
Terminology and Naming:
- Always define new terms when first used. Use callouts or glossary links if possible
- Prefer domain-relevant language that reflects the user's perspective (e.g., playbooks, branches, schemas, commits)
- Be consistent: follow naming conventions established by Infrahub's data model and UI
Reference Files:
- Documentation guidelines:
docs/docs/development/docs.mdx - Vale styles:
.vale/styles/ - Markdown linting:
[tool.rumdl]inpyproject.toml
How-to Guides Structure (Task-oriented, practical steps):
- Title and Metadata
- Title should clearly state what problem is being solved (YAML frontmatter)
- Begin with "How to..." to signal the guide's purpose
- Optional: Imports for components (e.g., Tabs, TabItem, CodeBlock, VideoPlayer)
- Introduction
- Brief statement of the specific problem or goal this guide addresses
- Context or real-world use case that frames the guide
- Clearly indicate what the user will achieve by following this guide
- Optional: Links to related topics or more detailed documentation
- Prerequisites / Assumptions
- What the user should have or know before starting
- Environment setup or requirements
- What prior knowledge is assumed
- Step-by-Step Instructions
- Step 1: [Action/Goal]
- Clear, actionable instructions focused on the task
- Code snippets (YAML, GraphQL, shell commands, etc.)
- Screenshots or images for visual guidance
- Tabs for alternative methods (e.g., Web UI, GraphQL, Shell/cURL)
- Notes, tips, or warnings as callouts
- Step 2: [Action/Goal]
- Repeat structure as above for each step
- Step N: [Action/Goal]
- Continue as needed
- Validation / Verification
- How to check that the solution worked as expected
- Example outputs or screenshots
- Potential failure points and how to address them
- Advanced Usage / Variations
- Optional: Alternative approaches for different circumstances
- Optional: How to adapt the solution for related problems
- Optional: Ways to extend or optimize the solution
- Related Resources
- Links to related guides, reference materials, or explanation topics
- Optional: Embedded videos or labs for further learningTopics Structure (Understanding-oriented, theoretical knowledge):
- Title and Metadata
- Title should clearly indicate the topic being explained (YAML frontmatter)
- Consider using "About..." or "Understanding..." in the title
- Optional: Imports for components (e.g., Tabs, TabItem, CodeBlock, VideoPlayer)
- Introduction
- Brief overview of what this explanation covers
- Why this topic matters in the context of Infrahub
- Questions this explanation will answer
- Main Content Sections
- Concepts & Definitions
- Clear explanations of key terms and concepts
- How these concepts fit into the broader system
- Background & Context
- Historical context or evolution of the concept/feature
- Design decisions and rationale behind implementations
- Technical constraints or considerations
- Architecture & Design (if applicable)
- Diagrams, images, or explanations of structure
- How components interact or relate to each other
- Mental Models
- Analogies and comparisons to help understanding
- Different ways to think about the topic
- Connection to Other Concepts
- How this topic relates to other parts of Infrahub
- Integration points and relationships
- Alternative Approaches
- Different perspectives or methodologies
- Pros and cons of different approaches
- Further Reading
- Links to related topics, guides, or reference materials
- External resources for deeper understandingGeneral Documentation:
- Content is accurate and reflects the latest version of Infrahub
- Instructions are clear, with step-by-step guidance where needed
- Markdown formatting is correct and compliant with Infrahub's style
- Spelling and grammar are checked with Vale
- Vale style checks pass: Run
vale $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \) -not -path "./docs/node_modules/*")and address all issues
For Guides:
- The guide addresses a specific, practical problem or task
- The title clearly indicates what will be accomplished
- Steps follow a logical sequence that maintains flow
- Each step focuses on actions, not explanations
- The guide omits unnecessary details that don't serve the goal
- Validation steps help users confirm their success
- The guide addresses real-world complexity rather than oversimplified scenarios
For Topics:
- The explanation is bounded to a specific topic area
- Content provides genuine understanding, not just facts
- Background and context are included to deepen understanding
- Connections are made to related concepts and the bigger picture
- Different perspectives or approaches are acknowledged where relevant
- The content remains focused on explanation without drifting into tutorial or reference material
- The explanation answers "why" questions, not just "what" or "how"
- Go 1.25.0 + kloset v1.0.13 (Plakar core), integration-fs (storage), cobra, logrus, viper (002-plakar-integration)
- Plakar repository (local filesystem or S3 via integration backends) (002-plakar-integration)
- Go 1.25.0 + cobra, viper, logrus; Docker/Kubernetes via
docker/kubectlCLI shell-out throughCommandExecutor— no client-go or Docker SDK (003-collect-tool) - Local filesystem bundle output under
--output-dir(default./infrahub_bundles); no network egress beyond the target deployment (003-collect-tool)
- 003-collect-tool: Added
infrahub-collecttroubleshooting-bundle binary (collector framework, log/metrics primitives on both backends, key-name secret masking, bundle manifest) - 002-plakar-integration: Added kloset (Plakar core library), integration-fs (filesystem storage/exporter), cobra, logrus