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
- Choose a predictable directory layout for sources, tests, configuration, and documentation.
- Separate configuration from code and keep secrets out of both.
- Validate configuration at the boundary before it reaches core logic.
- Write documentation that stays accurate, including generated reference material.
- Prepare a project that a new contributor can build and run from the README alone.
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
| Directory | Holds | Rule |
|---|---|---|
| src | Module source files | Layered as in Lesson 2 |
| tests | Tests and fixtures | Synthetic data only |
| config | Defaults and examples | No secrets committed |
| docs | Reference and guides | Regenerate 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.
| Check | Example | Failure code |
|---|---|---|
| Required key present | report_title exists | config_missing_key |
| Type is correct | max_rows is a number | config_bad_type |
| Value in range | max_rows between 1 and 100000 | config_out_of_range |
| Known values only | regions are in the approved list | config_unknown_value |
3.6 Secrets and environment values
- Never store credentials, tokens, or keys in source or in committed configuration files.
- Commit an example file with placeholder values and keep real values outside version control.
- Obtain secrets through a host or secret provider at run time, as later chapters describe.
- Never print or log configuration values that could be sensitive.
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
| Document | Audience | Contents |
|---|---|---|
| README | New contributors and users | Purpose, setup, how to run and test, layout, configuration keys |
| Module reference | Callers of a module | Exports, contracts, failure codes |
| Configuration reference | Operators | Every key, type, default, and valid range |
| Change notes | Everyone | Breaking 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
- One-paragraph purpose and scope.
- Prerequisites, including the PeaLang version.
- Setup steps that a new person can follow verbatim.
- How to run the program and the tests, with expected output.
- A short layout map.
- Configuration overview with a link to the full reference.
- The capabilities the project requests and why.
3.11 Common mistakes
| Mistake | Effect | Correction |
|---|---|---|
| Hard-coded environment values in rules | Edits needed for every deployment | Move them to configuration |
| Committing real credentials | Leaked secrets | Commit placeholders only |
| Unvalidated configuration | Failures deep in core logic | Validate once at the boundary |
| Hand-editing generated docs | Changes lost on regeneration | Edit the source and regenerate |
| README that skips setup steps | New contributors get stuck | Test it on a clean machine |
| Inconsistent layouts across projects | Time lost searching | Adopt one layout |
3.12 Diagnostic workflow
- Reproduce the problem from a clean checkout following only the README.
- Check which configuration file and values are actually loaded.
- Confirm the validation result and its reason code.
- Compare the documented behavior with the actual behavior and decide which is wrong.
- Fix the code or the documentation, then regenerate derived files.
3.13 Guided practice
- Sketch a layout for a three-module project with tests and configuration.
- List which values from the Chapter 8 utility belong in configuration and which are policy constants.
- Write four validation checks with reason codes for a configuration file.
- Decide which documents should be generated and which hand-written.
- Outline a README for the utility.
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.
- No credentials or real data appear anywhere in the project.
- Invalid configuration fails with a specific reason code.
- The README steps work verbatim on a clean copy.
- Generated documentation is separate and marked as generated.
3.15 Review questions
- Why does a consistent project layout help?
- What belongs in configuration, and what in a constants module?
- Why validate configuration at the boundary?
- How should secrets be handled?
- How do defaults and local overrides interact?
- Why separate generated from hand-written documentation?
- What must a README contain for a new contributor?
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
- Use a predictable layout and describe it in the README.
- Keep environment-specific values in validated configuration, separate from rules.
- Never commit secrets; commit placeholder examples instead.
- Generate reference documentation from source and keep it separate from hand-written guides.
- Test the README on a clean copy.
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.