Rapid prototyping of microfluidic devices has advanced greatly, along with the development of 3D printing and micromachining technologies. However, peripheral systems for microfluidics still rely on conventional equipment, such as bench-top microscopy and syringe pumps, which limit system modification and further improvements. Herein, optofluidic modular blocks are presented as discrete elements to modularize peripheral optical and fluidic systems and are used for on-demand and open-source prototyping of whole microfluidic systems. Each modular block is fabricated by embedding optical or fluidic devices into the corresponding 3D-printed housing. The self-interlocking structure of the modular blocks enables easy assembly and reconfiguration of the blocks in an intuitive manner, while also providing precise optical and fluidic alignment between the blocks. With the library of standardized modular blocks developed here, how the blocks can be easily assembled to build whole microfluidic systems for blood compatibility testing, droplet microfluidics, and cell migration assays is demonstrated. Based on the simplicity of assembling the optofluidic blocks, the prototyping platform can be easily used for open-source sharing of digital design files, assembly and operation instructions, and block specifications, thereby making it easy for nonexperts to implement microfluidic ideas as physical systems.