# What dmog is made of

dmog's library joins three libraries that do not know about each other, the language, the routers, and the renderers, and the dmog command is one of its users.

dmog is small. Almost everything it does is done by three libraries, and dmog's job is to put them together. It does that job as a library of its own, and the `dmog` command is built on that library.

## The three parts

[alchemy](https://github.com/tabnas/alchemy) is the language. It reads a program, checks it, and compiles it into a plan. It also defines what the other two share: the events a document becomes, the shape of a table, the failures and their codes, and the limits.

[transduce](https://github.com/tabnas/transduce) reads. It turns a document into a stream of events, as its parser goes, and routes the events through the plan: which parts of the document the program selects, and which it lets pass.

[render](https://github.com/tabnas/render) writes. It turns events and tables back into text, and its writer decides when text reaches the output.

A compiled plan needs something to read with and something to write with. alchemy does not choose them. The host passes them in, and dmog's library is that host: it builds transduce's routers and render's renderers and hands both to alchemy.

## Why the parts are kept apart

None of the three depends on the code of the other two. A library that needs only to read a document depends on transduce alone, and one that needs only to write depends on render alone. Each can be released without the others.

The cost is that behaviour needing all three has to live somewhere, and that place is dmog. The tests of alchemy's programs, which need a reader and a writer to run, are dmog's tests. So is the translation of every format into every other.

## Where the formats come in

Each data format is its own package: a grammar, and the parts that translate it. A format's package says how its documents become events and how events become its text, in alchemy programs of its own. dmog collects those parts from the format packages it depends on and gives them to alchemy's translation. dmog has no code for any one format.

That is why `dmog formats` can describe every format exactly: the description is what each package declares. For what those parts are, see [What a translation keeps](https://dmog.tabnas.dev/explanation/translation.html).

## The library and the command

The host is a library, not the command, because the composition is all that the three parts lack. Once the routers and the renderers are built and handed to alchemy, what remains is the command line: reading the options, opening the files, and turning a failure into an exit status. The `dmog` command does that, and leaves the rest to the library.

A program that calls the library gets what a script gets from the command: the same translations, the same failures with the same codes, and the same limits. It also gets what a separate process cannot give: no process to start for each document, a translation compiled once for many documents, and any reader or writer in place of files. For the calls, see [The libraries](https://dmog.tabnas.dev/reference/library.html).

## One composition, three languages

The same libraries exist in TypeScript, Go, and Rust, and so do dmog's library and its command. Each build composes its own language's three parts in the same way. The three are held to the same test files, so a program or a translation gives the same answer whichever build runs it. For the details of each build, see [The three builds](https://dmog.tabnas.dev/reference/builds.html).
