Periplasmic flagella are essential for the distinctive morphology, motility, and infectious life cycle of the Lyme disease spirochete Borrelia burgdorferi. In this study, we genetically trapped intermediates in flagellar assembly and determined the 3D structures of the intermediates to 4-nm resolution by cryoelectron tomography. We provide structural evidence that secretion of rod substrates triggers remodeling of the central channel in the flagellar secretion apparatus from a closed to an open conformation. This open channel then serves as both a gateway and a template for flagellar rod assembly. The individual proteins assemble sequentially to form a modular rod. The hook cap initiates hook assembly on completion of the rod, and the filament cap facilitates filament assembly after formation of the mature hook. Cryoelectron tomography and mutational analysis thus combine synergistically to provide a unique structural blueprint of the assembly process of this intricate molecular machine in intact cells.