How florius0/schema works
Project type and purpose
• Project type: An open-source Elixir library (Mix project) that provides a compile-time DSL for defining complex, set-theoretic schemas with validation and export capabilities.
• Purpose: Let Elixir developers declare rich data schemas (with pattern matching, constraints, type inference) via macros and extensions; validate data at compile- and run-time; and export schemas to other formats.
File structure
• Top-level mix files: mix.exs, mix.lock, .formatter.exs, .credo.exs, .doctor.exs
• .check/ & .github/workflows/: CI/tooling pipelines (Credo, Dialyzer, ExUnit, etc.)
• config/: application configuration (config/config.exs)
• lib/: core library code
• apix.access.ex
• ecto_like_syntax.ex
• apix.schema.* – modules under Apix.Schema namespace
• apix.schema.extensions.* – built-in extensions (core, elixir)
• test/: unit tests for core and extensions
Key insights from README
• DSL entrypoint: schema macro
• Core concepts: set-theoretic types, type inference, parameterized schemas, validations
• Extensible architecture via Apix.Schema.Extension
• Planned feature: exporting schemas in multiple formats
Main components
A. User code / Client modules
• Modules that call use Apix.Schema and define schema blocks (e.g., Api.Data, Api.Error)
B. Compile-time DSL Processor (Macro Expansion)
• Apix.Schema module (entrypoint)
• Parses schema definitions, produces an internal AST (Apix.Schema.AST)
C. Extension Manager
• Apix.Schema.Extension behaviour
• Loads built-in extensions:
• Core extension (lib/.../core.ex) – provides set-theoretic operations, type graph, validators
• Elixir extension (lib/.../elixir.ex) – maps Elixir built-in types to internal types
• Allows third-party extensions to register additional type rules or transforms
D. AST & Type Graph Processor
• Apix.Schema.Validator & Apix.Schema.Core.TypeGraph
• Builds a directed graph of type relationships, prunes unreachable nodes, enforces constraints
E. Runtime Validation & Helpers
• Generated code for runtime checks (via macros)
• Apix.Schema.Error and Apix.Schema.Warning
F. Exporter subsystem (future/maybe)
• Modules that take the AST and produce JSON, YAML, OpenAPI specs, etc.
G. CI/Tooling
• .check scripts, GitHub Actions for formatting, linting, docs, tests
Relationships and data flow
1) Developer writes schema in a client module →
2) At compile time, Apix.Schema macro →
3) Produces Apix.Schema.AST →
4) Routed through Extension Manager →
5) Core & Elixir extensions enrich AST & define type rules →
6) TypeGraph builder constructs full graph →
7) Validator runs static checks →
8) Macros emit compiled code for runtime validation →
9) (Optional) Exporter reads AST to generate external schema definitions
Architectural patterns and design principles
• Macro-based DSL for compile-time metaprogramming
• Plugin architecture via behaviours (extensions)
• Separation of concerns: AST modeling, type graph, validation logic
• Functional, immutable data flow between components
Detailed elements to capture
• Apix.Schema macro entrypoint
• Apix.Schema.AST data structures
• Extension behaviour and individual extensions
• Type graph building/pruning/validation modules
• Generated runtime validation code
• Exporter interface (if present)
• CI/tooling paths invoked by GitHub Actions