Skip to main content

CALint: A Tool for Enforcing the Clean Architecture’s Dependency Rule in Python

  • Conference paper
  • First Online:
Computational Science and Its Applications – ICCSA 2022 Workshops (ICCSA 2022)

Abstract

Clean Architecture (CA) aims to address the need for more loosely coupled components and better cohesion. CA focuses on preparing software engineers to write more stable, durable, and flexible applications capable of distinguishing between details (e.g., what framework it uses) and the business logic requirements. A literature review shows that considerable effort has been devoted to cataloging and solving code smells related to code, often called code smells. However, the same does not apply to architecture smells – its software architecture counterpart. Similar research regarding other programming languages such as Java, PHP, or C# represents noteworthy works in the area, but they do not address Python applications directly. This work directs efforts towards redesigning and adapting existing Python programs to the CA principles by detecting the code smells that break the CA constraints through the developed CALint tool. Moreover, this approach proposes two extended refactoring techniques to solve these smells efficiently by grouping and comparing static code analysis and reuse them to enforce Clean Architecture’s Dependency Rule programmatically. To demonstrate the feasibility of the two refactoring techniques described in this work and the CALint tool, we applied them to three different case studies. The major findings of this work include two extended refactoring techniques and the development of a tool to verify non-conformities related to the Clean Architecture dependency rule. The results show common cases where the dependency rule was violated and highlighted by the CALint tool, which are fixed with the support of refactoring steps.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 99.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 129.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    https://www.sonarqube.org.

  2. 2.

    https://github.com/lgiordani/rentomatic.

  3. 3.

    https://github.com/heumsi/python-clean-architecture-example.

References

  1. Beltrão, A., Farzat, F., Travassos, G.: Technical debt: a clean architecture implementation. In: Anais Estendidos do XI Congresso Brasileiro de Software: Teoria e Prática. SBC, Porto Alegre, RS, Brasil, pp. 131–134 (2020). https://doi.org/10.5753/cbsoft_estendido.2020.14620. https://sol.sbc.org.br/index.php/cbsoft_estendido/article/view/14620

  2. Bui, D.: Reactive programming and clean architecture in Android development. Metropolia Ammattikorkeakoulu (2017)

    Google Scholar 

  3. Chen, T.H., et al.: An empirical study on the practice of maintaining object-relational mapping code in Java systems. In: 2016 IEEE/ACM 13th Working Conference on Mining Software Repositories (MSR), pp. 165–176. IEEE (2016)

    Google Scholar 

  4. Cockburn, A.: Hexagonal architecture (2005). https://alistair.cockburn.us/hexagonal-architecture/

  5. Ferrante, J., Ottenstein, K.J., Warren, J.D.: The program dependence graph and its use in optimization. ACM Trans. Program. Lang. Syst. (TOPLAS) 9(3), 319–349 (1987)

    Article  Google Scholar 

  6. Fontana, F.A., Pigazzini, I., Roveda, R., Tamburri, D., Zanoni, M., Di Nitto, E.: Arcan: a tool for architectural smells detection. In: 2017 IEEE International Conference on Software Architecture Workshops (ICSAW), pp. 282–285. IEEE (2017)

    Google Scholar 

  7. Python Software Foundation: Python language reference, modules (2022). https://docs.python.org/3/tutorial/modules.html

  8. Fowler, M.: Refactoring: Improving the Design of Existing Code. Addison-Wesley, Reading (1999)

    MATH  Google Scholar 

  9. Garcia, J., Popescu, D., Edwards, G., Medvidovic, N.: Toward a catalogue of architectural bad smells. In: Mirandola, R., Gorton, I., Hofmeister, C. (eds.) QoSA 2009. LNCS, vol. 5581, pp. 146–162. Springer, Heidelberg (2009). https://doi.org/10.1007/978-3-642-02351-4_10

    Chapter  Google Scholar 

  10. Giordani, L.: Clean Architectures in Python, 2nd edn. Leanpub (2018). https://leanpub.com/clean-architectures-in-python

  11. Guo, Y., et al.: Tracking technical debt - an exploratory case study. In: ICSM 2011: Proceedings of the 2011 27th IEEE International Conference on Software Maintenance, pp. 528–531, September 2011. https://doi.org/10.1109/ICSM.2011.6080824

  12. Heumsi: Python clean architecture example (2020). https://github.com/heumsi/python-clean-architecture-example

  13. Hotta, K., Higo, Y., Kusumoto, S.: Identifying, tailoring, and suggesting form template method refactoring opportunities with program dependence graph. In: 2012 16th European Conference on Software Maintenance and Reengineering, pp. 53–62. IEEE (2012)

    Google Scholar 

  14. Louden, K.C.: Compiler Construction. Cengage Learning, Boston (1997)

    Google Scholar 

  15. Martin, R.C.: Clean Architecture: A Craftsman’s Guide to Software Structure and Design. Robert C. Martin Series. Prentice Hall, Boston (2017). https://www.safaribooksonline.com/library/view/clean-architecture-a/9780134494272/

  16. Microsoft:net microservices - architecture e-book (2021). https://docs.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/infrastructure-persistence-layer-design

  17. Milojkovic, N., Ghafari, M., Nierstrasz, O.: It’s duck (typing) season! In: 2017 IEEE/ACM 25th International Conference on Program Comprehension (ICPC), pp. 312–315. IEEE (2017)

    Google Scholar 

  18. Prajapati, M., et al.: ASP.NET MVC-generic repository pattern and unit of work. Int. J. All Res. Writ. 1(1), 23–30 (2019)

    MathSciNet  Google Scholar 

  19. Razina, E., Janzen, D.S.: Effects of dependency injection on maintainability. In: Proceedings of the 11th IASTED International Conference on Software Engineering and Applications, Cambridge, MA, p. 7 (2007)

    Google Scholar 

  20. Rhodes, B.: The clean architecture in Python (2014). https://archive.org/details/pyvideo_2840___The_Clean_Architecture_in_Python

  21. Rizzi, L., Fontana, F.A., Roveda, R.: Support for architectural smell refactoring. In: Proceedings of the 2nd International Workshop on Refactoring, pp. 7–10 (2018)

    Google Scholar 

  22. Velasco-Elizondo, P., Castañeda-Calvillo, L., García-Fernandez, A., Vazquez-Reyes, S.: Towards detecting MVC architectural smells. In: Mejia, J., Muñoz, M., Rocha, Á., Quiñonez, Y., Calvo-Manzano, J. (eds.) CIMPS 2017. AISC, vol. 688, pp. 251–260. Springer, Cham (2018). https://doi.org/10.1007/978-3-319-69341-5_23

    Chapter  Google Scholar 

Download references

Acknowledgments

The authors would like to thank the São Paulo Research Foundation (FAPESP) grant 2018/22064-4 – for financial support.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Fábio Fagundes Silveira .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2022 The Author(s), under exclusive license to Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

Cite this paper

de Oliveira Junior, C.O., Carvalho, J., Silveira, F.F., da Silva, T.S., Guerra, E.M. (2022). CALint: A Tool for Enforcing the Clean Architecture’s Dependency Rule in Python. In: Gervasi, O., Murgante, B., Misra, S., Rocha, A.M.A.C., Garau, C. (eds) Computational Science and Its Applications – ICCSA 2022 Workshops. ICCSA 2022. Lecture Notes in Computer Science, vol 13381. Springer, Cham. https://doi.org/10.1007/978-3-031-10548-7_39

Download citation

  • DOI: https://doi.org/10.1007/978-3-031-10548-7_39

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-031-10547-0

  • Online ISBN: 978-3-031-10548-7

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics