PeaBox Lab › PeaLang › Learn › Chapter 9 › Lesson 3

Part II — Intermediate Development · Chapter 9 · Lesson 3 of 5 · 6 min read

Lesson 3: Project Layout, Configuration, and Documentation

Lesson level: Intermediate

Purpose: Organize a multi-module project so that files are easy to find, behavior can be configured without editing code, and other people can learn and use the project from its documentation.

Learning objectives

Release note: project manifests, configuration file formats, and documentation commands vary by release. Verify exact names against the installed release, including the pea docs behavior introduced in Chapter 1.

3.1 A predictable layout

A consistent layout lets anyone find things without asking. Keep source modules together, tests beside or mirroring them, configuration in one place, and documentation at the top.

order-service/
  README.md
  config/
    defaults.json
    example.local.json
  src/
    constants.pea
    rules.pea
    adapters.pea
    main.pea
  tests/
    rules_test.pea
  docs/
    modules.md

The names here are illustrative. What matters is that the layout is the same across your projects and is described in the README.

3.2 One responsibility per directory

DirectoryHoldsRule
srcModule source filesLayered as in Lesson 2
testsTests and fixturesSynthetic data only
configDefaults and examplesNo secrets committed
docsReference and guidesRegenerate derived files, never hand-edit them

3.3 Why configuration is separate

Thresholds, limits, labels, and environment-specific values change more often than logic. Keeping them in configuration lets you adjust behavior without editing rules and makes the changes reviewable on their own. Policy constants that define the rules themselves, such as the Chapter 1 priority thresholds, may still belong in a constants module; use configuration for values that differ between deployments.

3.4 A configuration example

{
  "allowed_regions": ["north", "south", "east"],
  "max_rows": 10000,
  "report_title": "Daily order summary"
}

Keep the file small and flat. Every key should have a documented meaning, a type, and a default.

3.5 Validate configuration once, at the boundary

Configuration is external input and deserves the same suspicion as any other. Load it in one adapter, check that required keys exist and values are in range, then pass a validated map to the core. A bad value should fail early with a clear reason code rather than deep inside a rule.

CheckExampleFailure code
Required key presentreport_title existsconfig_missing_key
Type is correctmax_rows is a numberconfig_bad_type
Value in rangemax_rows between 1 and 100000config_out_of_range
Known values onlyregions are in the approved listconfig_unknown_value

3.6 Secrets and environment values

3.7 Defaults and overrides

Provide a defaults file that makes the project run out of the box, then allow a local file to override specific keys. Merge them in one place, validate the result, and record which source supplied each value when debugging. Keep the precedence rule simple and document it: defaults first, local overrides second.

3.8 What to document

DocumentAudienceContents
READMENew contributors and usersPurpose, setup, how to run and test, layout, configuration keys
Module referenceCallers of a moduleExports, contracts, failure codes
Configuration referenceOperatorsEvery key, type, default, and valid range
Change notesEveryoneBreaking changes and migrations

3.9 Generated and hand-written documentation

Chapter 1 introduced documentation generation from source. Use it for reference material that mirrors the code, such as module exports, and regenerate it when declarations change. Write guides, rationale, and examples by hand. Mixing the two in one file invites hand edits that the next regeneration silently overwrites, so keep generated files separate and mark them as generated.

3.10 A README that works

3.11 Common mistakes

MistakeEffectCorrection
Hard-coded environment values in rulesEdits needed for every deploymentMove them to configuration
Committing real credentialsLeaked secretsCommit placeholders only
Unvalidated configurationFailures deep in core logicValidate once at the boundary
Hand-editing generated docsChanges lost on regenerationEdit the source and regenerate
README that skips setup stepsNew contributors get stuckTest it on a clean machine
Inconsistent layouts across projectsTime lost searchingAdopt one layout

3.12 Diagnostic workflow

3.13 Guided practice

3.14 Hands-on lab: package a project

Scenario: Take the modules from the Lesson 2 lab and turn them into a project others can run.

Requirements. Create the directory layout, a defaults configuration file, an example local override, a configuration adapter that validates keys and ranges, and a README. Generate reference documentation for each module and keep it in a separate folder.

Tests. Test the configuration adapter with valid files and with one file per failure code. Follow the README on a clean copy of the project and record any step that fails.

Deliverables. The project tree, configuration files and reference, validated loader, README, generated module reference, and a note recording the clean-copy run.

Acceptance criteria.

3.15 Review questions

3.16 Applied challenge

Review a project you have built in this book. Write its configuration reference, identify any hard-coded environment value that should move into configuration, and add the validation checks and reason codes needed. Then ask a colleague to follow your README on a clean copy and fix every point where they stall.

3.17 Lesson summary

3.18 Transition to Lesson 4

The next lesson covers formatting, checking, and maintainability conventions: how the toolchain's formatter and checker keep a multi-module project consistent over time.

Lesson status: Ready for review.

← Previous Next →