Skip to content

    Reference03

    Conventions and generated files

    Every file the generator reads, what it must export, what it refuses or warns about, and what it writes.

    bounda generate reads app/domain and app/read by file and directory names, and looks for app/audit.ts; it imports no module. This page is the contract in one place. Project layout and Read models explain each kind of module with an example, and Names how a file name becomes the key and the type your code sees.

    Names are kebab-case. <x> is a name you choose.

    Path Exports
    app/domain/<aggregate>/state.ts optional: initialState, and aggregateId (the payload field holding the id)
    app/domain/<aggregate>/<event>.ts payload (optional), and begin for the event that opens the aggregate or evolve, or both; nothing else at run time
    app/domain/<aggregate>/<event>.upcast.ts upcasts, oldest version first, next to its event
    app/domain/<aggregate>/<port>.ts interface <Port>, named after the file; it is a port because infrastructure/<port>/ exists. For a port that sends personal data out, recipient, satisfies Port.Recipient, and the six handlers that tell it: onPersonalDataForgotten, onProcessingRestricted, onProcessingRestrictionLiftAnnounced, onProcessingRestrictionLifted, onPersonalDataRedacted and onTenantForgotten (see Recipients). For a port whose calls answer what can hold text, returnsPersonalData, satisfies Port.ReturnsPersonalData: whose personal data each call returns, or false (see personal data a port returns)
    app/domain/<aggregate>/infrastructure/<port>/<implementation>.ts export default ... satisfies <Port>, or create, typed as CreateImplementation<Port>
    app/domain/<aggregate>/commands/<command>.ts payload (optional), rejections (optional), handler
    app/domain/<aggregate>/policies/<action>-on-<event>.ts handler; on, delay and restricted, the basis it processes restricted data on, optional
    app/domain/<aggregate>/policies/<other-aggregate>/<action>-on-<event>.ts the same, for that aggregate’s events; bounda for the runtime’s own: PersonalDataForgotten, ProcessingRestricted, ProcessingRestrictionLiftAnnounced, ProcessingRestrictionLifted
    app/domain/<aggregate>/processes/<process>/index.ts config (startedBy, completedBy, timeout), state (optional), correlate (optional), restricted (optional, the basis it processes restricted data on)
    app/domain/<aggregate>/processes/<process>/on-<event>.ts handler
    app/domain/<aggregate>/processes/<process>/at-<deadline>.ts, at-timeout.ts handler
    app/domain/<aggregate>/processes/<process>/<other-aggregate>/on-<event>.ts handler, for that aggregate’s event
    app/audit.ts optional: onPersonalDataAccess, typed as OnPersonalDataAccess, where the access log goes, and onHostRejection, typed as OnHostRejection, where the host log goes; without it, the host’s logger
    app/personal-data.ts optional: categories, satisfies PersonalData.Categories, the categories of personal data with their basis, retention, purposes, sources, any special or criminal data, the purposes the GDPR has rules for and an exemption from erasure they claim, and automatedDecisions, satisfies PersonalData.AutomatedDecisions, {} for none; without it, every personal field is in the default category
    app/read/<read-model>/view.ts fields; .person() on at most one field, .personal() on those that hold that person’s data, .notPersonal() on those that hold none; holdsPersonalData = false (optional) to state it keeps nothing of anyone’s data though it projects events with personal fields
    app/read/<read-model>/projections/<aggregate>/<event>.ts project; on optional
    app/read/<read-model>/projections/bounda/personal-data-forgotten.ts project, required once its view keeps a field in the clear with .personal({ clear: true }), or a projection of the read model sees a field marked personal and the view marks no field .personal()
    app/read/<read-model>/projections/bounda/processing-restricted.ts, processing-restriction-lift-announced.ts, processing-restriction-lifted.ts project, optional
    app/read/<read-model>/queries/<query>.ts payload (optional), repository (optional), handler
    app/read/<read-model>/<port>.ts, infrastructure/<port>/<implementation>.ts as in an aggregate, recipient, its handlers and returnsPersonalData included; only the queries’ handler receives them

    Any other module or directory at the root of an aggregate or a read model is yours: a value object, a domain service, a helper the handlers import. The generator leaves it alone, and so it does files that start with _ or ., tests (*.test.ts, *.test-d.ts), declarations (*.d.ts) and +types directories.

    bounda generate fails, naming the file and saying what to do, for:

    • a name that is not kebab-case, or a file that is not a .ts module where modules go;
    • a command or a policy that is a directory, a process that is a file, a process directory without index.ts, a read model without view.ts, a projection or a query that is a directory;
    • a projection outside a folder named after an aggregate of the app, or after bounda with a name that is no event of the runtime’s; an aggregate named bounda;
    • a process handler not named on-<event>.ts or at-<deadline>.ts, or one for an event its aggregate does not have;
    • a module at an aggregate’s root that exports an event’s function (payload, begin, evolve) and something else besides, and an <event>.upcast.ts with no event next to it;
    • a port’s module that exports a recipient’s handler and no recipient;
    • a port whose module does not export an interface or a type alias named after it, a port directory with no implementation or with subdirectories, an implementation with no port, and a port named after an event of its aggregate or after a reserved name: command, state, events, event, commands, idempotencyKey, signal, aggregateId, after, reject, forget in an aggregate, and view, query, repositoryData, table, queries, actor in a read model;
    • a policy and a process of one aggregate with the same key (policies/checkout.ts next to processes/checkout/, or policies/payment-refund-on-payment-failed.ts next to policies/payment/refund-on-payment-failed.ts), a policy named after an aggregate, a policy folder named after the aggregate it is in, and a read model named like an aggregate;
    • two commands, or two queries, with the same key anywhere in the app: app.commands and app.queries are one namespace each;
    • an aggregate or a read model whose generated types would meet others in .bounda/types.ts: one named test (TestPorts is Bounda’s own), or order-created next to order.

    Some rules are checked by the compiler rather than the generator, at the <ReadModel>Forgetting type of .bounda/types.ts, which says what to add: a read model that keeps a field in the clear with .personal({ clear: true }), or projects an event with a field marked personal and marks no field .personal(), and has no projections/bounda/personal-data-forgotten.ts; one that marks a field .personal() and none .person(); one that projects an event with a field marked personal and marks no field .person() without its view exporting holdsPersonalData = false, or one that exports it and marks a field; one that marks two fields .person(). <Aggregate>Classification and <ReadModel>Classification fail to compile while a top-level field of an event’s or a command’s payload or of a process’s state that can hold text is marked neither personal, person nor notPersonal, while a string column, or a json one whose value can hold text, is marked neither .personal(), .person() nor .notPersonal(), and while a payload or a state is not an object or keeps keys it does not declare, naming each (fields that hold no personal data). <Module>PortReturns fails to compile while a port answers what can hold text and its module does not export returnsPersonalData, or exports one that does not fit the port (personal data a port returns). The app refuses to start on the same rules, with ConfigurationError. The generated registry is checked against Registry, so an app/audit.ts whose onPersonalDataAccess is not an OnPersonalDataAccess, or whose onHostRejection is not an OnHostRejection, fails to compile there. PersonalDataDeclaration fails to compile while app/personal-data.ts declares a category named default, or one without a basis Bounda knows, a retention, a purpose or a source, or with special or criminal data without a kind, condition or authority Bounda knows, or with a purpose in processedFor or an erasureExemption Bounda does not know; special data on archiving-research-or-statistics without a purpose of article 89(1) in processedFor; an erasureExemption that does not apply, on consent, public-health without special data on health-or-social-care or public-health, or archiving-research-or-statistics without a purpose of article 89(1); or a category an exemption of article 17(3) keeps past a forgetting whose special data rests on explicit-consent, or that is processed for direct-marketing; while it exports no automatedDecisions, or one of them lacks what it must say, names a category the file does not declare, or decides on special data on a condition other than explicit-consent or substantial-public-interest, or without its measures (article 22(4)), and a category that personal({ category }), .personal({ category }) or forget names and the file does not declare does not compile where it is written. <Owner>Recipients fails to compile while a port’s module declares a recipient and lacks one of its six handlers, naming the port and the event it tells, or while a method of the port answers something other than a promise; a recipient whose country is outside the European Economic Area and names no safeguard, or one inside that names one, a kind the GDPR does not name, a country that is no ISO 3166-1 code or a category the app does not declare does not compile at its satisfies Port.Recipient. See Personal data in read models.

    Some rules need the modules themselves, so the app checks them when it is created and throws a ConfigurationError:

    • a policy or a projection whose trigger is not an event of the aggregate it listens to, the runtime’s own bounda included; an event, a command or a process state that marks two fields with person, and a process state that starts with a personal or person field set; a field given two of personal, person and notPersonal; a field or a column that can hold text and has none of them, and a payload or a state that holds text out of a mark’s reach;
    • a deadline() field without its at- file, and an at- file without its field; the name timeout is reserved for the process’s lifetime;
    • an event of another aggregate that a process listens to and cannot assign to an instance, by an id field in its payload or by correlate;
    • a policy and a process that share a key;
    • a read model that marks two fields .person(), marks a field .personal() and none .person(), or keeps a field in the clear with .personal({ clear: true }) and does not project PersonalDataForgotten; one that seals its primary key, or names a field like the columns the runtime keeps beside personal ones, ending in __key or __index;
    • an app/audit.ts that does not export onPersonalDataAccess and onHostRejection as functions;
    • a port that declares a recipient without a name, a kind the GDPR names, an ISO 3166-1 country, the safeguard a transfer out of the European Economic Area rests on (and none within it) or categories the app has, or without one of its six handlers; one that has no implementation; a recipient.formerly key that is not "<aggregate or read model>.<port>", that is a port of the app, or that two ports name;
    • a port whose returnsPersonalData is neither false nor an object, declares a call without a persons function, with a personsOnError that is no function, or with categories the app does not have, or that has no implementation;
    • an app/personal-data.ts whose categories is not an object, declares default, names a category with anything but letters, digits, - and _ after a first letter, or gives one a basis article 6 does not name, a retention that is not a duration longer than none, no purpose in words or a source Bounda does not know, special data without kinds of article 9(1) or a condition of article 9(2), criminal data without an authority of article 10, a processedFor without purposes Bounda knows, special data on archiving-research-or-statistics without a purpose of article 89(1), an erasureExemption Bounda does not know or that does not apply, or a category an exemption of article 17(3) keeps past a forgetting with special data on explicit-consent or processed for direct-marketing; whose automatedDecisions is not an object, or has a decision without categories it declares, a logic, significance or consequences in words, a profiling that is true or false, or a ground article 22(2) names, measures that are not in words, or one on special data whose condition is neither explicit-consent nor substantial-public-interest, or that gives no measures; a field marked personal in a category the file does not declare;
    • a payload, repository, process state or correlate export that is not a function;
    • a configuration that names a port, an implementation, an aggregate or a read model that does not exist, or leaves out a port that has several implementations.

    Mistakes that leave the layout valid but would leave a module unregistered are warnings, printed and not failed on:

    • a module at an aggregate’s root that imports its own +types without exporting payload, begin or evolve: an event that lost the export that made it one (a leftover apply, a typo in evolve);
    • a directory one letter away from commands, policies, processes or infrastructure, or named command, policy, process or infra;
    • in a read model, a directory one letter away from projections, queries or infrastructure, or named projection, query or infra, and a module at its root that exports project, repository or handler;
    • a policy or a projection that exports no on and whose name gives no event of its aggregate, which boot refuses: most likely a misspelt event.

    bounda generate writes:

    Path Holds
    .bounda/registry.ts Every module, grouped as the runtime needs it, and app/audit.ts as audit and app/personal-data.ts as personalData when there are. boot() imports it
    .bounda/register.d.ts Registers the registry type, the type of the ports section and the names of the categories of personal data with @bounda-dev/core/register, so boot() and BoundaApp are typed for the project without a type argument, defineConfig checks the implementation names, and personal({ category }) and forget check the categories
    .bounda/types.ts The state, events, ports, commands, rows and queries maps the +types build on, how each read model stores its fields (<ReadModel>FieldTypes, which decides what its table filters each field by), one <ReadModel>Forgetting check per read model, one <Aggregate>Classification and one <ReadModel>Classification check per aggregate and read model, one <Owner>Recipients check per aggregate or read model whose ports declare recipients, one <Owner>PortReturns check per aggregate or read model with ports, PersonalCategory, the names app/personal-data.ts declares, and its PersonalDataDeclaration check
    **/+types/<name>.ts The argument types each module imports; a port’s: Port.ReturnsPersonalData, and, when it declares a recipient, Port.Recipient and its handlers’ arguments. An implementation has none: it imports its port

    They are derived from your code, so they are not versioned. tsconfig.json must include them as .bounda/**/* (TypeScript skips a bare .bounda entry because the directory starts with a dot); create-bounda sets this up. Add to .gitignore:

    .bounda/
    **/+types/

    and run the generator before anything type-checks, typically as prepare in package.json:

    JSON
    { "scripts": { "prepare": "bounda generate", "dev": "bounda generate --watch" } }

    If your formatter or linter picks up generated files, exclude the same two patterns; their layout is fixed by the generator. bounda generate has the command’s options.