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

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

Chapter 9 Checkpoint: Multi-Module Business-Rules Project

Checkpoint level: Intermediate

Purpose: Integrate module boundaries, cross-module contracts, project layout, validated configuration, and the quality routine in one complete multi-module business-rules project.

Release note: module names, commands, and configuration keys are illustrative. Verify them against the installed v0.63 release before relying on them.

Checkpoint outcomes

9C.1 Scenario: Order discount and eligibility service

A retailer needs a rules project that decides, for each order, whether it is eligible for a discount, which discount applies, and why. The project uses synthetic data only. It has no network, secret, or process access. Each decision returns a discount amount, a reason code, and a short message.

9C.2 Required modules

ModuleResponsibilityMay depend on
typesConstants, reason codes, and decision shapeNothing
validationChecks order input and returns clear errorstypes
rulesPure discount rules and precedencetypes
configLoads and validates thresholds and ratestypes, validation
serviceCombines validation, configuration, and rules into one exported decision functiontypes, validation, rules, config
mainEntry point that prints a labeled report for sample ordersservice

Dependencies point downward. No lower module may import a higher one, and no two modules may import each other.

9C.3 Contracts

The service module exports one function, decide_order, which accepts a string-keyed map and returns a string-keyed map.

DirectionFieldTypeRule
Inputorder_idstringRequired, nonempty
Inputcustomer_tierstringOne of standard, gold
InputsubtotalnumberZero or greater
Inputitem_countintegerOne or greater
OutputallowedbooleanTrue when the input is valid
OutputdiscountnumberNever negative and never above the subtotal
Outputreason_codestringVALIDATION_ERROR, GOLD_BULK, GOLD, BULK, or NONE
OutputmessagestringShort, labeled, free of secrets

9C.4 Policy

9C.5 Project layout

order_rules/
  pea.toml            # project metadata (illustrative)
  config/
    rules.defaults    # thresholds and rates, no secrets
  src/
    types.pea
    validation.pea
    rules.pea
    config.pea
    service.pea
    main.pea
  tests/
    rules_tests.pea
    service_tests.pea
  docs/
    contracts.md      # derived from exported comments

9C.6 Requirements

9C.7 Constraints

9C.8 Acceptance criteria

9C.9 Reference design

The core is a pure function that takes validated values and returns a decision. Validation and configuration sit beside it and never call upward. The service function is the only place where they are combined.

Keeping rules pure means it can be tested without any configuration file, and a different host could reuse it unchanged.

9C.10 Test matrix

CaseTierSubtotalItemsExpected reason
Astandard501NONE
Bgold501GOLD
Cstandard50at bulk thresholdBULK
Dgold50at bulk thresholdGOLD_BULK
Estandard50one below bulk thresholdNONE
Fgold01GOLD with discount 0
Ggold10at bulk threshold, with combined rate above 100%GOLD_BULK, discount capped at 10
Hsilver501VALIDATION_ERROR
Istandard-51VALIDATION_ERROR
Jstandard500VALIDATION_ERROR
Kstandard501, with an empty order_idVALIDATION_ERROR

Cases C, D, and E test the exact bulk boundary. Case G tests the cap. Cases H–K test validation. Add a configuration test that loads a rate of 1.5 and confirms rejection.

9C.11 Validation workflow

9C.12 Debugging requirement

Introduce one temporary defect: swap the gold-with-bulk branch below the gold-only branch. Confirm that case D fails with reason GOLD instead of GOLD_BULK. Restore the correct order and rerun. Then add a temporary upward import from rules to service and confirm that your dependency review catches it. Remove both defects before submission.

9C.13 Submission package

9C.14 Assessment rubric

AreaEvidence of mastery
Module designEach module has one responsibility and a stated contract.
Dependency directionNo cycles and no upward imports.
CorrectnessAll policy branches, boundaries, and the cap behave as specified.
ConfigurationValues are validated at load time and contain no secrets.
Quality routineFormat, check, and tests run separately in non-mutating mode.
MaintainabilityNames, comments, and exports follow the agreed conventions.
SecurityNo capability beyond the documented local read.
ExplanationThe learner can justify the layout and trace any decision.

Completion standard: Every test passes, every acceptance criterion is met, and the learner can explain why the dependency table prevents cycles.

Reflection questions

Optional extensions

Chapter 9 summary

You can now draw module boundaries, control imports and exports, design contracts that dependencies respect, lay out and configure a project safely, and keep it healthy with formatting, checking, review, and a repeatable quality routine. The checkpoint brought these together in a multi-module business-rules project.

Transition to Chapter 10

Chapter 10 turns to testing and quality engineering. The next lesson covers native test syntax and expectations, so the tests used informally here become a first-class part of the project.

Checkpoint status: Ready for review.

n

← Previous Next →