The game and anime series are set in the late 19th century, a tumultuous period in Japanese history. The Tokugawa shogunate, which had ruled Japan for over 250 years, was on the verge of collapse. The arrival of American Commodore Matthew Perry and his fleet of warships in 1853 forced Japan to open its doors to the West, leading to a period of rapid modernization and upheaval. Against this backdrop, Hakuoki explores the struggles and loyalties of the Shinsengumi, a group of samurai tasked with maintaining order in Kyoto.