Skip to main content

Architecture

@biref/scanner uses a hexagonal (ports & adapters) architecture that separates database-specific logic from the paradigm-neutral core.

Layers

+-----------------------+
| Your code |
| Biref.builder()... |
+-----------+-----------+
|
+-----------v-----------+
| Core |
| Biref, Scanner, |
| QueryPlanExecutor, |
| AdapterRegistry |
+-----------+-----------+
|
+----------------+----------------+
| |
+----------v----------+ +-----------v-----------+
| Postgres Adapter | | MySQL Adapter |
| Introspector | | Introspector |
| QueryEngine | | QueryEngine |
| RawQueryRunner | | RawQueryRunner |
| RecordParser | | RecordParser |
+----------+-----------+ +-----------+-----------+
| |
+----------v----------+ +-----------v-----------+
| pg (driver) | | mysql2 (driver) |
+----------------------+ +-----------------------+

Ports

Every adapter implements four ports:

PortResponsibility
IntrospectorReads the database catalog and produces a DataModel
QueryEngineConverts a QuerySpec into a parameterized SQL string
RawQueryRunnerExecutes a BuiltQuery against the driver and returns raw rows
RecordParserCoerces raw driver output into typed ParsedRecord values

Key types

TypeDescription
BirefMain facade. Holds the adapter registry, exposes scan() and query()
BirefBuilderFluent builder for configuring adapters
AdapterA bundle of Introspector + QueryEngine + RawQueryRunner + RecordParser
AdapterFactoryCreates an Adapter from a driver client
DataModelThe scan result: all entities with relationships in both directions
QuerySpecParadigm-neutral query description (entity, select, filters, order, limit)
BuiltQueryEngine output: SQL string + bound parameters
QueryPlanImmutable tree built by the chain builder, one node per include level