Skip to content

Project Structure

Most users start with a single app.py file. That is the right starting point, but it is not the right ending point for a larger repository.

Small Project Layout

Good for learning and small internal tools:

my-infra/
  app.py
  pyproject.toml

Good for real applications with more than one stack:

my-infra/
  pyproject.toml
  infra/
    __init__.py
    app.py
    stacks/
      __init__.py
      network.py
      storage.py
      app_service.py
    constructs/
      __init__.py
      service_baseline.py
    environments/
      __init__.py
      dev.py
      prod.py
  tests/

Why This Layout Works

  • app.py stays focused on composition
  • stacks stay small and easier to reason about
  • reusable constructs have a clear home
  • environment policy can be kept separate from resource definitions
  • tests can target stacks and constructs without importing a giant monolith

app.py

Keep:

  • app creation
  • stack instantiation
  • environment selection
  • execution-path selection

stacks/

Keep:

  • stack-local provider setup
  • resource composition
  • outputs and stack metadata

constructs/

Keep:

  • reusable patterns made of multiple resources
  • code you expect more than one stack to use

environments/

Keep:

  • env-specific values
  • backend selection policy
  • region/account choices