If absolute minimum space is required, rigid flex PCBs can be helpful but expensive to prototype. No connectors are the smallest connectors, and flex PCB can be shaped just right to connect to your stuff.
Alternatively, could your design could fit on a 2 layer flex PCB with a stiffener behind the electronics? This has been very effective and a lot cheaper than true rigid flex.