S++Core systems, human-reviewable
SDK DOCUMENTATION · 1.0-SNAPSHOTStart the tutorial

S++ tutorial

This tutorial takes you from a business scenario to generated, executable Java, then introduces persistence and custom technical services. It uses the open basic SDK: no account, paid module, scenario quota or deployment-topology license restriction is required. Instructions match the 1.0-SNAPSHOT source layout; use matching compiler and runtime artifacts throughout.

Public S++ documentation, examples and release notes use English as their primary language. This tutorial has one English source of truth.

1. Understand the three layers

Layer Question it answers Typical content
SPP What does the business do? Participants, calculations, checks, scenarios and business transaction boundaries
APP How is this business realized as an application? Table identities, query bindings, service exposure, deployment and technical policies
PHY Which concrete facilities execute it? JDBC repositories, resource adapters, endpoints and technical service classes

For example, SPP says “revise the entry and save it.” APP selects the entry key and transaction resource. PHY supplies the database and repository adapter. Changing databases or a request-handling policy should not require rewriting the business scenario.

An Entity represents an independently identified business object. A Role expresses the facts and responsibilities of a participant in a business context; it can be mapped to an entity or another role. A Contract expresses a business agreement and its terms. These are business concepts, not names for controller, database-table or generic JSON DTO classes.

2. Prepare the basic SDK

Install JDK 25 and Maven 3.9+. The following commands use a POSIX shell and run from the SDK source root. Windows users can use WSL, or adapt paths and classpath separators to their shell.

java -version
mvn -version
mvn -Pbasic -pl :spp-basic-cli -am install -DskipTests
java -jar sdk-tools/basic-cli/target/spp-basic-cli-1.0-SNAPSHOT.jar --version

install makes the matching runtime available to the generated application's separate Maven build. -DskipTests shortens this setup command; it does not mean tests have passed. Maven needs access to its dependency repositories on the first build. The compiler itself works offline once its dependencies are available. The template engine is included under vendor/antlrmustache; no sibling checkout or manual template-engine installation is needed.

For VS Code installation, settings and navigation, see the SDK user guide.

3. Write a small business scenario

The complete input is checked in at sdk-tools/samples/tutorial/src/main/spp. Its ledger.spp is:

domain ledger;

Role Facts {
    int amount;
}

atomic calculate prepare(Facts) {
    Facts.amount = 7;
}

atomic calculate twice(Facts) {
    Facts.amount *= 2;
}

atomic check verifyAmount(Facts) {
    require(Facts.amount == 14, "The amount must be 14");
}

readonly Scenario serial preview(Facts) {
    prepare;
    twice;
    verifyAmount;
}

domain groups the model and services. Facts is the participant passed through the scenario. A calculate service changes its in-memory business facts; it does not by itself save those facts to a database. A check service confirms a condition with require and must not modify the participant. A serial scenario composes the named services in order: initialize 7, double it, then check 14.

The prepare service is an example fixture. A real application would normally receive or query the starting facts, rather than reset every request to 7.

The accompanying ledger.app declares an executable example:

domain ledger;

scope {
    local { preview; }
}

examples {
    run preview;
}

The local scope binds the example to local execution and supplies the default for the domain’s other services. The generic example runner creates the request and its empty top-level participants. SPP prepares the business data and checks the result. No handwritten Java implementation of the scenario is needed. This example has no business persistence and therefore needs no PHY file.

A service is bound by the scope that lists it. Services that no scope lists take the default local scope. APP files of one domain may each declare their own local { } scope (for example a shared file and a flow-specific file): when all local scopes carry the same in/out headers (or none), they are interchangeable and an unlisted service takes the first, so a flow does not have to list every service. Local scopes with different headers make an unlisted service ambiguous, because the choice would change its headers; list the service in the scope you mean. The order of the staged .spp, .enum and .app files does not matter: an enum literal such as Status.DONE resolves wherever its enum is declared.

4. Check and generate

From the SDK source root:

