A sanmon (三門 or 山門), also called sangedatsumon (三解脱門, lit. "gate of the three liberations"), is the most important gate of a Japanese Zen Buddhist temple, and is part of the Zen shichidō garan, the group of buildings that forms the heart of a Zen Buddhist temple. It can be often found in temples of other denominations too. Most sanmon are 2- or 3-bay nijūmon (a type of two-storied gate), but the name by itself does not imply any specific architecture.
See also: Shanmen
Its importance notwithstanding, the sanmon is not the first gate of the temple, and in fact it usually stands between the sōmon (outer gate) and the butsuden (lit. "Hall of Buddha", i.e. the main hall). It used to be connected to a portico-like structure called kairō (廻廊), which however gradually disappeared during the Muromachi period, being replaced by the sanrō (山廊), a small building present on both sides of the gate and containing a stairway to the gate's second story. (Both sanrō are clearly visible in Tōfuku-ji's photo above.)
The sanmon's size is an indicator of a Zen temple's status. Structurally, the sanmon of a first rank temple as Nanzen-ji in Kyoto is a two-storied, 5x2 bay, three entrance gate (see photo below). Its three gates are called kūmon (空門, gate of emptiness), musōmon (無相門, gate of formlessness) and muganmon (無願門, gate of inaction) and symbolize the three gates to enlightenment, or satori. Entering, pilgrims can symbolically free themselves from the three passions of ton (貪, greed), shin (瞋, hatred), and chi (癡, foolishness). The fact the gate has entrances but no doors, and cannot therefore be closed, emphasizes its purely symbolic function as a limit between the sacred and the profane.
A temple of the second rank will have a two-storied, 3x2-bay, single entrance gate (see photo below). The second story of a first or second rank temple usually contains statues of Shakyamuni or of goddess Kannon, and of the 16 Rakan, and hosts periodical religious ceremonies. The side bays of sanmon of the first two ranks may also house statues of the Niō, wardens who are in charge of repelling evil.
A third rank temple will have a single-storied, lx2-bay, single entrance gate.
Some images of the second story of Kōmyō-ji's sanmon in Kamakura, Kanagawa Prefecture. It is a high rank Jōdo sect sanmon, the largest of the Kantō region.