Bases

Last updated 2 months ago

'Bases' is the folder where we store all of our bases.

We can imagine the bases folder as "drawer", which holds all of the bases in our workspace.

The RealWorld bases "drawer" contains a single base called 'rest-api'
Bases have a standard project structure

Each base has a standard Clojure project structure; with a project.clj file (similar to pom.xml, if you are used to Maven and Java), a readme.md file, a resources folder, a src folder, and a test folder. Each base is a project to allow us to compile them as individual artefacts, which guarantees that they are de-coupled from all the other building blocks.

The 'api' namespace exposes the base's endpoints

As you hopefully remember from the block metaphor, a base's API is where it exposes its endpoints to the outside world. A base's API is simply a namespace, in this case called api.clj The RealWorld example exposes a REST-API, but remember that Polylith doesn't restrict you to any particular API technology.

'rest-api' has two implementation namespaces: 'handler' and 'middleware'

Bases should usually delegate the implementation of each endpoint to components. However, it's also possible to keep tightly coupled implementation within a base. In the RealWorld example the handler namespace delegates each API endpoint to an appropriate component, but the middleware namespace implements REST-API specfic middleware functions directly within the base.