The api layer of MACSS, implemented
It is three things at once: a methodology that is contract-first and use-case driven, a
specification of how modules, DTOs, repositories and use cases relate, and a set of
SDKs in three languages that produce structurally identical openapi.json
from the same model.
Every operation is a UseCase — typed Input, typed Output, a
validate() step and an execute() step. Validation, business logic and HTTP stay apart because the framework has no layer that mixes them.
CQRS is structural: commands travel over REST, queries over GraphQL. The OpenAPI specification and the GraphQL schema are generated from the use cases.
Every server ships these, with no configuration:
/docs/health/openapi.json/openapi.yaml/metricsDart below. The same model is available in TypeScript and Python.
dependencies:
modular_api: ^1.0.0
import 'package:modular_api/modular_api.dart';
Future<void> main() async {
final api = ModularApi(
basePath: '/api',
title: 'My App',
version: '1.0.0',
);
api.module('clients', (m) {
m.usecase('create', CreateClient.fromJson);
m.usecase('list', ListClients.fromJson);
});
await api.serve(port: 8080);
}
# Commands travel over REST
curl -X POST http://localhost:8080/api/clients/create \
-H "Content-Type: application/json" \
-d '{"name":"Acme"}'
# Queries travel over GraphQL, generated from the same use cases
# Docs http://localhost:8080/docs
# Spec http://localhost:8080/openapi.json