-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add architecture documentation (#599)
* Add docs on architecture. * Add opening remark. * Add to index * Add headings, and copyedits Co-authored-by: Padraic Shafer <76011594+padraic-shafer@users.noreply.github.com> * MyST cannot resolve reference to target that is later in document? * Explicit targets for architecture docs links * https://myst-parser.readthedocs.io/en/latest/syntax/cross-referencing.html#creating-explicit-targets * Hint in sphinx config for adding Myst config options * Strip -target for friendlier archor fragments. * Add -arch to scope the anchor to this document. * Add links to further reading --------- Co-authored-by: Padraic Shafer <76011594+padraic-shafer@users.noreply.github.com> Co-authored-by: Padraic Shafer <pshafer@bnl.gov>
- Loading branch information
1 parent
4ef1716
commit 8ae226b
Showing
10 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# Architecture | ||
|
||
This is an overview of the major components of Tiled. | ||
|
||
(client-arch)= | ||
## Client | ||
|
||
Tiled ships with a Python client. This is separable from the rest of the | ||
project, and could potentially someday be split off as a separate package. The | ||
client enables the user to navigate and access the data in a Tiled server using | ||
familiar Python item-lookup and slicing idioms, while it generates HTTP | ||
requests to transfer metadata and data. | ||
|
||
(connection-context-arch)= | ||
### Connection _Context_ | ||
When the user connects, a **Context** object is created. The Context is | ||
shared by all client-side objects that use this connection. It wraps an | ||
[httpx HTTP client][httpx], which in turn wraps an HTTP connection pool and (if | ||
applicable) authentication-related state---either an API key or a pair of | ||
OAuth2 access and refresh tokens. | ||
|
||
Further Reading: | ||
* [`Context` reference](#context-ref) | ||
|
||
(client-side-caching-arch)= | ||
### Client-side _Caching_ | ||
The Context also may hold an HTTP response **Cache**, similar to a web | ||
browser's cache. This is currently not enabled by default because it is | ||
experimental. | ||
|
||
Further Reading: | ||
* [Client HTTP Response Cache overview](#client-http-response-cache) | ||
* [`Cache` reference](#client-http-response-cache-ref) | ||
|
||
(server-arch)= | ||
## Server | ||
|
||
The Tiled HTTP server is built using the framework [FastAPI][], which is built | ||
on [Starlette][]. A key feature of FastAPI is auto-generated [OpenAPI][] | ||
documentation, which Tiled serves at the `GET /docs` endpoint. FastAPI | ||
works with [Pydantic][] to parse and validate requests. | ||
|
||
(authentication-arch)= | ||
### Authentication | ||
Most endpoints require authentication, unless the server is configured to be | ||
public. For single-user deployments, a single API key is specified or randomly | ||
generated at server startup. For multi-user deployments, an **Authentication | ||
Database** (PostgreSQL or SQLite) is used to store session information and to | ||
validate API keys. | ||
|
||
Further Reading: | ||
* [Security](#security) | ||
* [Login Tutorial](#login-tutorial) | ||
* [Authentication Details](#auth-details) | ||
* [Tiled Authentication Database](#tiled-authn-database) | ||
|
||
(accessing-data-and-metadata-arch)= | ||
### Accessing Data and Metadata | ||
Endpoints that serve metadata or data resolve the URL path to identify the | ||
relevant [**Adapter**](#adapter-arch), which returns the data | ||
as a scientific data structure. It may be a "lazy" data structure, | ||
representing data that will be loaded later -- on demand and piecemeal. | ||
|
||
(content-negotiation-and-serializers-arch)= | ||
### Content Negotiation and _Serializers_ | ||
The endpoint implements [content negotiation][], comparing the list of requested formats | ||
that are accepted by the client to those supported by the server for this particular | ||
dataset. It dispatches to a registry of **Serializers**, which convert the data | ||
structure into bytes which can be sent in a response by FastAPI. Custom | ||
serializers may be registered during server configuration. | ||
|
||
Further Reading: | ||
* [Custom Export Formats](#custom-export-formats) | ||
* [Media Type Format Registry reference](#media-type-registry-ref) | ||
|
||
(compression-arch)= | ||
### Compression | ||
On its way, the response may be compressed, again using content negotiation | ||
to compare the list of compression schemes supported by the client (if any) | ||
to those the server deems appropriate to the dataset. | ||
|
||
(adapter-arch)= | ||
## Adapter | ||
|
||
In Tiled, an **Adapter** provides a standard interface to data, regardless of | ||
how it is stored. Adapters that wrap different structure have different | ||
interfaces. For example, an array adapter implements `read_block` whereas a | ||
table adapter implements `read_partition`. But all array adapters are alike, | ||
and all table adapters are alike. They enable the server to abstract over | ||
the details of _how_ to get the data. | ||
|
||
Typically Adapters take a filepath or URI and, perhaps, some additional | ||
configuration. For development, test, or demonstration purposes, Adapters can wrap | ||
in-memory data, such as a numpy array. Several Adapters are included in the Tiled | ||
codebase, in the spirit of "batteries included," but Adapters can be defined in | ||
external modules, too, and operate on the same footing as the built-in ones. | ||
|
||
Further Reading: | ||
* [Adapters](#adapters-ref) | ||
|
||
(catalog-arch)= | ||
## Catalog | ||
|
||
The Catalog is an Adapter that stores the metadata and structure for a | ||
potentially large number of datasets in a SQL database (PostgreSQL or SQLite). | ||
This enables it to efficiently respond to _metadata_ requests and _search_ | ||
requests without opening any data files. Requests for _data_ are then | ||
dispatched down to the appropriate [Adapter](#adapter-arch) which can load the data | ||
from the given storage medium and format. | ||
|
||
Not all Tiled servers are configured to use the Catalog: | ||
|
||
* Demo deployments wrapping a handful of datasets use data Adapters directly, | ||
with no need for a database. | ||
* Specialized deployments with custom Adapters may use a custom database or | ||
external service. | ||
|
||
But for most standard applications, including serving a directory of files or | ||
providing a writable data store, the Catalog is used. | ||
|
||
[FastAPI]: https://fastapi.tiangolo.com/ | ||
[httpx]: https://www.python-httpx.org/ | ||
[Starlette]: https://www.starlette.io/ | ||
[OpenAPI]: https://www.openapis.org/ | ||
[Pydantic]: https://docs.pydantic.dev/ | ||
[content negotiation]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Content_negotiation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
(auth-details)= | ||
# Authentication Details | ||
|
||
See {doc}`../explanations/security` for an overview. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters