Summaries > Technology > Rails > Modularizing Rails Monoliths One Bit...
TLDR Restructuring code into packages, declaring dependencies, and maintaining public interfaces are crucial steps in addressing 'spaghetti code.' The conversation emphasized using tools like Packwerk for static code analysis to enforce boundaries and ensure modularization. It also highlighted the challenges in identifying privacy violations, resolving complex dependencies, and maintaining documentation for long-term efficiency and sustainability.
In dealing with spaghetti code, the use of tools like Packwerk can bring significant benefits to software development. Packwerk, a static code analysis tool, enforces code boundaries and helps in modularization, leading to clearer code ownership and increased efficiency. By integrating Packwerk into the CI pipeline, privacy violations can be detected, eliminating the need for manual code reviews for every PR.
To effectively restructure code into packages and declare dependencies, it's crucial to align the code structure with the business's perspective. Utilizing event storming to plan and name feature sets can aid in this process. Moving classes into packages, eliminating unused code, and utilizing YAML files for declaring dependencies and adding metadata to files are essential steps in this phase.
Phase three involves making hard decisions, identifying privacy violations, and creating stable public interfaces for other packages to use. It is essential to use heavily commented public interfaces, avoid leaking private methods or classes through return types, and utilize plain old Ruby objects instead of exposing Active Record objects. Furthermore, categorizing packages into infrastructure, common tooling, and feature sets can aid in resolving complex dependencies.
Using automated tools to manage code reviews and detect issues like privacy violations and circular dependencies is crucial for maintaining a clean and efficient codebase. Additionally, maintaining public interfaces, keeping documentation up to date, and actively listening to feedback, including from support teams, are vital aspects of effective code management and improvement. Emphasizing the importance of enjoying the development process and striving for clarity in the code base, the speaker advocated a phased approach and reiterated the goal of building software that solves hard problems.
The challenges include confusion and inefficiency in software development.
Packwerk is a static code analysis tool that enforces code boundaries and helps in modularization. It can be integrated into the CI pipeline to avoid manual code reviews for every PR and to detect privacy violations.
The phases include examining features, organizing files into packages, defining package dependencies, and maintaining the codebase to ensure long-term efficiency and sustainability.
Aligning code structure with the business's perspective is important for planning and naming feature sets, as well as for moving classes into packages and eliminating unused code.
Phase three involves making hard decisions, identifying privacy violations, creating stable public interfaces, and using heavily commented public interfaces.
Using automated tools to manage code reviews, maintaining public interfaces, and actively listening to feedback from support teams are important considerations.