Rule #1: Always separate your business-logic code from the GUI code.
Without this rule, all your code will be a hot mess, where libraries cannot exist.
Rule #2: There should be no floating units.
A unit should always belong to a project (Dpr or Dpk). Without this, you will fail to properly generate some DCU files, meaning that your project will link to a DCU file that was compiled with a different version of a unit. At that point there will be no correct way to discern if a DCU was generated with Delphi 10 or 11, if that DCU is a debug or a release DCU, or if it is a 32-bit or 64-bit. The linker will refuse to link that DCU, and you will embark onto a quest to figure out why a seemingly valid PAS file cannot be linked. Good luck.
Rule #3: A unit can belong to a project (dpr, dpk) and only one project.
Unfortunately, this is the only rule enforced by the compiler, and only for libraries. So, I don’t even need to explain why it is good to follow this rule. The compiler will force it on you anyway. 😊
Rule #4: The unit of a low-level library cannot access a unit in a higher-level library.
Ignore this rule and you will create circular references. Even though this rule is not directly enforced by the compiler, the compiler will scream at you as soon it encounters a circular reference. Unfortunately, in some circumstances the compiler cannot figure out that it stepped into a circular reference, and it will run out of memory trying to compile your code.
We will study the necessity of the above rules one by one, in detail, in the chapters of Delphi in all its glory – Libraries and Packages.
As you can see, these rules are simple and to the point. It is not hard at all to follow them. If you don’t, you will do a lot of file re-arrangements and code refactoring as your code grows. So, obey them or… suffer.