A Repository That Explains Itself: The Ideal GitHub Project Structure for DevOps Teams
A guided tour of a DevOps-ready GitHub repository: root files, the .github folder, source and tests, docs, infrastructure, scripts, monorepo layouts and starter configs you can copy.
- Author
- Navinda Chandrasiri
- Published
- Reading time
- 15 min read

On this page
- Principles for a good structure
- The 30-second tour
- The root: a front door, not a junk drawer
- The .github folder in detail
- Name workflows by what they do
- Share logic with reusable workflows
- Share steps with composite actions
- Ownership and templates
- Source code and tests
- Documentation: docs/
- Infrastructure: infra/ and deploy/
- Scripts and a single entry point
- A reproducible development environment
- Configuration and secrets
- Three starter files you can copy
- Monorepo or multiple repositories?
- Other repository types
- Naming conventions that age well
- Make the structure repeatable with a template
- Mistakes to avoid
- The structure checklist
- Wrapping up
Open an unfamiliar repository and you learn a lot in the first ten seconds. Is there a README? Can you tell where the code lives, where the pipelines are, and where the infrastructure is defined? Or is it a flat pile of folders called stuff, new and old-final?
A good project structure is a user interface for contributors. It answers "where does this go?" and "where do I find that?" before anyone has to ask. For a DevOps team it matters even more, because the repository holds not just application code but the pipelines, infrastructure, documentation and runbooks that keep it running.
This post walks through a structure you can adopt, explains why each piece is there, and gives you starter files to copy. It pairs with The GitHub Repository Playbook, which covers the process around the repository: branching, rulesets, security, releases and recovery.
Principles for a good structure#
A few rules sit behind every choice below:
- Predictable. A new person should guess where things live and be right most of the time.
- A small root. The top level is for the entry points and the handful of files that tools expect there. Everything else goes in a folder.
- One home per concern. Application code, infrastructure, documentation and automation each have one obvious location.
- Docs live next to the code. If the architecture changes in a pull request, the diagram changes in the same pull request.
- Generated and secret things stay out. Build output, dependencies and credentials never belong in git.
- Enforced, not just agreed. Where you can, back the convention with CODEOWNERS, linters and CI so it survives new team members.
The 30-second tour#
Here is a complete layout for a typical application repository with its own infrastructure. Do not worry about every name yet. We will go through each part.
my-project/
├── .github/ # GitHub-specific config and automation
│ ├── workflows/ # CI/CD pipelines
│ ├── actions/ # Reusable composite actions
│ ├── ISSUE_TEMPLATE/ # Issue forms
│ ├── CODEOWNERS
│ ├── dependabot.yml
│ ├── pull_request_template.md
│ └── release.yml # Release-notes grouping
├── .devcontainer/ # Reproducible dev environment
├── docs/
│ ├── architecture/ # Diagrams and system overview
│ ├── adr/ # Architecture Decision Records
│ └── runbooks/ # Operational procedures
├── infra/ # Infrastructure as code
│ ├── modules/
│ └── envs/
├── scripts/ # Small automation helpers
├── src/ # Application source
├── tests/ # Tests that are not co-located
├── .editorconfig
├── .env.example
├── .gitattributes
├── .gitignore
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── Makefile
├── README.md
└── SECURITY.mdThe root: a front door, not a junk drawer#
The root holds the files people and tools look for first. Everything has a job:
| File | Purpose |
|---|---|
README.md | What the project is, how to run it in five minutes, where to learn more |
LICENSE | What others are allowed to do with the code. No license means all rights reserved |
CONTRIBUTING.md | How to propose changes: branching, commit style, running tests, review process |
CODE_OF_CONDUCT.md | Expected behaviour in the community |
SECURITY.md | Supported versions and how to report a vulnerability privately |
CHANGELOG.md | What changed per release. Generate it from commits rather than writing it by hand |
.gitignore | Files git must never track |
.gitattributes | Line endings and how git treats certain file types |
.editorconfig | Editor-agnostic indentation and whitespace rules |
.env.example | A template listing every environment variable, with fake values |
Makefile | One memorable entry point for common commands |
| Lockfile and tool pins | package-lock.json, pnpm-lock.yaml, .nvmrc, .tool-versions: reproducible installs |
GitHub recognises the community health files (CONTRIBUTING, CODE_OF_CONDUCT, SECURITY, SUPPORT) in the root, in docs/, or in .github/. If you are tired of the root getting crowded, move them into .github/. And at the organisation level, a special repository named .github can hold default versions of these files that every repository without its own copy inherits, which is a good way to keep policy consistent.
The .github folder in detail#
This folder is the control room. It holds the automation and the templates that shape how people work with the repository.
.github/
├── workflows/
│ ├── ci.yml # lint, test, build on every pull request
│ ├── codeql.yml # code scanning
│ ├── dependency-review.yml # block risky new dependencies
│ ├── pr-title.yml # Conventional Commits check
│ ├── release.yml # release automation
│ ├── deploy-staging.yml
│ ├── deploy-production.yml
│ ├── backup.yml # scheduled repository backup
│ └── _reusable-node-ci.yml # shared pipeline logic
├── actions/
│ └── setup-project/
│ └── action.yml # composite action
├── ISSUE_TEMPLATE/
│ ├── bug_report.yml
│ ├── feature_request.yml
│ └── config.yml
├── CODEOWNERS
├── dependabot.yml
├── pull_request_template.md
└── release.ymlName workflows by what they do#
Use short, descriptive file names and keep one responsibility per workflow: ci.yml, deploy-production.yml, backup.yml. A person scanning the Actions tab should understand each pipeline from its name alone. Set a clear name: at the top of each file too, since that is what appears in the UI and in required-check lists.
Share logic with reusable workflows#
When three repositories (or three apps in one repository) need the same pipeline, do not copy it. Write it once as a reusable workflow with a workflow_call trigger. The leading underscore in _reusable-node-ci.yml is only a naming convention that signals "do not run this directly":
# .github/workflows/_reusable-node-ci.yml
name: Reusable Node CI
on:
workflow_call:
inputs:
node-version:
type: string
default: "22"
working-directory:
type: string
default: "."
permissions:
contents: read
jobs:
ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ${{ inputs.working-directory }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
cache-dependency-path: ${{ inputs.working-directory }}/package-lock.json
- run: npm ci
- run: npm run lint
- run: npm testA calling workflow then becomes tiny:
# .github/workflows/ci.yml
name: CI
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
web:
uses: ./.github/workflows/_reusable-node-ci.yml
with:
working-directory: apps/webTo share across repositories, put reusable workflows in a central repository and reference them as my-org/shared-workflows/.github/workflows/node-ci.yml@v1. Version them with tags, just like any other dependency.
Share steps with composite actions#
For a few repeated steps rather than whole jobs, write a composite action under .github/actions/:
# .github/actions/setup-project/action.yml
name: Setup project
description: Install Node.js and dependencies with caching
inputs:
node-version:
description: Node.js version
default: "22"
runs:
using: composite
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
- run: npm ci
shell: bashUse it in any job with uses: ./.github/actions/setup-project.
Ownership and templates#
CODEOWNERS, the pull request template and the issue forms live here as well. They are covered in the playbook post, so the one rule to repeat is this: give /.github/ a code owner on your platform or security team. Whoever controls workflows controls what runs with your secrets.
Source code and tests#
There is no single right layout for source code, because it depends on the language and framework. Two ideas hold across all of them.
Organise by feature when you can, by layer when you must. A structure like src/orders/ (containing the handlers, services and models for orders) keeps related things together and makes ownership clear. A structure like src/controllers/, src/services/, src/models/ scatters one feature across the tree. Small projects are fine either way, but feature folders scale better.
Keep tests close and obvious. Either co-locate tests with the code they cover (orders.service.ts and orders.service.test.ts) or mirror the source tree under tests/. Pick one and stay consistent. Put slow cross-system tests (integration, end-to-end) in their own folder so CI can run them separately.
For a Next.js application the source commonly looks like this:
src/
├── app/ # routes, layouts, pages
├── components/ # shared UI components
│ └── ui/
├── features/
│ └── orders/
│ ├── components/
│ ├── actions.ts
│ └── orders.test.ts
├── lib/ # helpers, clients, config
└── styles/
public/ # static assets
tests/
└── e2e/ # Playwright or Cypress specsAnd for a Python API such as one built with FastAPI:
src/
└── my_service/
├── api/ # routers and request/response schemas
├── services/ # business logic
├── models/ # database models
├── core/ # settings, logging, security
└── main.py
tests/
├── unit/
├── integration/
└── conftest.py
pyproject.tomlDocumentation: docs/#
Keep documentation in the repository, in a predictable shape:
docs/
├── README.md # index: where to find what
├── architecture/
│ ├── overview.md
│ └── diagrams/
├── adr/
│ ├── 0001-use-nextjs.md
│ ├── 0002-deploy-with-sst.md
│ └── template.md
├── runbooks/
│ ├── deploy.md
│ ├── rollback.md
│ ├── restore-from-backup.md
│ └── incident-response.md
└── onboarding.mdThe split reflects different audiences and lifetimes. Architecture explains how the system is shaped today. ADRs are an append-only log of why decisions were made, numbered so nothing is rewritten. Runbooks are step-by-step procedures for the person on call at 3 a.m., so they should be short, copy-pasteable and tested. Onboarding gets a new teammate from zero to a running environment.
Diagrams are best kept as text (Mermaid or similar) so they diff and review like code. If you use images, store the editable source file next to the exported picture.
Infrastructure: infra/ and deploy/#
If infrastructure is code, it belongs in version control next to the application it serves, or in its own repository when several applications share it. Keep modules (reusable building blocks) separate from environments (the actual deployments of them).
A Terraform layout:
infra/
├── modules/
│ ├── network/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
│ └── database/
├── envs/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── backend.tf
│ │ └── terraform.tfvars.example
│ ├── staging/
│ └── production/
└── README.mdCommit .terraform.lock.hcl so provider versions are reproducible, keep real *.tfvars out of git when they hold anything sensitive, and use a remote backend for state rather than a state file in the repository.
For Kubernetes manifests, a base-and-overlays layout (for example with Kustomize) keeps shared configuration in one place and environment differences small:
deploy/
├── base/
│ ├── deployment.yaml
│ ├── service.yaml
│ └── kustomization.yaml
└── overlays/
├── staging/
│ └── kustomization.yaml
└── production/
└── kustomization.yamlTools that define infrastructure with a single configuration file, such as SST, usually put it in the root (sst.config.ts) alongside the app. That is fine: follow the tool's convention, and point to it from the README.
The Dockerfile also usually lives at the root of the thing it builds. If you have several, give each its own folder (docker/api/Dockerfile) and name them clearly.
Scripts and a single entry point#
Small automation helpers go in scripts/: seeding a database, generating types, running a local stack. Keep them short and documented, written in a language the team already uses, and make them safe to run twice.
Then give everyone one memorable doorway to all of it. A Makefile (or justfile, or npm scripts) means "how do I run the tests?" has the same answer in every repository:
.DEFAULT_GOAL := help
.PHONY: help setup lint test build
help: ## Show the available commands
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'
setup: ## Install dependencies and git hooks
npm ci
lint: ## Run linters and formatters
npm run lint
test: ## Run the test suite
npm test
build: ## Create a production build
npm run buildRecipes in a Makefile must be indented with a tab, not spaces. Your CI pipelines can then call the same commands (make lint test build), so what runs on a laptop and what runs in CI cannot drift apart.
A reproducible development environment#
.devcontainer/devcontainer.json describes a containerised development environment that GitHub Codespaces and VS Code can open in one click. A new contributor gets the right runtime, tools and extensions without a setup guide:
{
"name": "my-project",
"image": "mcr.microsoft.com/devcontainers/typescript-node:22",
"postCreateCommand": "npm ci",
"customizations": {
"vscode": {
"extensions": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
}
}
}Configuration and secrets#
The rule is simple and absolute: real secrets never enter git. Instead:
- Commit
.env.examplewith every variable name and a harmless placeholder, so people know what to set. - Ignore the real files (
.env,.env.local) in.gitignore. - Keep secret values in a secret manager or in GitHub Actions secrets and environment secrets, and inject them at deploy time.
- Separate configuration (safe to commit, like feature flags and ports) from secrets (never committed).
- Remember that anything prefixed for the browser (
NEXT_PUBLIC_in Next.js) ends up in public JavaScript, so never put a secret there.
# .env.example
DATABASE_URL=postgres://user:password@localhost:5432/app
API_BASE_URL=http://localhost:8080
# Public values only below this line
NEXT_PUBLIC_SITE_URL=http://localhost:3000Three starter files you can copy#
These are the unglamorous files that prevent the most arguments and accidents.
.gitignore, trimmed to the essentials. Extend it for your stack:
# dependencies and build output
node_modules/
.next/
dist/
build/
coverage/
# environment and secrets
.env
.env.*
!.env.example
# terraform
.terraform/
*.tfstate
*.tfstate.*
*.tfvars
# OS and editors
.DS_Store
.idea/
.vscode/*
!.vscode/extensions.json.gitattributes, so line endings are the same on every machine and generated files stay quiet in diffs:
* text=auto eol=lf
*.sh text eol=lf
*.png binary
*.jpg binary
*.pdf binary
package-lock.json linguist-generated=true
pnpm-lock.yaml linguist-generated=true.editorconfig, so every editor agrees:
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[Makefile]
indent_style = tabMonorepo or multiple repositories?#
At some point you will wonder whether several services belong in one repository.
| Choose a monorepo when | Choose separate repositories when |
|---|---|
| Projects share code and change together | Projects have independent lifecycles and owners |
| You want one pull request to update a library and its users | Different teams need different access and review rules |
| You want shared tooling, one set of standards, atomic changes | You want small clones, simple CI, and clear boundaries |
If you go with a monorepo, a layout like this works well:
my-platform/
├── apps/
│ ├── web/ # Next.js frontend
│ └── api/ # backend service
├── packages/
│ ├── ui/ # shared components
│ ├── config/ # shared ESLint, TypeScript, Prettier configs
│ └── utils/
├── infra/
├── docs/
├── .github/
├── package.json
├── pnpm-workspace.yaml
└── turbo.json# pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"Three habits keep a monorepo healthy:
- Build only what changed. Tools such as Turborepo and Nx understand the dependency graph, so a change to
apps/webdoes not rebuildapps/api. - Use
CODEOWNERSper folder, so each team still reviews its own area. - Beware path-filtered workflows combined with required checks. A workflow that only runs when
apps/web/**changes will leave its required check pending on other pull requests. Theci-gatejob pattern in the playbook post solves this.
Other repository types#
Not everything is an application. The same principles apply with different shapes.
An infrastructure or GitOps repository is organised by environment and cluster rather than by feature:
platform-config/
├── clusters/
│ ├── staging/
│ └── production/
├── apps/
│ ├── web/
│ └── api/
├── policies/ # security and compliance rules
└── README.mdA library adds public API documentation and examples, and puts its tests and a CHANGELOG.md front and centre:
my-library/
├── src/
├── tests/
├── examples/
├── docs/
├── package.json # or pyproject.toml
└── README.md # installation and quick-start firstNaming conventions that age well#
Consistency beats cleverness. Pick a convention and apply it everywhere:
- Folders and files:
kebab-casefor most things (order-service/,deploy-production.yml), unless your language or framework dictates otherwise (Python packages usesnake_case). - Workflows: named after what they do, never after who wrote them.
- Branches:
type/short-description, as described in the playbook. - ADRs: zero-padded numbers and a short title (
0007-use-postgresql.md). - Avoid: spaces in names, vague folders like
misc,utils2orold, and committed copies such asconfig-backup.json. Git already remembers the old version.
Make the structure repeatable with a template#
A structure that only exists in one repository is a good habit. A structure that is stamped onto every new repository is a standard. Create a template repository containing the folders, config files, workflows and placeholder docs above, mark it as a template in its settings, and start new projects from it:
gh repo create my-org/new-service --template my-org/project-template --private --clonePair that with an organisation-level .github repository for default community files, and a new project begins life with sensible defaults rather than a blank page.
Mistakes to avoid#
- Committing secrets,
.envfiles or state files. Treat any that slip in as compromised and rotate them. - A giant root folder with thirty config files and no README. Move what you can into folders.
- Copy-pasted workflows that drift apart. Use reusable workflows and composite actions.
- Docs in a separate wiki nobody updates. Keep them in the repository and review them with the code.
- Committing generated output such as build folders and compiled assets, which bloats history and creates merge conflicts.
- Unowned folders. Every area should have a code owner.
- An aspirational structure. Do not create empty folders for things you do not have. Add structure when you need it.
The structure checklist#
- A clear README with a five-minute quick start.
LICENSE,CONTRIBUTING.md,CODE_OF_CONDUCT.mdandSECURITY.mdin place..gitignore,.gitattributesand.editorconfigcommitted..env.examplecommitted, real environment files ignored..github/containing workflows, issue forms, PR template,CODEOWNERSanddependabot.yml.- Shared pipeline logic in reusable workflows or composite actions.
docs/with architecture, ADRs and runbooks.infra/(anddeploy/if needed) separating modules from environments.scripts/and aMakefilegiving one entry point to common tasks.- A dev container or pinned tool versions for a reproducible setup.
- A template repository so new projects start from this structure.
Wrapping up#
A structure is a promise to the next person: "you will find things where you expect them." Keep the root small, give every concern one home, keep docs beside the code, and back the conventions with ownership and automation so they last.
You do not need every folder on day one. Start with the README, the .github basics and a clear separation of code, docs and infrastructure, then grow the structure as the project does. For the rules that protect the repository once it is organised, continue with The GitHub Repository Playbook: Branching, Rulesets, Security, Releases and Recovery for a DevOps Project.
Related reading
The GitHub Repository Playbook: Branching, Rulesets, Security, Releases and Recovery for a DevOps Project
A practical playbook for running a project on GitHub: branching, rulesets, security scanning, versioned releases, issue management, backups and disaster recovery, docs and standards.
GitHubDevOpsSecurityGit
24 min readFrom Commit to Two Regions: A Multi-Region CI/CD Pipeline with AWS CodePipeline and CodeDeploy
Build a CI/CD pipeline on AWS DevOps tools: GitHub triggers CodePipeline, CodeDeploy ships to EC2 in two Regions, with a manual approval gate and an automated Lambda readiness check.
AWSCI/CDCodePipelineCodeDeploy
14 min readGoodbye Access Keys: Connecting GitHub Actions to AWS with OIDC
Replace long-lived AWS keys in GitHub secrets with short-lived OIDC credentials. IAM setup, trust policies, a working workflow, Terraform and a troubleshooting guide.
AWSGitHub ActionsOIDCIAM
9 min read