The fortifications of Bangkok consist of several series of defensive structures built to protect the city during the late Ayutthaya to early Rattanakosin periods. The earliest structures were built when Bangkok was an outpost of Ayutthaya guarding entry to the Chao Phraya River during the 15th–16th centuries. These were reinforced when the city became the site of the short-lived capital of Thonburi after the fall of Ayutthaya in 1767. New walls and forts were built when the city of Rattanakosin replaced Thonburi in 1782, which were mostly removed and replaced in the second half of the 19th century in order to accommodate the expanding city. Today, four of the city's defensive forts remain, along with two short sections of the Rattanakosin city wall and one of the city gates.