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
Section titled “The core”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
Section titled “The primitives”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.
Extension points
Section titled “Extension points”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 |
— |
What is not built in
Section titled “What is not built in”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()andparseJson()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()andperEnv()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.