Back to Concepts Roadmap
πŸ”₯ Level 12 β€” Architecture & Practices
Architecture

Standard Go Project Layout

Organizing scalable production repositories: cmd, internal, pkg, and api.

Real-World Analogy (Mental Model)

β€œA well-organized bank: public ATM in front lobby (`cmd/`), security vaults and staff-only rooms in the back (`internal/`), shared brochures in reception (`pkg/`).”

Key Concepts & Rules To Remember

  • `cmd/<app-name>/main.go` for application binaries.
  • `internal/` for private domain logic that cannot be imported by external packages.
  • `pkg/` for public reusable libraries.
Step-by-Step Code

1. Understanding Standard Go Project Layout

Organizing scalable production repositories: cmd, internal, pkg, and api. In Go, standard go project layout is designed around clarity and high runtime efficiency.

example.goGo 1.24+
my-service/
β”œβ”€β”€ cmd/server/main.go
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ user/
β”‚   └── order/
└── pkg/apiclient/

Common Beginner Pitfalls & Mistakes

Mistake: Misusing standard go project layout without understanding its memory or concurrency semantics.
βœ… Correct Way: Always follow standard Go idioms and verify with tests.
Self Assessment

Knowledge Check

Verify your understanding with these interactive practice questions.

Quizzes

Quick checks for understanding

Multiple-choice with inline explanationsβ€”expand to see why.

What is the primary concept behind Standard Go Project Layout?

Finished this lesson?

Mark it as complete to track your overall Go mastery.