Part of [Architecture](https://docs.mapcairn.com/architecture.md), which is built from [ARCHITECTURE.md](https://github.com/MapCairn/mapcairn/blob/main/ARCHITECTURE.md) in the repository, where it is edited.

An adapter reaches the ui through the services. Arrows run from the port towards the code that uses it.

```mermaid
flowchart TD
  port["SearchProvider<br/>port, in packages/core"]
  adapter["NominatimSearchProvider<br/>in packages/web/src/adapters"]
  create["createServices()<br/>real adapters, then the test seam,<br/>then options.overrides"]
  provider["ServicesProvider<br/>in routes/app.tsx"]
  hook["useSearch, useSettings, ...<br/>hooks in packages/map"]
  port --> adapter
  adapter --> create
  create --> provider
  provider --> hook
```

1. Define or extend the port in `packages/core/src/ports`, with typed errors and an `AbortSignal` on async calls.
2. Write the fake in `packages/core/src/fakes` and the contract suite in `packages/core/src/contracts`.
3. Write the real adapter in `packages/web/src/adapters`, passing the same suite. Helpers that more than one adapter uses (reading media queries, fetching and reading JSON) live in `packages/web/src/adapters/shared`. The MapLibre adapter is the exception: it is the package `packages/adapter-maplibre`, which depends on `core` and `theme` only, keeps its event emitter beside it, and runs the same contract suite over a scripted engine.
4. Register it in `createServices()`. An optional port whose data belongs to the host, as the selection and the feature query do, is not built there: list it in `HOST_SUPPLIED_PORT_NAMES` (`packages/core/src/contracts/portRegistry.ts`) and the host supplies it.
5. Read it in the ui through a typed hook (`useSettings`, `useSearch` and so on).
