Project Structure for Gos
Project structure in Go is how code is organised into modules and packages. A go.mod file defines the module and its dependencies, packages group related code, and internal directories limit imports. Configuration is read from environment variables or files, and structured logging with log/slog records events consistently.
Stage: Production Go · Part of the Go roadmap · Last reviewed 19 November 2026
What to learn in Project Structure
- Initialise a module and add dependencies with go mod tidy
- Organise packages with cmd and internal directories
- Load configuration from environment variables with defaults
- Log structured key-value records using log/slog
- Explain what a package-level init function does and why to avoid it
Project Structure interview questions
What does the internal directory do in Go?
Packages inside an internal directory can only be imported by code rooted at the parent of that directory. It lets you share code within your module while stopping outside modules from depending on it, keeping your public API small.
What does go mod tidy do?
It scans your code and adds missing module requirements while removing ones no longer used, updating go.mod and go.sum. Running it keeps the dependency list accurate and the build reproducible.
Where Project Structure fits in the Go roadmap
Project Structure belongs to the Production Go stage (advanced level), which takes about 20 hours. Run it well.