Skip to content

Architecture

A small core and a set of primitives, not a framework of features. Everything is built on the router's public methods.

edgetime is a small core and a set of primitives, not a framework of features. The core does little and is strict about it; everything else is built on its public methods, by the other packages and by your code in the same way.

The core is @edgetime/router: matching a request to handlers, running the middleware pipeline, carrying typed per-request values, and turning anything thrown into a response. It has no dependencies and knows nothing about logging, authentication, storage or any platform.

The primitives are the other packages. Each solves one problem, validates its settings when it is created, bounds what it reads and holds, and fails closed. None has access to the router that an application lacks, so anything they do, an application or a third-party package can do too.

A feature is added through one of these, without changing the core:

To add Write Install with
Behaviour around requests: auth, limits, headers, logging A middleware, (c, next) => Response use(), or on a route
A dependency handlers read: a client, the current user A provider factory provide(), perEnv()
A backing service: a limiter, a cache, a store An object with the methods the package calls An option, or env
A whole feature: routes with their middleware and providers An extension, (router) => void extend(), or mount() for a router
Your own error types and error format A mapping function errorHandler({ map, body })
Where logs go A sink function createLogger({ sink })
Another runtime An entry file that builds env and calls router.fetch —

These are left out on purpose, because each can be built on the above and one choice would not suit every service:

  • A schema library. validate() and parseJson() accept any Standard Schema validator.
  • Database, storage and queue clients. Describe what the routes call as a port and supply it from the entry file.
  • A dependency-injection container. provide() and perEnv() cover per-request and per-environment values.
  • A server-side session store. createSessionCodec() seals the cookie; pair it with your own store where sessions must be revocable.
  • Metrics and tracing exporters. Write a middleware or a log sink for the system you use.
  • API description generation, templating and static file serving.