I designed a PCB which matches the dimensions of a receptacle box (the blue ones, just gonna call it the box). It is meant to mount next to an outlet in a double gang box and has a relay controlled by an esp to control the outlets. The components face into the box, and an led faces out, but is flush with the out-side of the board. I'm wondering the legality (code-wise) of installing a custom device like this into an electrical box. All it's doing is breaking or making the live connection to the outlet, but for now the design necessitates soldering the Live wire directly to the board, which I'm pretty sure I don't wanna do. If it had proper screw terminals for Live would that be ok? I'm having trouble finding information on this, maybe my Google-fu is off.
That would not be code-compliant. The NEC requires that all installed equipment be listed by a recognized testing laboratory (i.e. Underwriters' Laboratories, "UL", in the US) who has performed safety testing.
One way to deal with this is to outsource the switching job to a listed relay that mounts in or to a junction box, so that the mains voltage is completely contained in the junction box. Outside, the relay gives you terminals (for either closing a circuit or providing a voltage) to control the relay. Your custom IoT gadget can control the mains circuit without needing to be listed itself, because it is isolated from the mains power.