Developers
MAD is an embedded relational reporting engine: a portable .mad document, a
first-party Objective-C engine, and a mad command-line tool that runs the same
engine headless on Linux and Windows. These pages are organised by what you want
to do.
Contributing? Read
CONTRIBUTING.md
for the prerequisites, the green baseline, and the first-task lanes. An AI
agent? Start with
AGENTS.md and the two
repository skills, mad-verify
and mad-headless-port.
Embed the engine
An application that links the MAD framework, a database driver (MADMySQL,
MADPostgres, MADTdsClient, or the SQLite driver in MADSqlite3), and
MADSqlite3 for the local row cache has relational reporting with no server in
the loop. Open a document, refresh it through the shared operation chain, and
export it through the format registry:
#import <MAD/MADHeadlessDocument.h>
#import <MAD/MADDocumentDataProtocol.h>
#import <MAD/MADOperationRefreshInitalizeMainDataTable.h>
#import <MAD/MADOperationRefreshInitialize.h>
#import <MAD/MADOperationRefresh.h>
#import <MAD/MADReportExporterRegistry.h>
#import <MAD/MADReportExporting.h>
#import <MADFoundation/MADOperationQueue.h>
NSError *error = nil;
id <MADDocumentDataProtocol> document =
[MADHeadlessDocument documentWithContentsOfURL: url error: &error];
if (document == nil) { /* report error */ }
MADOperationQueue *queue = [[MADOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 1;
MADOperationRefreshInitializeMainDataTable *initializeTable =
[[MADOperationRefreshInitializeMainDataTable alloc] initWithDocument: document];
MADOperationRefreshInitialize *initialize =
[[MADOperationRefreshInitialize alloc] initWithDocument: document];
MADOperationRefresh *refresh = [[MADOperationRefresh alloc] initWithDocument: document];
[initialize addDependency: initializeTable];
[refresh addDependency: initializeTable];
[refresh addDependency: initialize];
[queue addOperation: initializeTable];
[queue addOperation: initialize];
[queue addOperation: refresh];
// The operations are asynchronous; turn the run loop until they finish, as the CLI does.
while (queue.operationCount > 0) {
@autoreleasepool {
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 0.05]];
}
}
if (refresh.errors.count > 0) { /* report refresh.errors.firstObject */ }
Class <MADReportExporting> exporterClass =
[MADReportExporterRegistry exporterClassForFormat: @"html"];
id <MADReportExporting> exporter = [[(Class)exporterClass alloc] init];
[exporter exportDocument: document
toURL: outURL
options: MADReportExportOptionsNone
error: &error];
That is the CLI’s own path:
CLI/Source/MADCLIDocument.m
builds exactly this chain, and
CLI/Source/MADCLIExport.m
looks the exporter up by name instead of naming a class. A document whose source
needs credentials adds an operation that adopts
MADOperationHoldsCredentialsProtocol as a dependency of the refresh operation,
the way the CLI’s MADCLICredentialsOperation does. A composed document takes
MADOperationRefreshComposed; +[MADOperationRefresh documentUsesComposedRefresh:]
is the test.
Drive the CLI
The mad command-line tool is the same engine with verbs: inspect,
schema, query, refresh, export, write, and the serve JSON protocol.
The CLI runs on Linux and Windows; the published container image is
linux/amd64. On macOS it is a developer build that runs through the iOS
Simulator (CLI/build.sh and xcrun simctl spawn booted); it is not a native
macOS binary.
Add a driver
A database driver is two classes: a MADDatabase subclass that returns the
schema and rows, and a MADDatabaseConnection subclass that conforms to
MADDatabaseDriver and registers with MADDatabaseDriverRegistry in +load, so
the engine builds it by type without a fork. The
driver-authoring tutorial walks the first
driver end to end. The live suites (MADMySQLLiveTests,
MADTdsClientLiveTests, MADPostgresLiveTests) skip when no server is
reachable, so the framework suites stay green without one.
Add an export format
An export format adopts MADReportExporting and registers itself with
MADReportExporterRegistry in +load; the CLI asks for it by the --format
name and nothing else changes. The protocol supplies the format name,
description, file extension, output-path requirement, and an +isAvailable gate
for machinery a build may not have. The CLI guide records the export
seam (MADReportExporterRegistry).
Add an element
A document element is an RptqDocumentElement subclass stored in the portable
store and produced through RptqDocumentElementFactory; the render half draws it
as a MADPrintPageElement, and the designer needs a view for it. Adding one
touches the document model, the designer, and the renderer, so it is an advanced
task rather than a first contribution. Read
the data-object design for where the layout sits in the
contract, and the MADDataTable architecture for
how the rows reach it.
Build and verify
The Apple suites run against one shared derived-data path (the frameworks
reference each other through BUILT_PRODUCTS_DIR); choose a simulator by device
id:
xcrun simctl list devices available
xcodebuild test -workspace Reports.xcworkspace -scheme MADFoundation \
-destination 'platform=iOS Simulator,id=<device-udid>' \
-derivedDataPath ~/Library/Developer/Xcode/DerivedData/Reports-shared
The headless engine has its own builds:
- Building the engine on Linux —
./Linux/build.sh, the Docker image, the twelve headless frameworks, and their suites (130 suites, 1,313 tests). - Building the engine on Windows — the pinned Clang and
GNUstep toolchain and
Windows/Engine/build.ps1. - Portability and the native macOS application — the
framework audit and the
AppKitarchitecture;./Mac/build.sh --smoke-testbuilds and smoke-tests the app. - The Compressor static-library build — the third-party C libraries and how Xcode reaches them.
- The headless PDF writer — Cairo, FreeType, and deterministic export.
- The applications: MAD Designer for macOS and MAD Designer for Windows. The repository READMEs carry the Linux, macOS, and Windows build and layout details.
Understand the format
- The
.madformat specification — what a document is, the container, the store, the hazards, and the normativev1target. - The data object — a report’s definition, schema, and result set as one contract, and how composition realizes it.
- Multi-source reports — reports as tables, drivers for anything that returns a table, and same-document composition.
- Pasting SQL into the query designer — the supported subset, the parser, and the apply path.
- The MADDataTable architecture — the data-table class cluster across the frameworks.
- The MADModel layer — the document read-model
over the
Rptqentities. - MADArrayCaching — the render cache’s disk-backed array.
- Composition reports and the vision — reports as composable data sources, materialized locally.
Contribute
MAD is one maintainer and an open development process. The good first lanes are
a docs correction, a test that pins a real bug, a small exporter, or a scoped fix
to an existing driver; a new driver or element is advanced. Read
CONTRIBUTING.md
for the prerequisites, the test-first rule, the DCO sign-off, and the Linux gate
when a headless source changes, look for the
good first issue
label, and ask in Discussions.
Satellite repositories records how mad-action and the
container image are published from this repository.
For agents
An AI agent should begin with
AGENTS.md, the
repository map and the approval gate. Its two skills are
mad-verify,
which routes a change to the cheapest verification that can pass or fail because
of it, and
mad-headless-port,
which ports a source file into the headless engine. The first tasks are the same
as the human lanes: a docs correction, a test that pins a bug, or a small
exporter.