Well, yes & no.
Seriously, you can build what & however you like. (You have my permission ! :bike_rider
But displaying such pictures, You get commentary from professional electrician observers.
Conductors "just passing thru" that blue shallow box is poor electrical practice.
Shallow boxes with a wiring device are tight enough, its all the worse to have wires within what dont serve a purpose within that box.
It appears the red & black are lowvoltage circuits ? Under NEC, They would not be permitted inside that box along with highvoltage circuits present.
The highvoltage wiring appears to be ordinary type "S" cable, (extension cord) ? Another NEC violation.
I hope it works out problem free for years to come & it probably will.
Its just not a star example of good electrical practice.