02. Decisions
Every architectural decision, with the runner-up and why it lost. The runner-up is recorded so nobody relitigates it from scratch 6 weeks in.
Changing a decision here means updating the doc it governs. Don't change one silently in code.
Language and Runtime
D1. TypeScript Only
strictplusnoUncheckedIndexedAccess- no JavaScript escape hatch
- no
anyin public surfaces
any is permitted only at a vendor boundary inside a driver package, with a comment naming what it bridges.
D2. Bun by Default
Bun runs install, dev, build, test, the CLI, and the Vercel function runtime.
Runner-up: Node by default with Bun optional. It loses the zero-config TypeScript execution that makes the CLI and generators pleasant.
Constraint: @avelonjs/core and @avelonjs/orm may never import bun:*, so Bun is the default and not a requirement. See 11-runtime.md.
D3. Prettier for Formatting
Shipped config, zero decisions for the user.
Runner-up: Biome, which is faster and does lint plus format in one pass. Revisit if Prettier becomes the slow step in CI.
Formatting isn't worth a debate, which is the entire point of shipping a config.
Portability
D4. Adapter-First Core
Only the Next adapter ships in v1.
Runner-up: Next-only, which was v1 of this spec. It lost because Next reinventing its conventions every major version is the single largest risk in the project, and adapter-first is the only structural hedge.
Cost: roughly 15 to 20% more upfront design, and the discipline to keep Next types out of core.
D5. A Throwaway Second Adapter During M0
Roughly 200 lines of Hono, serving the same controllers, never shipped.
An abstraction with one implementation is a guess. This is the only cheap way to find out whether the contract is secretly Next-shaped.
D6. Drivers for Every External Service
Driver-first covers every external service, the database included.
Runner-up: drivers for the database only. It lost because:
- the same lock-in argument applies to auth, storage, queue, mail, and everything else
- a driver system built for one capability never generalizes cleanly afterward
See 04-drivers.md.
D7. Capability Narrowing at Compile Time
A driver declares capabilities as literal types and the facade narrows. NotSupportedError is banned. Verified working against tsc in strict mode.
Runner-up: runtime feature detection, with optional methods plus runtime throws. That turns every driver swap into a runtime bug hunt.
Structure
D8. Domain Directories Colocate Inside Next's app/
These sit at the paths the directory map promises:
app/Modelsapp/Http/Controllersapp/Policies
The generated router lives in app/(web) and app/(api).
Runner-up: the Next router at src/app with domain code at root. It fails because Next prefers root app/ when both exist. The domain directory would need renaming, and the map that motivates the project is lost.
D9. Writes Are Generated Server Actions
A route marked .api() also generates a route handler.
Runner-up: route handlers plus _method spoofing everywhere. It keeps the real request lifecycle, but it:
- moves write URLs off the resource paths
- gives up the
useActionStateerror round trip
Next can't serve a page and a POST handler at the same path. People expect POST /posts to sit where GET /posts is, so writes move off the URL entirely.
D10. app/Actions/ for Single-Purpose Use Cases
Controllers stay thin. A named directory for one-shot work keeps them that way, without inventing a service layer nobody agrees on.
D11. app/Wards/ Is a Sibling of app/Policies/
2 different questions get 2 different directories. See 06-authorization.md.
Data
D12. The Model Layer Produces a Query IR, Drivers Compile It
The IR is serializable.
Runner-up: building directly on the driver's query builder. That leaks vendor quirks into application code and makes a second database driver a rewrite instead of a package.
This is the one decision that can't be reversed later without touching every model, which is why it moves into M0.
D13. Migrations Are Driver-Owned
The contract is:
planapplyrollbackstatus
The Supabase driver emits SQL into one Supabase-compatible history.
Runner-up: a hand-rolled schema builder DSL. Highest parity, and every Postgres type, index, constraint, and policy would need a wrapper maintained forever. Deferred, not rejected.
D14. Row Access Is Declared Once as a Ward and Enforced Twice
- compiled to RLS where the driver supports it
- applied as a query predicate everywhere
Runner-up: writing RLS by hand and documenting it. That's what everyone does today, and it's why RLS bugs are data leaks instead of test failures.
D15. @avelonjs/postgres Ships in v1
It ships alongside @avelonjs/supabase. Revised from v2, where it was deferred.
Reason: a driver-first framework shipping one driver per capability invites exactly the criticism it was built to avoid. Supabase-only also means the first impression is "no transactions." Shipping 2 real database drivers is the only thing that proves the abstraction.
Behavior
D16. Events Are Sync, Ordered, and Stoppable
Sync and ordered by default, with opt-in after and queued delivery.
Runner-up: always-async, which breaks the mental model where a listener can veto an action. See 07-events.md.
D17. No Dependency Injection Container
A typed service registry for driver swapping, plus providers for registration.
Runner-up: a full IoC container. It lost on:
- indirection that JavaScript developers reject
- TypeScript generics making
resolve<T>()unpleasant
Providers stay because they let a third-party package register listeners and policies without touching your code.
D18. Third-Party Packages Register Through Providers
Providers are listed explicitly in config.
Runner-up: auto-discovery from package.json. That's magic that breaks tree-shaking and makes "why is this route here" unanswerable.
Product
D19. Scoped npm Packages Plus create-avelon
The framework is a dependency, not vendored source.
Runner-up: vendoring framework/ into the template. Hackable, no version skew, and you can never ship a fix.
D20. Server Components With a view() Helper
- Tailwind 4
- no bundled UI kit
reeve ui:installadds a component library if the user wants one
Runner-up: shadcn preinstalled. That's an opinion that ages badly, and one most teams override anyway.
D21. bun test as the Test Runner
Framework helpers and fakes sit on top. It's fast enough to run on save, which is the only property that matters for whether tests get written.
D22. Greenfield Only in v1
No adapter for dropping into an existing Next app.
Runner-up: that adapter. It doubles the compatibility surface before anyone has used the framework once.
D23. Bare reeve Opens a TUI
Subcommands with arguments stay fully scriptable and skip the TUI entirely. See 08-cli.md.
D24. Tooling Enforces Documentation Conventions
The conventions are enforced by tooling instead of requested in a contributing guide. See 10-conventions.md.
Revisions From M0
The M0 spike (see .avelon/checkpoints/checkpoint-1.md) did 2 things:
- disproved assumption 6 and assumption 5 as originally drafted
- left assumption 3 unverifiable without live Vercel access
D25 to D27 resolve those findings. They were made under delegated ownership after Checkpoint 1.
D25. The Query IR Defines Its Own Semantics
Nothing is left to compiler judgment:
CompareOpandRelationLoadare exported concrete typeswhere: Predicate[]composes with ANDwardis ANDed withwhere- upsert requires an explicit conflict target and update column list
- a
constpredicate kind expresses always-true and always-false - a
const falseward short-circuits without a database round trip
Empty boolean and list predicates normalize by identity:
and: []is trueor: []is falsein: []matches nothing
See 05-database.md.
Runner-up: rejecting underdefined shapes at the builder with nonempty tuple types. That pushes the burden onto every machine producer of IR and makes normalization a per-driver behavior, which is exactly the divergence the IR exists to prevent.
D26. Write Routes Are Transport-Neutral and Views Are Opaque References
For write routes:
Route.post()describes a write action- the Next adapter serves it as a generated server action
- an adapter without server actions mounts an ordinary POST route for the same controller
- the
serverActionscapability selects the transport. It doesn't gate the route's existence
For views:
ViewResult.viewis an opaque reference that core never inspects- the configured adapter both accepts and renders it
- under Next it's an RSC component import. Under other adapters it's whatever their renderer resolves
Adapters delegate the request pipeline to the core kernel instead of reimplementing it. The pipeline is middleware, binding, validation mapping, and exception mapping.
Runner-up: the v2 wording. In it, serverActions: false made Route.post() a generation error, and the view example implied a concrete RSC contract.
The M0 Hono spike showed both are Next-shaped. They make every non-Next adapter incapable of serving writes and views that Hono demonstrably serves.
D27. Node Is the Default Deployed Function Runtime
Bun stays the default everywhere else. Install, dev, build, test, and the CLI run on Bun, all verified locally in M0.
The deployed function runtime defaults to Node because Bun-on-Vercel couldn't be verified against a live deployment. A prescriptive framework doesn't ship an unverified default.
bunVersion remains a documented one-line opt-in. It gets promoted to default when a live Vercel verification passes.
This supersedes the function runtime clause of D2. See 11-runtime.md.
Runner-up: keeping Bun as the function runtime default per documentation alone. That trades a support-ticket-shaped risk for no user-visible benefit until verified.
D28. Storage Ships a Narrow v1
Storage ships these in v1:
- upload
- download
- delete
- signed read URLs
Signed upload URLs and list() are deferred.
This was recorded at the S2 freeze because StorageCapabilities keys are required literals. Adding one later is a breaking change for every driver author, and this is the most likely place the frozen contract comes under pressure.
Client-direct upload is a real need on platforms with request body limits. Until a capability key exists, the answer is raw() inside app/Drivers/. That's deliberately non-portable and leaves a searchable trail.
Runner-up: adding signedUploads and listing capability keys now. Rejected because:
- neither has a v1 driver to prove the shape against
- a capability invented without an implementation is the guess this framework exists to avoid
An agent that hits the limit escalates instead of improvising.
S2 Freeze
The contracts in @avelonjs/core are frozen as of the commit tagged s2-contract-freeze.
No package may edit a contract to make itself compile, by any route, including widening a type or casting through unknown. A package that can't be built against a contract as written has found a contract bug. It stops and reports.
Left to the Conformance Suites
4 items are deliberately unpinned at the type level. They belong to the conformance suites, which were written before any driver:
How a request-scopedPinned by the identity conformance suite asRequestCookiesreaches a config-time identity driver factory.(cookies: RequestCookies) => TDriver, a synchronous config-time factory taking request-scoped cookies explicitly.- Asynchronous driver setup defers into the driver's own methods.
- Chosen over an ambient request context because cookie scope stays explicit and independently testable.
- Chosen over an async factory because a per-request
awaitbefore every identity call is a cost paid on the hot path forever.
Pinned by the database suite. See the next section.countresult edges: whatrowsandaffectedcontain, and whetherselect: '*'is accepted as equivalent to empty.ThePinned by the queue conformance suite: the job is dropped after its first delivery attempt.drainthrow path when a driver declaresretries: false.- Redelivering would secretly implement retries the driver declared it doesn't have, and could wedge every later drain behind a job that always fails.
- A retry-disabled but dead-letter-capable driver may still record the terminal failure. It may not redeliver it.
rawBody()on a transport with no wire bytes, such as a server action.
Pinned by the Database Suite
The database suite has since pinned 3 of its own. They're recorded here so drivers don't relitigate them:
- A count result carries
rows: [],affected: 0, andcount: n. Counting selects no rows and mutates none. select: '*'on a count is rejected. Requiring an explicit empty projection catches a leaked query-builder default, at the cost of one explicit field.rpc()against a routine that doesn't exist raisesInvalid, notNotFound, carrying the routine name in metadata.
NotFound maps to a 404 in the central handler. A missing stored procedure is deployment drift rather than a missing page, and surfacing it as 404 would hide a broken deploy.
NotFound in Database Conformance
NotFound is deliberately absent from database conformance. The contract has no must-exist operation. That concern belongs to the model layer, where findOrFail owns it.
Empty Eager-Loaded Relations
An eager-loaded relation that matches nothing is present, not absent:
belongsToandhasOnekeys arenullhasManykeys are[]
The database suite pins this because Scrivener consumes the shape. A driver omitting the key entirely would force every caller into an existence check the contract never asked for.
Named Instances
Named-instance selection belongs to config resolution and the facade, not to a driver:
- a driver is one instance and reports it as
instance Storage.disk('archive')resolves against the{ default, disks }style registry inavelon.config.ts
Config resolution and the facade own resolving a name and rejecting an unknown one. The tests cover the unknown-name case, because a silent fallback to the default sends real mail from the wrong identity.