How vst/postmap works
Main Components
• Application Entry Point: The executable located in the “app” directory (app/Main.hs) represents the CLI entry point that a user interacts with.
• Core Library Modules:
• The “Postmap” module in the “src/Postmap” directory is the heart of the introspection and code generation process. Within this, you have:
∘ CLI support (e.g. src/Postmap/Cli.hs) for handling command-line arguments.
∘ Database Introspection Components (inside src/Postmap/Database and its submodules): This subcomponent handles reading the database schema, constraints, names, and structures.
∘ Code Generation components (src/Postmap/Codegen/Haskell and submodules): Responsible for translating the introspected schema into Haskell code, using patterns and overriding settings.
∘ A “Meta” submodule (src/Postmap/Meta.hs) for potentially coordinating and managing higher-level logic.
• Build and Configuration Tools: The project uses a variety of build scripts and configuration files:
• Haskell build configuration files (cabal.project, package.yaml, .ghci, etc.).
• Nix-related files (default.nix, shell.nix, and the nix/lib submodules) that build reproducible development and deployment environments.
• Formatting, linting, and testing configurations (fourmolu, hlint, doctest, and spec folders).
Relationships and Data Flow
• The CLI component (from “app/Main.hs” and “src/Postmap/Cli.hs”) serves as the entry point and passes user parameters into the workflow.
• The Database Interaction module (from “src/Postmap/Database”) is invoked to introspect the PostgreSQL database, extract schemas, constraints, and references.
• The Code Generation engine (under “src/Postmap/Codegen/Haskell”) takes the data provided by introspection, processes it, and produces Haskell code that maps to the database schema.
• The Zamazingo utilities may be called upon during both introspection (for parsing or formatting) and code generation (for mapping data types and JSON serialization).
Architectural Patterns and Design Principles
• Modularity and Separation of Concerns: The project is separated into distinct modules (CLI, DB introspection, code generation, helper utilities), ensuring each responsibility is encapsulated.
• Layered Architecture: Data flows from the user input via CLI to the database introspection layer and then moves into the code generation layer, all while being supported by shared utility functions.
• Infrastructure-as-Code elements: The use of Nix configuration for development environments shows a clear separation between development tooling and application logic.