I would suggest letting the shelf essentially float. The short rail behind it is a structural member tied fast to the legs (various ways to do this). The shelf could be tongued into this rail to add front/back rigidity, but need not be glued or otherwise fixed tightly. It would slide in the rail.
Similarly, the lap joint between the shelf and leg could float. Leave, say,1/16” gap where the hidden faces of shelf and leg meet. Again, the join could be tight enough to add a little side/side rigidity, but not glued. The small gap between meeting faces would allow enough play for wood movement.