Skip to content

Project structure

A project is a folder with a selectjoin.toml at its root. Commands find it by walking up from the current directory, the way git finds a repository.

This is what selectjoin init my_project --template layers creates:

  • Directorymy_project
    • selectjoin.toml dialect, folders, layers, windows, packages
    • Directorysources/ physical tables you read from
      • orders.py
      • archived_orders.py
      • customers.py
    • Directorymodels/ one model per file
      • Directorystaging/ clean one input table
        • stg_orders.py
        • stg_archived_orders.py
        • stg_customers.py
      • Directoryintermediate/
        • Directorycombine/ join or union tables
          • int_all_orders.py
          • int_orders_customers.py
        • Directoryenrich/ add attributes from one table
          • int_order_attributes.py
        • Directoryfeatures/ derive attributes from combined data
          • int_order_customer_features.py
      • Directorymarts/ outputs for end users
        • mart_customer_revenue.py
    • Directorycomponents/ shared Python, imported by models
      • orders.py
      • features.py
      • schemas.py
    • checks.py data checks, generated with loops
    • README.md
Path You write it Purpose
selectjoin.toml Yes The SQL dialect, folder names, layers, date windows, and packages. See the reference.
sources/*.py Yes One file per physical table. Each exports a build() decorated with @source that names the table and its column types.
models/**/*.py Yes One file per model. Each exports a build() decorated with @model that returns a query.
components/*.py Yes Plain Python functions that models import. No decorator and no registration.
checks.py Optional A build(project) function that yields data checks.
metadata.json Optional An offline snapshot of table and column metadata that sources can read their schemas from.
build.py Optional A script that compiles the project. The minimal template includes one.
target/ No Where you choose to write compiled SQL. Nothing is written unless you pass --output.
  • A source is named after its file: sources/orders.py is orders.
  • A model is named after its file, without the layer folder: models/staging/stg_orders.py is stg_orders.
  • A file outside a layer folder keeps its path, with dots: models/finance/revenue.py is finance.revenue.
  • @model(name="...") or @source(name="...") overrides the file name.

Names are unique across sources and models. Files and folders that start with an underscore are ignored.

Layers are optional. A model in a layer’s folder gets that layer, and selectjoin new adds the layer’s prefix (stg_, int_, mart_) for you. The layer never affects compile order; only references do.

selectjoin init my_project creates the minimal layout, which is enough to start:

  • Directorymy_project
    • selectjoin.toml
    • metadata.json column types for raw.orders
    • Directorysources/
      • orders.py
    • Directorycomponents/
      • staging.py one shared cleaning function
    • Directorymodels/
      • Directorystaging/
        • stg_orders.py
    • build.py compiles everything from a script
    • README.md

Add checks.py and more layer folders when you need them. Nothing has to be declared in advance. selectjoin init my_project --bare creates only the source.

Commit selectjoin.toml, sources/, models/, components/, checks.py, and metadata.json. Those are the project.

Compiled SQL is generated. Commit it only if something reads it from the repository, such as a scheduler that runs files from a folder. Otherwise generate it in CI or at deploy time and keep target/ out of version control.

Per-model files are a convention, not a requirement. A script can register sources and models in a loop and compile them, with no sources/ or models/ folders at all. See Scripting without files.