name: design-repository-layout
description: Use when creating a new repository, or when an existing repo's root is cluttered or confusing — newcomers can't find how to build, run, test, or contribute; config files, scripts, and docs are scattered; or source and tooling are mixed at the top level.
source: 'GitHub Docs, "About community profiles for public repositories" and "About code owners"; Python Packaging Authority, "src layout vs flat layout", Python Packaging User Guide; Go Team, "Organizing a Go module", go.dev/doc/modules/layout, 2023; Wiggins, "The Twelve-Factor App", 2011; Lacan, "Keep a Changelog"; EditorConfig.org'
tags: [project-structure, repository-layout, onboarding, developer-experience, documentation, conventions]
related: [design-backend-project-structure, design-frontend-project-structure, design-monorepo-structure, apply-convention-over-configuration, write-changelog]
Design Repository Layout
Give every repository a predictable top level: a clear entry point for humans (README), one obvious place each for source, tests, docs, scripts, and CI, and a single command to build, test, and run.
Why This Is Best Practice
Adopted by:
- GitHub's community-profile checklist (README, LICENSE, CONTRIBUTING, CODE_OF_CONDUCT, SECURITY, issue/PR templates).
- The official layout guidance of language ecosystems: the Go team's "Organizing a Go module", the PyPA's src layout, Maven's Standard Directory Layout, and Cargo's conventions.
- Large open-source foundations (CNCF, Apache), which require these files for project graduation.
Impact:
- A conventional layout cuts onboarding time: contributors and tools (IDEs, CI, package managers, security scanners) find things without project-specific knowledge.
- The PyPA recommends the src layout specifically because it prevents tests from accidentally importing the uninstalled local copy, a common class of "works on my machine" bug.
Why best:
- Every repo has the same questions: what is this, how do I run it, how do I contribute, who owns it.
- Answering them with standard file names in standard places means zero lookup cost. Custom layouts force every reader to reverse-engineer the project.
Sources: GitHub Docs (community profiles, CODEOWNERS). PyPA Packaging User Guide, "src layout vs flat layout". Go Team (2023), "Organizing a Go module". Maven, "Introduction to the Standard Directory Layout". Wiggins, A. (2011), The Twelve-Factor App.
Steps
Start from the language or framework's official layout. Generate with the official scaffolder (cargo new, go mod init, uv init --package, npm create vite, Spring Initializr, dotnet new). Deviate only with a reason.
Use a standard top level. Include only what applies:
.github/ # CI workflows, issue/PR templates, CODEOWNERS, dependabot
docs/ # architecture, ADRs (docs/adr/), runbooks, guides
scripts/ # dev/ops scripts (bootstrap, seed, release)
src/ | cmd/ | app/ # source (per ecosystem convention)
tests/ # if the ecosystem doesn't colocate tests
deploy/ | infra/ # Dockerfile(s), Helm/k8s, Terraform (or a separate repo)
.editorconfig
.gitignore
.env.example # documented config keys, never real secrets
Makefile | justfile | package.json scripts | Taskfile.yml
README.md
CONTRIBUTING.md
CHANGELOG.md
LICENSE
SECURITY.md
Write the README as the front door. In this order:
- one-line purpose
- quick start (clone, install, run in 3 commands or fewer)
- how to test
- configuration
- project layout map (a short tree with one line per folder)
- links to docs, CONTRIBUTING, and the license
Provide one task runner with standard verbs: make setup, make dev, make test, make lint, make build. CI calls the same targets, so local and CI behavior match.
Keep config out of code and secrets out of git. Read config from the environment (Twelve-Factor III). Commit .env.example with every key documented. Add .env to .gitignore. Scan for secrets in CI (gitleaks, GitHub secret scanning).
Declare ownership and quality gates:
CODEOWNERS for review routing.
- Pinned tool versions (
.tool-versions, .nvmrc, rust-toolchain.toml, go.mod toolchain).
- Lockfiles committed for applications.
- Formatter and linter config at the root, enforced by pre-commit hooks and CI.
Record decisions. Keep architecture decision records in docs/adr/ (see write-adr) and a CHANGELOG following Keep a Changelog (see write-changelog).
Keep the root lean. Move tool configs into package.json/pyproject.toml where supported. Group generated output under ignored folders (dist/, build/, target/, coverage/).
Rules
- A newcomer can go from clone to running tests using only the README.
- One canonical command per task, used by both humans and CI.
- No secrets, build artifacts, or IDE-specific files in git.
- Follow the ecosystem's convention before inventing your own.
- Every top-level folder has a one-line explanation in the README layout map.
Common Mistakes
- README that only says the project name. Readers can't run anything.
- Copying the unofficial "golang-standards/project-layout". The Go team has said it isn't an official standard. Use go.dev's module layout guide and add
pkg/ or internal/ only as needed.
- Committed
.env files. Leaked credentials. Rotate immediately and purge from history.
- Scripts with hidden prerequisites. Pin versions and document requirements in
setup.
- Twenty dotfiles at the root. Consolidate configs where the tools allow.
Examples
Python service: src/myservice/, tests/, pyproject.toml (deps, ruff, pytest config), uv.lock, Makefile with setup/dev/test/lint, .env.example, docs/adr/0001-use-postgres.md, .github/workflows/ci.yml calling make lint test.
Go CLI: go.mod, main.go at the root for a single binary (or cmd/<name>/main.go for several), internal/ for private packages, README.md with an install line (go install …@latest).
When NOT to Use
- Throwaway scripts and gists. A README line is enough.
- Repos governed by an organizational template. Follow the template and propose changes upstream.
1---2name: design-repository-layout3description: Use when creating a new repository, or when an existing repo's root is cluttered or confusing — newcomers can't find how to build, run, test, or contribute; con4---5---6name: design-repository-layout7description: Use when creating a new repository, or when an existing repo's root is cluttered or confusing — newcomers can't find how to build, run, test, or contribute; config files, scripts, and docs are scattered; or source and tooling are mixed at the top level.8source: 'GitHub Docs, "About community profiles for public repositories" and "About code owners"; Python Packaging Authority, "src layout vs flat layout", Python Packaging User Guide; Go Team, "Organizing a Go module", go.dev/doc/modules/layout, 2023; Wiggins, "The Twelve-Factor App", 2011; Lacan, "Keep a Changelog"; EditorConfig.org'9tags: [project-structure, repository-layout, onboarding, developer-experience, documentation, conventions]10related: [design-backend-project-structure, design-frontend-project-structure, design-monorepo-structure, apply-convention-over-configuration, write-changelog]11---1213# Design Repository Layout1415Give every repository a predictable top level: a clear entry point for humans (README), one obvious place each for source, tests, docs, scripts, and CI, and a single command to build, test, and run.1617## Why This Is Best Practice1819**Adopted by:**20- GitHub's community-profile checklist (README, LICENSE, CONTRIBUTING, CODE_OF_CONDUCT, SECURITY, issue/PR templates).21- The official layout guidance of language ecosystems: the Go team's "Organizing a Go module", the PyPA's src layout, Maven's Standard Directory Layout, and Cargo's conventions.22- Large open-source foundations (CNCF, Apache), which require these files for project graduation.2324**Impact:**25- A conventional layout cuts onboarding time: contributors and tools (IDEs, CI, package managers, security scanners) find things without project-specific knowledge.26- The PyPA recommends the src layout specifically because it prevents tests from accidentally importing the uninstalled local copy, a common class of "works on my machine" bug.2728**Why best:**29- Every repo has the same questions: what is this, how do I run it, how do I contribute, who owns it.30- Answering them with standard file names in standard places means zero lookup cost. Custom layouts force every reader to reverse-engineer the project.3132Sources: GitHub Docs (community profiles, CODEOWNERS). PyPA Packaging User Guide, "src layout vs flat layout". Go Team (2023), "Organizing a Go module". Maven, "Introduction to the Standard Directory Layout". Wiggins, A. (2011), *The Twelve-Factor App*.3334## Steps35361. **Start from the language or framework's official layout.** Generate with the official scaffolder (`cargo new`, `go mod init`, `uv init --package`, `npm create vite`, Spring Initializr, `dotnet new`). Deviate only with a reason.37382. **Use a standard top level.** Include only what applies:39 ```40 .github/ # CI workflows, issue/PR templates, CODEOWNERS, dependabot41 docs/ # architecture, ADRs (docs/adr/), runbooks, guides42 scripts/ # dev/ops scripts (bootstrap, seed, release)43 src/ | cmd/ | app/ # source (per ecosystem convention)44 tests/ # if the ecosystem doesn't colocate tests45 deploy/ | infra/ # Dockerfile(s), Helm/k8s, Terraform (or a separate repo)46 .editorconfig47 .gitignore48 .env.example # documented config keys, never real secrets49 Makefile | justfile | package.json scripts | Taskfile.yml50 README.md51 CONTRIBUTING.md52 CHANGELOG.md53 LICENSE54 SECURITY.md55 ```56573. **Write the README as the front door.** In this order:58 - one-line purpose59 - quick start (clone, install, run in 3 commands or fewer)60 - how to test61 - configuration62 - project layout map (a short tree with one line per folder)63 - links to docs, CONTRIBUTING, and the license64654. **Provide one task runner** with standard verbs: `make setup`, `make dev`, `make test`, `make lint`, `make build`. CI calls the same targets, so local and CI behavior match.66675. **Keep config out of code and secrets out of git.** Read config from the environment (Twelve-Factor III). Commit `.env.example` with every key documented. Add `.env` to `.gitignore`. Scan for secrets in CI (gitleaks, GitHub secret scanning).68696. **Declare ownership and quality gates:**70 - `CODEOWNERS` for review routing.71 - Pinned tool versions (`.tool-versions`, `.nvmrc`, `rust-toolchain.toml`, `go.mod` toolchain).72 - Lockfiles committed for applications.73 - Formatter and linter config at the root, enforced by pre-commit hooks and CI.74757. **Record decisions.** Keep architecture decision records in `docs/adr/` (see `write-adr`) and a CHANGELOG following Keep a Changelog (see `write-changelog`).76778. **Keep the root lean.** Move tool configs into `package.json`/`pyproject.toml` where supported. Group generated output under ignored folders (`dist/`, `build/`, `target/`, `coverage/`).7879## Rules8081- A newcomer can go from clone to running tests using only the README.82- One canonical command per task, used by both humans and CI.83- No secrets, build artifacts, or IDE-specific files in git.84- Follow the ecosystem's convention before inventing your own.85- Every top-level folder has a one-line explanation in the README layout map.8687## Common Mistakes8889- **README that only says the project name.** Readers can't run anything.90- **Copying the unofficial "golang-standards/project-layout".** The Go team has said it isn't an official standard. Use go.dev's module layout guide and add `pkg/` or `internal/` only as needed.91- **Committed `.env` files.** Leaked credentials. Rotate immediately and purge from history.92- **Scripts with hidden prerequisites.** Pin versions and document requirements in `setup`.93- **Twenty dotfiles at the root.** Consolidate configs where the tools allow.9495## Examples9697**Python service:** `src/myservice/`, `tests/`, `pyproject.toml` (deps, ruff, pytest config), `uv.lock`, `Makefile` with `setup/dev/test/lint`, `.env.example`, `docs/adr/0001-use-postgres.md`, `.github/workflows/ci.yml` calling `make lint test`.9899**Go CLI:** `go.mod`, `main.go` at the root for a single binary (or `cmd/<name>/main.go` for several), `internal/` for private packages, `README.md` with an install line (`go install …@latest`).100101## When NOT to Use102103- **Throwaway scripts and gists.** A README line is enough.104- **Repos governed by an organizational template.** Follow the template and propose changes upstream.