Reading diagrams / Topic 26 of 42

Libraries: plugs and what fills them

The rule

A library often defines a record of functions, a port, and several definitions that fill it: one for tests, one for production. The map draws a port as a teal plug strip above the rack, with one plug per definition.

A filled plug is used: an arrow names the definition that plugs it in, such as “← test_deps”. A hollow plug, marked “← nothing”, is defined but used by nothing in the program.

A port is not a resource. cosmic-python's Repository strip stands above a struck database: the program names a repository but never reaches a database.

A library can also be put together as a chain: a value built step by step, each step adding a part. In koa, the band at the top of the wall reads “app = use …”: app starts from new_app, then adds logger, response_time, routes and not_found in turn. Each pale region round the steps is the package that defines them, named in its corner. A purple hull round the chain, labelled “compose applies mw”, says the definition compose takes each part the chain hands in and calls it.

cosmic-python.

Loading the system map.

allocation-local: the same allocation code, with repositories built where they are used.

Loading the system map.

koa again: the top band of its wall is a chain.

Loading the system map.

Loading the worked examples and practice.