Sea levels are rising around the world, but as they rise, Bangkok is sinking. The low-lying megacity, built on marshland, is also now so covered in concrete that during heavy rains—the type of storms that are becoming more common because of climate change—streets can quickly flood.

A massive new green roof is designed to help capture rainwater in one neighborhood, on the Bangkok campus of Thammasat University. Designed to mimic traditional rice terraces, one part of the roof serves as an urban farm, now the largest farm of its kind in Asia; the cascading terraces use rain to grow rice along with native plants, and then store as much as 3 million gallons of water in detention ponds to be used later for irrigation in a drought.

Another part of the 236,000-square-foot roof is covered in solar panels to help power the building below, and the roof will also be used as an outdoor classroom for students at the university. Like other green roofs, the design also helps the building below it stay cool in heatwaves and reduces the urban “heat island” effect, the way that concrete surfaces and typical roofs reflect sunlight to make cities even hotter on hot days.

Rice production used to be common in paddies around the perimeter of the city as recently as a century ago, but “after years of unstoppable urban sprawl, the marshlands have turned to paralyzed concrete cities, no longer able to breathe, absorb water, or grow food,” the designers, from a Thai firm called Landprocess led by landscape designer Kotchakorn Voraakhom, write in a description of the project. (Voraakhom also designed another water-storing park in the city center.)

As the green roof absorbs water in storms, it’s also intended to demonstrate an alternative to the industrial agriculture that has become common in rural parts of the country. Thailand is among the world’s largest importers of pesticides; the new urban farm will be organic. In a year, the farm can grow enough rice for more than 100,000 meals to be served on the campus. Any leftover food from plates and the kitchen will be composted and sent back to the roof to fertilize the next crop of rice.