We describe a framework to assemble permanent-magnet cubes in 3Dprinted frames to construct dipole, quadrupole, and solenoid magnets, whose field, in the absence of iron, can be calculated analytically in three spatial dimensions. Rotating closely spaced dipoles and quadrupoles in opposite directions allows us to adjust the integrated strength of a multipole. Contributions of unwanted harmonics are calculated and found to be moderate. We then combine multiple magnets to construct beam-line modules: chicane, triplet cell, and solenoid focusing system.