When a source file contains no module directives, it is compiled into the module from which the compilation was invoked. This makes it possible to write small programs without caring about modules. However, serious applications should be structured into modules.
A proper module definition consists of
The directive module_interface/1 will first erase the module if it already exists, i.e. remove all items and interfaces contained in the module and then create a new empty module. This is necessary to maintain the integrity of the data and perform a complete recompilation of the module. The module interface contains the declarations and definitions of all modular items which this module shares with other modules that use it. As long as no further module directive occurs, all clauses and queries of the file have this module as definition module. The effect of module_interface/1 ends at the next module_interface/1 or begin_module/1 directive or a the end of the file. If the file contains queries to compile another file containing module directives, this is done and then the module of the current file is resumed.
module/1 in a file is an obsolete shorthand for a module with an empty interface (and it may not be available in future releases).