An example would be a REST API with a few endpoints where the database operations are handled directly in the route handlers uniquely for that specific task.
That’s a prime example for untestable code (not testable with unit tests/without IO). That might be fine for a tiny experiment, but I’d advise against it for projects of any size, even private ones. Always use a model like MVC, MVVM, three layers (data, business, user) …
I feel like we should have an in depth talk to better understand the problems you’re facing and the line of thinking that motivates your initial request. Unfortunately I currently do not have the time for that. The best I can do now, with the best of intentions, is to advise you to read literature about software development. The trouble is, that I’m not sure what to suggest, because I think there’s nothing that fits your premise. Maybe read about library development/reusable code so you better understand what not to make reusable by comparison? So maybe “Reusable Software: The Base Object-oriented Component Libraries” by Bertrand Myer or “Analysis Patterns: Reusable Object Models” by Martin Fowler. Though, both books are more on the old-fashioned side and I wouldn’t recommend them if you’re not an avid reader and (former) student of computer science.
The unix philosophy is about making highly reusable and pluggable tools which is the exact opposite of what OP is asking for.