This is a very broad question, but it may point you in the right direction. Please note that you can store relationship rules in a database. Their use will match your customer code. Try this for size ..
unit:
unit id,
name,
unit relationship:
unit id,
foreign unit id
Then you can use the relationship table with your device as follows.
unit idrefers to the unit being described.
foreign unit idmust be zero.
A unit . A unit null foreign unit id unit . a unit unit, , .
, .
instance:
instance id,
unit id,
parent instance_id
, (, ), , .