Refactor a provided codebase to improve its modularity and clean code architecture while keeping all core functionality intact.