How should software be organized into modules (aka packages or namespaces)?

I have long been intrigued by the principles that guide the proper organization of software code into modules (aka packages, namespaces). Ideally, these principles should be well-defined, leading to the same modular structure whenever the same software requirements are given, […]