Bathroom vanity light with no junction box
Someone cheated pretty bad here. They probably busted the hole in the wall, fished the line, and then it looks like they used the ring for mounting the fixture to the box to just drywall screw it into the wall.

Not code. Not safe. Not smart.

You have a stud behind it so you could use a pancake box (could only find 30 packs online but your local big box should have individuals for sale)



Note that this one has clamps built in, but you can buy them with 1/2" knockouts as well (just use a NM clamp with those). You can then mount the ring to it and then put the fixture back up. Thankfully it's a cheap fix (I bet the box costs no more than $2)