Abstract—Code smells have been defined as symptoms of poor design and implementation choices. Empirical studies showed that code smells can have a negative impact on the understandability and maintainability of code. For this reason, tools have been developed in industry and academia to automatically detect design flaws and, in some cases, to recommend developers how to remove them via refactoring. However, these tools are not able to prevent the introduction of design flaws. This means that the code has to experience a quality decay (with a consequent increase of maintenance costs) before state-of-the-art tools can be applied to identify and refactor the design flaws. In addition, existing tools recommend refactoring operations that (i) mostly target the improvement of some quality metrics (e.g., class cohesion) rather than the generation of refactorings that are meaningful from the developers’ point of view; and (ii) do not provide the developer with a “rationale” motivating the need for the refactoring. Our goal is to develop techniques serving as the basis for a new generation of refactoring recommenders able to (i) predict code components likely to be affected by code smells in the near future, to refactor them before they experience a quality decay; (ii) recommend meaningful refactorings emulating the ones that developers would perform, rather than the ones targeting the improvement of quality metrics; and (iii) explain the rationale behind the recommended refactorings. We refer to such a novel perspective on refactoring as just-in-time rational refactoring.