golang-project-layout

Guides Go project structure, module naming, and workspace setup for new codebases.

Updated Jun 15, 2026
One-click install
npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-project-layout-2877389577
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-project-layout
Source: https://github.com/2877389577/novels_ai_gen/tree/main/.agents/skills/golang-project-layout
Command: npx skills add https://github.com/2877389577/novels_ai_gen --skill golang-project-layout-2877389577

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve? Starting or reorganizing a Go project often leads to inconsistent directory structures, misplaced business logic, and poor module naming. This Skill provides opinionated, convention-based guidance for structuring Go projects correctly from day one. ## Core Features & Use Cases - Project Type Layouts: Provides directory templates for CLI tools, libraries, services, and monorepos, with clear rules for cmd/, internal/, and pkg/ placement. - Module & Package Naming: Enforces Go conventions such as lowercase module paths matching repository URLs and hyphenated multi-word names. - Workspaces & Testing Layout: Covers go.work setup for multi-module monorepos and co-located test file organization with testdata fixtures. - Use Case: When scaffolding a new Go microservice, the Skill asks about your preferred architecture and DI approach, then generates a right-sized structure with cmd/server, internal/, a Makefile, and .gitignore. ## Quick Start Ask the agent to set up the directory structure for a new Go project and answer its questions about architecture and dependency injection preferences.

Frequently Asked Questions about golang-project-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure a new Go project directory?▼

Place all main packages under cmd/{name}/ with minimal logic, put private code in internal/, and use pkg/ only for code intended for external consumers. Add a Makefile, .gitignore, and .golangci.yml at the root, and right-size the structure to the project's actual scope.

What is the difference between internal and pkg directories in Go?▼

The internal/ directory holds private code that Go's compiler prevents external modules from importing. The pkg/ directory is for public libraries genuinely useful to external consumers; default to internal/ for service and business logic.

When should I use go.work workspaces in Go?▼

Use go.work when developing multiple related Go modules that import each other, such as a monorepo with separate modules. Do not use workspaces for single-module projects, even ones with many packages.

Where should main.go go in a Go project?▼

Each main package belongs in its own subdirectory under cmd/, such as cmd/server/main.go. The main.go should only parse flags, wire dependencies, and call Run(); business logic belongs in internal/ or pkg/.

Should I put secrets in a Viper config.yaml file?▼

No. Sensitive values like database passwords, API keys, and JWT secrets must come from environment variables or a secret manager, never config files. Config files are acceptable only for non-sensitive values like ports and log levels.

Where do Go test files go in a project?▼

Co-locate _test.go files in the same directory as the code they test, using either the same package for white-box tests or a _test package suffix for black-box tests. Use a testdata/ directory for fixtures, which Go ignores during builds.