java -jar sdk-tools/basic-cli/target/spp-basic-cli-1.0-SNAPSHOT.jar check \
  --source sdk-tools/samples/tutorial/src/main/spp

java -jar sdk-tools/basic-cli/target/spp-basic-cli-1.0-SNAPSHOT.jar generate \
  --source sdk-tools/samples/tutorial/src/main/spp \
  --output target/tutorial-java \
  --package example.generated

The output directory must not already exist. To repeat generation, choose a new directory or deliberately remove only your previous generated output. The CLI reports one JSON result on stdout; compiler diagnostics go to stderr.

The generated directory contains pom.xml, Java models and services, API handlers, runtime catalogs under src/main/resources/META-INF/spp, OpenAPI inputs under openapi, and spp-generation.json. This is an integration library, not an automatically deployed web server. Keep your .spp/.app/.phy inputs as the editable source; regenerate Java instead of patching it.

5. Build and run the example

cd target/tutorial-java
mvn verify
mvn dependency:build-classpath -Dmdep.outputFile=target/runtime-classpath.txt
mvn dependency:copy -Dartifact=com.h2database:h2:2.2.224 \
  -DoutputDirectory=target/tutorial-lib
java -cp "target/classes:target/tutorial-lib/*:$(cat target/runtime-classpath.txt)" \
  ../../sdk-tools/samples/tutorial/VerifyTutorial.java

Expect BUSINESS PASS preview. The small VerifyTutorial.java acceptance adapter invokes the generic runner and checks the resulting business status. It contains no implementation of the ledger calculation. Java 25 runs this source file directly using the generated project's classpath.

The generic runner also prints PASS preview, meaning execution returned without a technical exception. A failed require is a business rejection, so that line alone is not proof that the business check passed. The adapter explicitly checks BusinessChecks.scenarioResult() and exits with an assertion failure on rejection. Hosts and tests must inspect business status, not just method return.

H2 supplies the runner's technical storage; this first lesson does not create a business ledger table. The runner does not invent an outer business transaction. For a failing exercise, change only Facts.amount == 14 to Facts.amount == 15, generate into a new output directory under target/, build it and run the same adapter with that output's classpath: it must fail with Business check rejected preview. Restore 14 afterwards. The message string is just a business rejection code/message; changing it does not change the condition.

6. Add identity, queries and persistence

Continue with the complete custom-services example. From the SDK source root, run:

mvn -Pbasic,basic-example -pl :spp-custom-services-example -am test

Read its files in this order:

  1. ledger.spp introduces an Entry, a Revision agreement and create/read/revise scenarios.
  2. ledger.app supplies the table key, query binding, LOCAL deployment and custom interceptor.
  3. ledger.phy selects JDBC, an H2 database, a transaction backend and the implementation class.
  4. BasicPersistenceTest.java invokes generated scenarios and checks the database results.

The revision scenario is:

Scenario serial reviseRecord(Entry, Revision) {
    findEntry;
    applyRevision;
    transaction { updateEntry; }
}

findEntry loads the existing participant, applyRevision changes its facts, and updateEntry persists them inside the source transaction boundary. Standard CRUD operations can be supplied by the compiler; an implicit findEntry or updateEntry is not an undefined handwritten Java function.

The important query binding in this example is:

scope {
    local {
        repository(argument(0, Entry.code), Entry) using records findEntry;
    }
}

The first participant argument supplies Entry.code; APP maps that property to the table primary key. The query populates that participant from records. It does not infer a SQL predicate from the function's spelling. A grouped or non-primary-key query needs its own explicit APP binding and criteria; copying this single-record binding does not turn it into a list query.

The example verifies both an explicit-null full update and a real version conflict: two updates based on the same read version cannot silently overwrite each other. The second conflicting write reports PERSISTENCE_VERSION_CONFLICT. Basic optimistic protection works without official tracking or partial updates. After a conflict, reload and re-evaluate the business decision; do not repeatedly submit the stale object or disable protection just to make the write succeed.

