Introduction to Drupal modules
A Drupal module is simply a collection of files containing a set of routines written in PHP. Because the module code executes within the context of the site, it can use all the functions and access all variables and structures of the main engine. In fact, a module is no different from a regular PHP file: it is more of a concept that encourages good design principles and a good development model. Modularity also suits the open-source development model, because it allows a number of developers to contribute functionality to Drupal without risk of interference.
This approach allows module code to be run at specific places in the engine. This code can then do whatever is needed to enhance the existing functionality. The places where code can be executed are called "hooks" and are defined by a fixed interface.
At the points where hooks are made available, the engine calls each module's exported functions. This is done by iterating through the modules directory. Say your module is named foo (i.e. modules/foo.module) and exports a function called foo_bar(). If the Drupal installation has a hook called bar, the engine will call your foo_bar() function.
See also the overview of module hooks, in the Drupal API Reference.
