Is it acceptable to have an electrical box the same depth as the stud?
Yes, that is acceptable. If you think there's a particular danger to that one wire (cabinetry/trim going on the other side), you can always install a 4x6 nail plate over it.