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.
Files and what they export
Section titled “Files and what they export”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.
What the generator refuses
Section titled “What the generator refuses”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
.tsmodule 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 withoutview.ts, a projection or a query that is a directory; - a projection outside a folder named after an aggregate of the app, or after
boundawith a name that is no event of the runtime’s; an aggregate namedbounda; - a process handler not named
on-<event>.tsorat-<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.tswith 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,forgetin an aggregate, andview,query,repositoryData,table,queries,actorin a read model; - a policy and a process of one aggregate with the same key (
policies/checkout.tsnext toprocesses/checkout/, orpolicies/payment-refund-on-payment-failed.tsnext topolicies/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.commandsandapp.queriesare one namespace each; - an aggregate or a read model whose generated types would meet others in
.bounda/types.ts: one namedtest(TestPortsis Bounda’s own), ororder-creatednext toorder.
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.
What boot refuses
Section titled “What boot refuses”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
boundaincluded; an event, a command or a processstatethat marks two fields withperson, and a processstatethat starts with apersonalorpersonfield set; a field given two ofpersonal,personandnotPersonal; 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 itsat-file, and anat-file without its field; the nametimeoutis 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 projectPersonalDataForgotten; one that seals its primary key, or names a field like the columns the runtime keeps beside personal ones, ending in__keyor__index; - an
app/audit.tsthat does not exportonPersonalDataAccessandonHostRejectionas functions; - a port that declares a
recipientwithout 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; arecipient.formerlykey that is not"<aggregate or read model>.<port>", that is a port of the app, or that two ports name; - a port whose
returnsPersonalDatais neitherfalsenor an object, declares a call without apersonsfunction, with apersonsOnErrorthat is no function, or with categories the app does not have, or that has no implementation; - an
app/personal-data.tswhosecategoriesis not an object, declaresdefault, 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,specialdata without kinds of article 9(1) or a condition of article 9(2),criminaldata without an authority of article 10, aprocessedForwithout purposes Bounda knows, special data onarchiving-research-or-statisticswithout a purpose of article 89(1), anerasureExemptionBounda does not know or that does not apply, or a category an exemption of article 17(3) keeps past a forgetting with special data onexplicit-consentor processed fordirect-marketing; whoseautomatedDecisionsis not an object, or has a decision without categories it declares, alogic,significanceorconsequencesin words, aprofilingthat is true or false, or a ground article 22(2) names,measuresthat are not in words, or one on special data whose condition is neitherexplicit-consentnorsubstantial-public-interest, or that gives nomeasures; a field marked personal in a category the file does not declare; - a
payload,repository, processstateorcorrelateexport 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.
What the generator warns about
Section titled “What the generator warns about”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
+typeswithout exportingpayload,beginorevolve: an event that lost the export that made it one (a leftoverapply, a typo inevolve); - a directory one letter away from
commands,policies,processesorinfrastructure, or namedcommand,policy,processorinfra; - in a read model, a directory one letter away from
projections,queriesorinfrastructure, or namedprojection,queryorinfra, and a module at its root that exportsproject,repositoryorhandler; - a policy or a projection that exports no
onand whose name gives no event of its aggregate, which boot refuses: most likely a misspelt event.
Generated files
Section titled “Generated files”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:
{ "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.