Add the canonical data product template

Moves the data product template from semprini-blog-dataproducts, as adapted to
the semprini-data domain platform, into canonical_data_product/. Its worked
example passed 9 of 9 checks on the domain platform on 2026-09-17.

Adds agent-canonical-product, the blog's agent-product adapted to generate a
product into a domain repository from a declaration in the domain's model
repository, and README/CLAUDE.md describing the template catalogue, the
product contract with the domain platform, and team ownership. Source-aligned
and experience templates are planned.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
paulandClaude Opus 5 committed 2026-09-17 22:55:11 +12:00
commit 62a3714562
30 files changed
+1529

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
-- {{product.name}}: operational data store schema (runs on the postgres service).
--
-- The product owns one PostgreSQL schema. pg_graphql reflects only the schemas on the
-- search_path, and the product's RPC endpoint (030_api.sql) sets the search_path to this
-- schema, so this is what scopes the GraphQL API to the product.
CREATE SCHEMA {{product.schema}};
COMMENT ON SCHEMA {{product.schema}} IS E'@graphql({"inflect_names": true, "introspection": true, "max_rows": 100})';
-- Maintains updated_at on every row change. Used by all product tables (020_tables.sql).
-- updated_at is the freshness signal carried on the outbound topics and into the lake.
CREATE FUNCTION {{product.schema}}.set_updated_at() RETURNS trigger
LANGUAGE plpgsql AS $$
BEGIN
NEW.updated_at := now();
RETURN NEW;
END
$$;
+69
View File
@@ -0,0 +1,69 @@
-- {{product.name}}: operational tables (PostgreSQL 17).
--
-- One block per entity in the product's `entities` list, parents before children, association
-- tables last. Names are snake_case of the MD-DDL names. Every table has:
-- <table>_id uuid the MD-DDL primary identifier; producers may supply it
-- created_at / updated_at platform columns, always last
-- Enum attributes are text with a CHECK listing the MD-DDL enum values verbatim.
-- One-to-many relationships become a foreign key on the owned side; many-to-many
-- relationships become association tables. Inheritance (`extends:`) is class-table: the
-- subtype's primary key is its foreign key to the parent, and an abstract parent carries a
-- <table>_type discriminator naming the subtype.
-- >>> repeat per core entity table (no `extends:`)
CREATE TABLE {{product.schema}}.{{table}} (
{{table}}_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
{{table}}_type text NOT NULL CHECK ({{table}}_type IN ({{subtype_names}})), -- abstract parents only
{{column}} {{pg_type}}, -- {{attribute.name}}
{{enum_column}} text CHECK ({{enum_column}} IN ({{enum_values}})), -- enum:{{enum.name}}
{{parent_table}}_id uuid NOT NULL REFERENCES {{product.schema}}.{{parent_table}} ({{parent_table}}_id), -- one-to-many, owned side
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
COMMENT ON TABLE {{product.schema}}.{{table}} IS '{{entity.description}}';
COMMENT ON COLUMN {{product.schema}}.{{table}}.{{column}} IS '{{attribute.description}}';
CREATE INDEX {{table}}_{{parent_table}}_id_idx ON {{product.schema}}.{{table}} ({{parent_table}}_id);
CREATE TRIGGER {{table}}_set_updated_at
BEFORE UPDATE ON {{product.schema}}.{{table}}
FOR EACH ROW EXECUTE FUNCTION {{product.schema}}.set_updated_at();
-- <<< end repeat
-- >>> repeat per subtype table (`extends: {{parent}}`)
CREATE TABLE {{product.schema}}.{{child_table}} (
{{child_table}}_id uuid PRIMARY KEY REFERENCES {{product.schema}}.{{parent_table}} ({{parent_table}}_id) ON DELETE CASCADE,
{{column}} {{pg_type}}, -- {{attribute.name}}
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
COMMENT ON TABLE {{product.schema}}.{{child_table}} IS '{{entity.description}}';
CREATE TRIGGER {{child_table}}_set_updated_at
BEFORE UPDATE ON {{product.schema}}.{{child_table}}
FOR EACH ROW EXECUTE FUNCTION {{product.schema}}.set_updated_at();
-- <<< end repeat
-- >>> repeat per many-to-many relationship
-- Self-referential relationships are named <table>_association and use
-- source_<table>_id / target_<table>_id in place of the two foreign keys below.
CREATE TABLE {{product.schema}}.{{source_table}}_{{target_table}} (
{{source_table}}_{{target_table}}_id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
{{source_table}}_id uuid NOT NULL REFERENCES {{product.schema}}.{{source_table}} ({{source_table}}_id) ON DELETE CASCADE,
{{target_table}}_id uuid NOT NULL REFERENCES {{product.schema}}.{{target_table}} ({{target_table}}_id) ON DELETE CASCADE,
{{relationship_attribute}} {{pg_type}}, -- from relationship_attributes
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
COMMENT ON TABLE {{product.schema}}.{{source_table}}_{{target_table}} IS '{{relationship.description}}';
CREATE INDEX {{source_table}}_{{target_table}}_source_idx ON {{product.schema}}.{{source_table}}_{{target_table}} ({{source_table}}_id);
CREATE INDEX {{source_table}}_{{target_table}}_target_idx ON {{product.schema}}.{{source_table}}_{{target_table}} ({{target_table}}_id);
CREATE TRIGGER {{source_table}}_{{target_table}}_set_updated_at
BEFORE UPDATE ON {{product.schema}}.{{source_table}}_{{target_table}}
FOR EACH ROW EXECUTE FUNCTION {{product.schema}}.set_updated_at();
-- <<< end repeat
+31
View File
@@ -0,0 +1,31 @@
-- {{product.name}}: API surface (runs on the postgres service).
--
-- PostgREST connects as `authenticator` and switches to the platform's `anon` role, so the
-- GraphQL API sees exactly what `anon` is granted here. The lab has no authentication; a real
-- deployment would grant per-consumer roles and add row-level security policies.
GRANT USAGE ON SCHEMA {{product.schema}} TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA {{product.schema}} TO anon;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA {{product.schema}} TO anon;
ALTER DEFAULT PRIVILEGES IN SCHEMA {{product.schema}} GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO anon;
-- The product's GraphQL endpoint. PostgREST exposes api.<name> as POST /rpc/<name>.
-- pg_graphql reflects the schemas on the search_path, so the SET clause is what scopes this
-- endpoint to the product's tables and keeps other products out of its schema.
CREATE FUNCTION api.{{product.schema}}_graphql(
query text,
variables jsonb DEFAULT '{}'::jsonb,
"operationName" text DEFAULT NULL,
extensions jsonb DEFAULT NULL
) RETURNS jsonb
LANGUAGE sql
SECURITY INVOKER
SET search_path = {{product.schema}}, graphql
AS $$
SELECT graphql.resolve(query, variables, "operationName", extensions);
$$;
GRANT EXECUTE ON FUNCTION api.{{product.schema}}_graphql(text, jsonb, text, jsonb) TO anon;
-- PostgREST caches the API definition; ask it to pick up the new endpoint.
NOTIFY pgrst, 'reload schema';
+10
View File
@@ -0,0 +1,10 @@
-- {{product.name}}: optional sample rows (runs on the postgres service).
--
-- Delete this file if the product should deploy empty. Use fixed uuids so child rows can
-- reference their parents and so the same rows can be published to the inbound topics or
-- queried through GraphQL in examples. Keep it to a handful of rows per table.
-- >>> repeat per entity table, parents before children
INSERT INTO {{product.schema}}.{{table}} ({{table}}_id, {{column}}, {{parent_table}}_id) VALUES
('{{uuid}}', {{value}}, '{{parent_uuid}}');
-- <<< end repeat