One of the main aims in the layered software architecture is to divide the code into different layers so that each layer contains related modules and serves its upper layers. Although layered software architecture is matured now; many legacy information systems do not benefit from the advantages of this architecture and their code for the process/business and data access are mostly in a single layer. In many legacy systems, due to the integration of the code in one layer, changes to the software and its maintenance are mostly difficult. In addition, the big size of a single layer causes the load concentration and turns the server into a bottleneck where all requests must be executed on it. In order to eliminate these deficiencies, this paper presents a refactoring mechanism for the automatic separation of the business and data access layers by detecting the data access code based on a series of patterns in the input code and transferring it to a new layer. For this purpose, we introduce a code scanner which detects the target points based on these patterns and hence automatically makes the changes required for the layered architecture. According to the experimental evaluation results, the performance of the system is increased for the layer separated software using the proposed approach. Furthermore, it is examined that the application of the proposed approach provides additional benefits considering the qualitative criteria such as loosely coupling and tightly coherency.