Question part A. Does the database take precedence or do the project config files take precedence? When Craft loads and there is an inconsistency between both... which setting makes it to the admin screen, the one living in the DB or the one living in the YAML files?
The database. In fact, Craft only uses the state in the database to display the interface. It only checks the YAML files to display the warnings if there's a discrepancy between the database state and the project config files. The YAML files are only used when you apply them manually, either using the
project-config/apply command or through the backend under Utilities -> Project Config.
Question part B. When I do craft project-config/apply, does it sync files --> database or database --> files or both (considering the most recent change)?
The former, it takes the YAML files in the config folder and applies those settings to the database. Though there are commands for both directions:
project-config/apply applies the YAML files in the
config/ folder to the database.
project-config/write takes the config currently stored in the database and writes it out as YAML files in the
config/ folder. You usually don't need this since Craft does this automatically whenever you change something in the backend (unless you have turned that off).
project-config/rebuild attempts to rebuild the entire project-config based on the state of the entire database. This is only required in rare edge-cases.
All of this is explained in detail in the documentation for the project config.