How to get the basetype of a domain in pg_type? Basically,

if typbasetype = 0, the oid gives the base type.
Else
   recusively look at typbasetype joined with pg_type oid till we end up at the basetype.

How can this be done?
You can use format_type() to get the correct base data type.

Something along the lines of:

SELECT t.typname as domain_name, 
       pg_catalog.format_type(t.typbasetype, t.typtypmod) as data_type,
       pg_catalog.pg_get_constraintdef(c.oid, true) as constraint_definition
FROM pg_catalog.pg_type t 
  LEFT JOIN pg_catalog.pg_constraint c ON t.oid = c.contypid 
WHERE t.typtype = 'd' 
  and t.typname = 'your_domain_name'