The example's jdbc:h2:mem:...;DB_CLOSE_DELAY=-1 database lasts for the JVM's lifetime, even when connections close. A file URL persists across restarts. Check the effective PHY URL when investigating retained data.

Read a participant by key

When other participants supply the lookup values, declare how they play the target role and list them on the read.

Role Book { String code; int edition; }
Role Selection { String requestedCode; }
Role Publication { int edition; }
take Selection as Book { String code = requestedCode; }
take Publication as Book { mapsame; }
const int CURRENT_EDITION = 3;

Scenario serial readSelectedBook(Book, Selection, Publication) {
    findBook by Selection, Publication;
}
Scenario serial readCurrentBook(Book, Selection) {
    findBook by Selection, Publication.edition = CURRENT_EDITION;
}

With APP declaring Book.code and Book.edition as the primary key, the first read gets the code from Selection.requestedCode and the edition from Publication.edition. The second read supplies the edition as a named constant through its performer field. Book.edition = 3 binds the target field directly. Each key field needs exactly one source. The compiler checks the take relation, field types, and declared widths. Binding works in scenarios and is independent of APP key order. The generated scenario sets the keys immediately before the read and keeps them on the target afterward.

For a declared list query such as atomic query listCopies(key Book book, Copy[] matches);, the values bind to book's APP primary key. The query still fills matches.

A failing plain check or identify ends its enclosing bare block. Only an explicit serial { }/parallel { } block, a transaction { } block or a failure handler is a bare block; the bodies of if/else and of a guarded check are transparent. When the enclosing bare block is the transaction { } itself, the failure rolls the whole transaction back, exactly as ,breakTransaction does. A check inside an if body that sits directly in the transaction therefore also rolls it back. To leave only part of the logic, wrap it in an extra serial { }: a failing check there exits only that block and the transaction continues and commits. Outside a transaction a failing check only ends its block. This holds at any depth of if/else nesting and inside the braces of a guarded check: a failing check ends the enclosing serial/parallel/transaction block (or the scenario body) and none of the statements that follow the if run.

Use ,breakTransaction to roll back the whole transaction from any depth, including from inside a nested bare block.

One participant per role

A service signature lists types. In the body, refer to each participant by its short name. The default is the type name in lower camel case. Declare a shared short name on the type when it reads better in business rules.

domain sampledomain;

Entity ExternalLoss short loss, losses {
    String registrationNumber;
}

Entity Operator {
    String operatorNumber;
    String operatorName;
}

Role LossRegisteringOperator short registrar;
Role LossReleasingOperator short releaser;

Scenario serial readLossOperators(LossRegisteringOperator, LossReleasingOperator) {
    findLossRegisteringOperator by registrar.operatorNumber = "R1";
    findLossReleasingOperator by releaser.operatorNumber = "R2";
}

The optional second name in short loss, losses names an array parameter. Without it, ExternalLoss[] adds s to the scalar short name. An explicit parameter name causes SPP_EXPLICIT_PARAMETER_NAME. A reused short name in the same signature causes SPP_PARAMETER_SHORT_NAME_COLLISION. Calculation locals still declare their own names. A type-name reference such as ExternalLoss.registrationNumber remains available when it resolves unambiguously. Use short names in new source.

A participant type can appear once per shape in a service signature. (ExternalLoss, ExternalLoss[]) can express a selector and a result collection. Two scalar records of the same entity need two roles. If the entity plays each role, you can omit the role's fields and map its key in APP.

play LossRegisteringOperator by sampledomain.Operator { operatorNumber = operatorNumber; }
play LossReleasingOperator by sampledomain.Operator { operatorNumber = operatorNumber; }

For an SPP take, use Role PeriodEnd; and take Period as PeriodEnd; to reuse the fields of Period. A calculation expecting Period can receive PeriodEnd. It can also receive another compatible role played by Period when the formal parameter names PeriodEnd. The caller's participant receives the changed facts. The types still identify distinct participants in a signature.

