This paper presents a framework for software architecture recovery and restructuring. The user specifies a high level abstraction view of the system using a structured pattern language. A pattern matching engine provides an optimal match between the given pattern and a decomposition of the legacy system entities by satisfying the inter/intramodule constraints defined by the pattern. The data mining technique Apriori is used by the matching engine to reveal meaningful data and control flow properties of the target system and limit the search space. A branch and bound search algorithm using a score function, models the constraints in the pattern as a Valued Constraint Satisfaction Problem (VCSP), and assists in searching for an optimal match between the given pattern and the target system.