You are asking me what constraints? Read your own message, you were saying I should write a CTE that is not recursive, or do not use repetitions. Why would that be, when I can use CTEs for that, I name them constraints because you are trying to limit the capabilities as you see fit.
Your function has CTE in it, while you were against that (and you would say but that is for recursive, repeated parts blah blah - if was more readable you could write repeatable parts with subqueries).
If you are asking me about the readability of this function, at top it is nice and understandable and suddenly gets ugly with subqueries. You are wrong about debug and optimizations of CTE vs subquery. I can't understand how you do make that distinction. You are just throwing such ideas with no base.