How to attach rails to legs on King x King bunk beds

I have made so many bunk beds for my customers but I tend to use the same techniques for every bed. Now I have a picture to go by and I cannot figure out how to do it. The legs I will be will be 6"x6" made with 4 boards to create a nine foot box. The two bed frame work, which is equally thick, seem to straddle the beam in some way but I really only see a bout 1/4 of the frame on the outside, as you can see from the pictures. I believe that there is another chunk of the frame work which enters the legs and some kind of metal brace maybe.