The detention of applicants should be applied in accordance with the underlying principle that persons should not be held in detention for the sole reason that they are seeking international protection, particularly in accordance with the international legal obligations of the Member States and in particular with Article 31 of the Geneva Convention. It should be possible for applicants to be detained only under the very clearly defined exceptional circumstances laid down in this Directive and subject to the principles of necessity and proportionality with regard to both the manner and the purpose of such detention. The detention of applicants pursuant to this Directive should only be ordered in writing by judicial or administrative authorities stating the reasons on which it is based, including in cases where the person is already detained when making the application for international protection. Where an applicant is held in detention, that applicant should have effective access to the necessary procedural guarantees, such as judicial review and the right to free legal assistance and representation, where applicable under this Directive.