Middleware has a major impact on the performance of distributed software applications. To predict the performance (e.g., response time, throughput) of an application using a performance model, it is essential to capture not only the characteristics of the application, but also the platform and the middleware. Model elements, which are added to an application software model for performance analysis are known as Completions. This research proposes a unified and flexible framework, called MMLQ (Middleware Modeling for Layered Queues), for modeling middleware completions and automatically composing them into software performance models. The existing approaches have many limitations. Some of them require to build and compose models manually, others lack generality, while others use component-based modeling which creates many elements that are not essential for performance analysis and complicate the model. MMLQ overcomes the limitations of the existing approaches and can model a wide range of middleware platforms. The contributions of this thesis include identifying the commonalities and differences among different middleware platforms, modeling their features, specializing middleware models to cater to the needs of an application, calibrating the specialized models and a proposing a process to compose calibrated models with the application models. The software application models and the middleware models are all built using Layered Queuing Network Model (LQN) developed at the RADS lab of Carleton University. The MMLQ framework is validated by showing its ability to model three different categories of middleware and by comparing the predicted performance with measured performance metrics.