Can someone please help me understand what are allocatable arrays while writing a code in Fortran? When do we allocate/deallocate arrays? What is the role of the module?
It is advisable to consult the documentation under the index of "allocatable arrays".
Essentially, an allocatable array is a placeholder of a descriptor that will define the rank (number of dimensions), size(s), and extents of an array who's capacity is unknown until runtime.
Older language standards require explicit allocation and deallocation, newer language features permit automatic allocate, reallocate, and deallocate of arrays.
Judging from your question, I would suggest that some background reading would be the best way to become familiar with the purpose/operation/use of allocatable arrays. BUT, most books on Fortran are little more than a reiteration of the latest Fortran standard which simply states facts rather than provide background and (actually) assume the reader already understands Fortran concepts. They are very difficult to learn from. There is one book that I can recommend:
I think you will find the book as a whole to be very helpful and the section on alloacatable arrays particularly so.