A role carries all facts of its player: the APP play when there is one, otherwise the first take in declaration order. Further takes of the role only map their own sources onto those facts. They add no facts, so a quantum fact of such a source is not pulled in. findRegionOffice by regionLink also works when regionLink is itself a role: the key is read through the player of regionLink and its take mappings. A role passed where its player is expected books the quantum position of the player, so a transfer between two roles of one player moves one conserved attribute between two positions.

Declare decimal rounding

Declare the precision, scale and rounding mode on the result. Use ordinary division in the calculation.

Role AccrualBasis {
    BigDecimal(15,2) amount;
    BigDecimal(15,2) unit;
}
Role AccrualResult {
    BigDecimal(15,0,DOWN) qualifiedUnits;
}
atomic calculate accrue(AccrualBasis, AccrualResult) {
    AccrualResult.qualifiedUnits = AccrualBasis.amount / AccrualBasis.unit;
}

With amount equal to 0.29 and unit equal to 0.03, the repeating quotient is computed at high precision. Assignment rounds it toward zero, giving 9 at scale zero. A calculation local can declare rounding the same way, for example BigDecimal(18,6,HALF_UP) rate.

If a calculation may lose fractional digits at a target with a scale and no rounding mode, the compiler warns and uses DOWN. Choose the mode in SPP so the same business rule applies across PHY representations.

Move a variable number of lines in one transaction

A slip with several lines moves each line's units between two holders. Give the quantum update the collections of positions and loop over the lines. Each iteration is one conserved transfer, the whole slip is all-or-none.

Entity Slot { String owner; String kind; quantum BigDecimal(16,0) pieces; }
Role Giving short giving, givings;
Role Receiving short receiving, receivings;
take Slot as Giving;
take Slot as Receiving;
quantum update moveSlip(Slip, Giving[], Receiving[]) {
    for (SlipLine line : slip.lines) {
        for (Giving source : givings) {
            for (Receiving target : receivings) {
                if (source.kind == line.kind && target.kind == line.kind) {
                    source.pieces -> target.pieces : line.units;
                }
            }
        }
    }
}

The scenario keys the positions once per kind, finds them with a plural find keyed by the player (repository(argument(0, Slot.owner), argument(0, Slot.kind), givings) using records findGivings;; keying the role collection by the role is refused, because the rows belong to the player) and calls moveSlip(slip, givings, receivings) in a transaction. The two collections may be roles of one player, or one collection of the player (for (Slot source : slots) { for (Slot target : slots) { ... } }). Both are resolved as positions of the player's conserved attribute, so the transfers move one attribute between distinct positions. APP declares the attribute once, quantum resource(movement, Slot.pieces) moveSlip;. An existing loop from one scalar source to a collection of members is unchanged.

Pick the positions by key

The nested loops above only select two positions. pick states the selection directly and checks that it found exactly one element:

quantum update moveSlip(Slip, Giving[], Receiving[]) {
    for (SlipLine line : slip.lines) {
        Giving source = pick givings by owner = slip.giver and kind = line.kind;
        Receiving target = pick receivings by owner = slip.taker and kind = line.kind;
        source.pieces -> target.pieces : line.units;
    }
}

