In contrast with conventional microgrids (MGs) with fixed boundaries, a smart and flexible MG with dynamic boundary is introduced in this paper. Such a MG can dynamically change its boundary by picking up or shedding load sections of a distribution feeder depending on its available power, leading to more flexible operation, better utilization of renewables, smaller size of energy storage system, higher reliability, and lower cost. To achieve a flexible MG, the main challenges in MG design are addressed, including recloser placement, MG asset sizing considering resilience, system grounding design, and protection system design. Meanwhile, a hierarchical structure is employed to design and implement the MG controller. On top of the functions defined in IEEE 2030.7-2018, a few new functions, e.g., online topology identification and PQ balance, are added, while the planned/unplanned islanding and reconnection functions are enhanced. The controller is implemented on a CompactRIO, a general-purpose hardware platform provided by National Instruments (NI), and tested on a controller hardware-in-the-loop setup based on an OPAL-RT real-time simulator and a reconfigurable power electronic converter-based hardware testbed. The test results have validated the performance of the developed controllers. Such a flexible MG and its controller have been deployed at a municipal utility, and part of the controller’s functions have been tested on-site.