go-cli-application-architecture
Design and review maintainable Go CLI application boundaries, package layout, dependency direction, command factories, configuration ownership, adapters, services, storage, and composition roots. Use when starting a multi-command CLI, extracting business logic from Cobra, untangling globals, adding external dependencies, or deciding what belongs under cmd, internal, or reusable packages.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 1.6k
- Forks
- 491
01 前言 Front Matter
- name
- go-cli-application-architecture
- license
- MIT
- metadata
- { "tags": "go,golang,cli,architecture,packages,dependency-injection", "version": "0.3.0", "category": "Go", "displayName": "Go CLI Application Architecture" }
- description
- Design and review maintainable Go CLI application boundaries, package layout, dependency direction, command factories, configuration ownership, adapters, services, storage, and composition roots. Use when starting a multi-command CLI, extracting business logic from Cobra, untangling globals, adding external dependencies, or deciding what belongs under cmd, internal, or reusable packages.
- compatibility
- Codex, Claude Code, and other Agent Skills-compatible clients.
02 资源文件 7
- 参考文档agents/openai.yaml240 B
- 参考文档guidelines.md2.0 KB
- 参考文档references/application-architecture/examples.md1.7 KB
- 参考文档references/application-architecture/knowledge.md3.3 KB
- 参考文档references/application-architecture/rules.md2.6 KB
- 参考文档workflows/design-application-boundaries.md1.5 KB
- 参考文档workflows/review-resource-lifecycle.md1.6 KB
03 SKILL.md 正文
Go CLI Application Architecture
Organize around dependency direction and testable behavior, not a copied folder template. Keep CLI framework code as an adapter around application services.
Core Workflow
- Identify commands, domain actions, external effects, and shared policies.
- Separate parsing/rendering from application orchestration and adapters.
- Define interfaces at the consumer that needs substitution.
- Construct dependencies once in a composition root and pass them explicitly.
- Keep configuration immutable after validation; give mutable state a dedicated store.
- Record ownership and cleanup for every acquired resource and background task.
- Test inward from pure logic to adapters and one assembled executable path.
Read Next
| Task | Load |
|---|---|
| Design or refactor boundaries | guidelines.md, workflows/design-application-boundaries.md |
| Review ownership and cleanup | workflows/review-resource-lifecycle.md |
| Decide package and interface placement | references/application-architecture/rules.md |
| Review patterns and examples | references/application-architecture/examples.md |
| Understand dependency direction | references/application-architecture/knowledge.md |
Guardrails
- Do not put domain behavior in Cobra
Runfunctions. - Avoid a central interfaces package and broad catch-all service abstractions.
- Do not use package globals or
initfor dependency construction. - Keep fallible I/O and order-dependent startup out of
init; use explicit composition. - Keep runtime configuration distinct from mutable application storage.
- Add layers only when they create a real seam, invariant, or dependency boundary.
Source Notes
Guidance is transformed and paraphrased from Marian Montagnino, Building Modern CLI Applications in Go (Packt, 2023), especially Chapters 2-3, with original adaptations aligned to current Go conventions.
Concrete-first interfaces, dependency ownership, and adapter lifecycle guidance also incorporates transformed material from Inanc Gumus, Go by Example: Programmer's Guide to Idiomatic and Testable Programs (Manning, 2025), Chapters 5 and 8-10.
Initialization and lifecycle guidance also incorporates transformed material from Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022), Chapters 2, 6, 7, and 10.
04 同仓库更多 Skills
worktable-review-with-annotations
Create, inspect, reply to, update, or resolve situated Worktable annotations. Use when feedback belongs to a Doc section, block, text range, or HTML Doc, or when the user asks to address existing review feedback and coordinate a requested artifact edit.
worktable-find-and-synthesize-context
Find, assess, and synthesize context from Worktable Docs and Records. Use when the user asks what a workspace contains, wants workspace-backed research, needs current facts reconciled across artifacts, or requests a cited synthesis without changing workspace state.
worktable-create-or-update-docs
Create, edit, rename, or maintain narrative Worktable Docs. Use for plans, decisions, briefs, notes, research syntheses, and other durable prose when the user requests a new artifact or a safe update to an existing one.
worktable-create-or-manage-records
Organize repeated structured information as durable Worktable Records. Use for research datasets, inventories, directories, pipelines, trackers, and other collections whose items need identity, fields, filtering, links, validation, or individual updates.
worktable-create-or-manage-interactive-html
Create or improve durable visual and interactive artifacts in Worktable. Use for dashboards, trackers, calculators, mini apps, slide presentations, and other requests that benefit from a polished HTML Doc.
worktable-collaborate-threads
Read, answer, and hand off messages through durable Worktable threads with users or other authenticated participants. Use when the user asks to check addressed messages, reply to a participant, continue a thread, request another agent's help, wait briefly for a response, or watch for comments and messages sent to the agent.