pick <collection parameter> by field = expression [and field = expression]... yields the element whose fields equal the expressions. The local is the element itself, and it can be a transfer endpoint. A line with no matching position is QUANTUM_MATCH_MISSING and a key that matches two is QUANTUM_MATCH_AMBIGUOUS; both roll back the slip, where the nested loops would silently do nothing or transfer twice. The key must cover the whole position identity here (owner and kind), otherwise the compiler reports PICK_KEY_INCOMPLETE. A field that the query hydrating the collection already fixes (for example owner, when the scenario finds the giver's positions by a scalar key participant) may be left out of the key: pick givings by kind = line.kind. Everything else in this section is unchanged: the whole collection is locked in key order, elements no line picks included, and bounds apply after each leg.

The same expression reads one element in a calculate or check, replacing a loop that searches a collection:

atomic calculate tally(Slip, Slot[]) {
    for (SlipLine line : slip.lines) {
        Slot held = pick slots by owner = slip.giver and kind = line.kind;
        slip.total += held.rank * line.units;
    }
}

There the codes are PICK_MATCH_MISSING and PICK_MATCH_AMBIGUOUS. When the original logic takes one of several matches, say so with pick first or pick last; in a calculate or check a first/last pick that finds nothing leaves the local null. Run spp-basic explain PICK_KEY (or any code named here) for the rule and an example.

The finds that load the positions take no row locks. After the finds the transaction locks every position of both collections in the order of attribute then position key, so two slips moving between the same positions in opposite directions never wait on each other, however they find the two collections. A non-quantum fact changed by another transaction since the find is rejected at the write with PERSISTENCE_VERSION_CONFLICT; retry the scenario. A position is one object: key it once in its collection however many lines move it, and the legs that touch it accumulate on it. A key that occurs twice in a collection, or once in each of two collections, is rejected with QUANTUM_COLLECTION_IDENTITY_REQUIRED_OR_DUPLICATED.

Every position the call can debit needs an explicit bound at the call site, named by the scenario argument; write [null, null] when the debit has no limit. A missing entry is the compile error SPP_QUANTUM_BOUND_REQUIRED, and a credit-only position needs none. The limit belongs to the transaction, not the account, so the scenario reads it from the customer contract.

Bounds on the call, bounds { givings.pieces: [0, null]; }, are checked after each leg, so a later leg cannot repay a position an earlier leg overdrew. Any failure rolls back every leg of the slip. An endpoint must be a participant parameter or an element of a loop over a participant collection parameter. A local copy, an element of a local collection or of a collection that is a fact of another participant is refused with SPP_QUANTUM_LOOP_ENDPOINT. Run spp-basic explain with that code, or with QUANTUM_COLLECTION_IDENTITY_REQUIRED_OR_DUPLICATED or QUANTUM_BOUND_REJECTED, to read the rule and an example. An empty slip applies no transfer and is rejected. A boolean fact that nothing set is false in a generated model.

Bind a quantum role across domains

Declare the role and the transfer in the consumer SPP. The provider SPP defines its own position independently. In the consumer APP, select the provider and map the role fields to its position fields.

play ProviderPlayedRole by positions.Position {
    accountCode = account;
    currency = currency;
    claim = outstanding;
}

Here account and currency are the provider's primary key. The transfer into played.claim books Position.outstanding for that key. Deploy both domains in a LOCAL environment with one JDBC quantum store. To try a second provider, see the reserves.Reserve binding in the generated H2 sample. Each lookup checks both alternatives. One matching position supplies the balance. A missing position reads as zero and rejects transfers. An overlapping key is an error for both reads and transfers.

7. Add a custom technical service

The same example binds callCounter using APP:

technical services { callCounter; }
intercept services {
    before: callCounter;
    after: callCounter;
    failure: callCounter;
}

PHY selects its implementation:

phy {
    technical service callCounter {
        implementation: "example.technical.CallCounter";
    }
}

CallCounter.java implements the public TechnicalService interface. It observes service phases; it does not implement request replay or transaction coordination. Custom implementations are available in the open basic SDK. The SDK does not silently install this counter for other projects.

after means the method has returned. An inner service may still be inside its caller's transaction, and a business check may have rejected the operation. Do not treat every after callback as a database commit notification.

8. Choose additional facilities

The open basic SDK provides the language, business generator, public extension interfaces, basic persistence and optimistic conflict protection. Official request idempotency, scenario duplicate submission protection, change tracking, partial-update selection, invocation logging, automatic update scheduling and Seata integration are separate paid-edition implementations.

The built-in technical services manual explains their prerequisites, independent APP switches and transaction boundaries. The SDK user guide covers CLI automation, editor configuration, Java integration and troubleshooting. Reading those manuals does not require installing the paid implementations.

Download the tutorial and custom-service sample sources. Use them with the matching basic SDK source tree.