Concepts
iwentsourcing stores what happened, as events, and derives everything else from them. You design the events and the state they produce. The platform runs the rest: the API, the workers, the live sync and the history.
flowchart LR
client["Client or CLI"] -->|push event| stream
subgraph platform["Platform"]
stream["Stream<br/>(event log)"] -->|handle| state["State<br/>(queryable)"]
stream -->|inject event| agg["Aggregation<br/>(read model)"]
end
state -->|snapshot / observe| client
agg -->|snapshot / observe| clientEvent
An event is an immutable record of something that happened: a key like create-todo, a typed payload, an id and a timestamp. Events are the only source of truth. They are never changed or deleted, so the log is also your audit history.
Good events describe the fact in the language of your domain (order-shipped, not order-updated) and carry the data you will want later. Spend your design time here.
Stream
A stream is an append-only log of events for one identity, decided by its pattern. Each event pushed to a stream runs through its handle function, which updates the stream's state. Every stream instance is independent, with its own log and its own state.
Pattern
A pattern splits one stream definition into many instances. personal-$(auth.sub) gives every signed-in user a stream of their own, group-$(args.groupId) gives every group one. The variables come from the signed-in user ($(auth.sub), $(auth.iss), $(auth.aud)) or from arguments the client passes ($(args.name)).
Instances are the unit of access and of parallelism: a user can reach the instances that resolve from their own login, and different instances are processed side by side without waiting for each other.
State
State is the queryable snapshot a stream or aggregation currently knows: typed tables with a primary key and optional indexes. A handle is the only place that changes it. State is never the source of truth, because it can always be rebuilt from the events. That makes it cheap to change your mind: change the handle, replay, and the state follows.
Handle and output
A handle receives one event and a context, and changes the state. It runs the same way live and on replay.
An output is produced inside a handle with ctx.output(key, data). Outputs are not stored in the event log and are not replayed, which makes them the place for effects that must happen once, such as sending an email.
Aggregation
An aggregation is a read model across streams. It subscribes to events (or outputs) of one or more streams and builds a state of its own, in whatever shape the reads need: all todos of a team, totals per month. An aggregation can only subscribe to streams of its own realm.
Realm
A realm is the authentication namespace. It lists the identity providers it trusts (username and password, Google, Microsoft, GitHub Actions) and groups the streams and aggregations that share those users. A realm belongs to a tenant, and its users sign in with a token issued for that realm.
Tenant
A tenant is the top-level boundary. Realms, streams, events and state all live inside one tenant and are isolated from every other. The same code can be deployed to several tenants, for example dev, staging and production.
Developers have a login of their own on the platform's directory. It is not bound to a tenant: the same login creates tenants, uploads definitions and inspects any tenant you are a member of.
Audit and replay
Because events are never changed, the event log is a complete audit history without any extra code: what happened, in which order, by which identity. Replaying the log through the handles rebuilds the state from nothing, which is how a new handle or a new aggregation gets its data. Read the log with aion stream events, see Inspect with the CLI.
Client and browser
@iwentsourcing/client talks to the API from Node or the browser: sign in, push events, read state, and observe it live. @iwentsourcing/browser adds storage in IndexedDB and a local runtime, so a stream can run in the browser and sync with the server, and the app keeps working offline.
Registry and manifesto
Your definitions reach the platform as a manifesto: the serialised streams, aggregations and realms, with their bundled code. aion upload registers it with the registry of a tenant. Every version is kept, and an upload that would break the schema of existing state is refused.
The registry also keeps each realm's latest definition, which the management UI edits and uploads again the same way. Secrets in it read as stored(): a definition that names stored() keeps the secret the registry already has for that provider. An auth provider is never left out of a later upload, as its users and sessions belong to the realm. Set disabled: true instead: it stays in the definition, but no one signs in with it and its tokens are no longer accepted.