Discovery of Architectural Layers and Measurement of Layering Violations in Source Code 1 Santonu Sarkar a , Girish Maskeri b , Shubha Ramachandran b a Accenture Technology Labs, Bangalore 560100, India b Software Engineering Technology Laboratory Infosys Technologies Limited Electronics City, Hosur Road Bangalore 560100, India Abstract The layers architectural pattern has been widely adopted by the developer com- munity in order to build large software systems. In reality, as the system evolves over time, rarely does the system remain conformed to the intended layers pattern, causing a significant degradation of the system maintainability. As a part of re- factoring such a system, practitioners often undertake a mostly manual exercise to discover the intended layers and organize the modules into these layers. In this pa- per we present a method for semi-automatically detecting layers in the system and propose a quantitative measurement to compute the amount of non-conformance of the system from the set of layered design principles. We have applied the layer detection method and the non-conformance measurement on a set of open source and proprietary enterprise applications. Key words: Metrics/measurement, maintenance, layers pattern, architecture recovery, clustering 1 The work was carried out at Infosys Technologies Ltd. 2 The authors would like to thank Mr. Daniel Popescu and Dr. Nenad Medvidovic at the University of Southern California for their feedback on the early draft of this paper. Preprint submitted to Elsevier 24 June 2009