# ๐Ÿ”ฌ Mathematical Optimization of Hybrid Software Architectures ### Balancing Coupling and Cohesion โ€” INPT ยท CEDoc 2TI ยท SEEDS Research Team **Supervisor:** Prof. Driss ALLAKI ยท **Duration:** 2 months ยท **Team:** 2โ€“3 interns --- ## ๐Ÿ“Œ Project Overview Modern software systems increasingly blend **monolithic** and **microservice** paradigms. While monoliths offer simplicity and maintainability, microservices bring scalability and independence. The challenge lies in *how* to split a system โ€” poor decomposition creates tight inter-module coupling and weak intra-module cohesion, making systems brittle and hard to evolve. This project builds a **mathematically grounded decision-support tool** that recommends optimal hybrid architectures. We model a software system as a weighted dependency graph and use combinatorial optimization to find component groupings that **maximize cohesion** within clusters and **minimize coupling** across them. --- ## ๐Ÿ† Results Summary All three methods successfully recover the ground-truth decomposition: | Metric | Spectral | Genetic Algorithm | Louvain | Ground Truth | |--------|:--------:|:-----------------:|:-------:|:------------:| | **Modularity Q** | 0.7571 | 0.7571 | 0.7571 | 0.7571 | | **Avg. Cohesion** | 0.5036 | 0.5036 | 0.5036 | 0.5036 | | **Avg. Coupling** | 0.0114 | 0.0114 | 0.0114 | 0.0114 | | **NMI** | 1.0000 | 1.0000 | 1.0000 | 1.0000 | | **ARI** | 1.0000 | 1.0000 | 1.0000 | 1.0000 | | **Runtime (s)** | 0.078 | 2.847 | **0.004** | โ€” | ### Visual Comparison ![Final Comparison](reports/03_final_comparison.png) --- ## ๐ŸŽฏ Objectives | # | Objective | Status | |---|-----------|:------:| | 1 | Formalize software systems as weighted graphs | โœ… | | 2 | Define quantitative metrics for cohesion & coupling | โœ… | | 3 | Formulate decomposition as multi-objective optimization | โœ… | | 4 | Implement and compare three solution strategies | โœ… | | 5 | Build visualization and evaluation tools | โœ… | --- ## ๐Ÿ—‚๏ธ Repository Structure ``` project/ โ”‚ โ”œโ”€โ”€ README.md โ† You are here โ”œโ”€โ”€ intro_for_new_members.pdf โ† Start here if you are new! โ”‚ โ”œโ”€โ”€ data/ โ”‚ โ”œโ”€โ”€ synthetic_dependency_graph.csv โ† Edge list (320 edges, 60 nodes) โ”‚ โ””โ”€โ”€ node_clusters.csv โ† Ground-truth cluster assignments โ”‚ โ”œโ”€โ”€ notebooks/ โ”‚ โ”œโ”€โ”€ 01_spectral_clustering.ipynb โ† Solution 1: Spectral Graph Partitioning โ”‚ โ”œโ”€โ”€ 02_metaheuristic_ga.ipynb โ† Solution 2: Genetic Algorithm โ”‚ โ””โ”€โ”€ 03_community_detection.ipynb โ† Solution 3: Louvain + Final Comparison โ”‚ โ””โ”€โ”€ reports/ โ”œโ”€โ”€ 01_graph_visualization.png โ† Graph + adjacency matrix โ”œโ”€โ”€ 01_eigenvalue_spectrum.png โ† Eigengap analysis โ”œโ”€โ”€ 01_spectral_results.png โ† Spectral embedding visualization โ”œโ”€โ”€ 01_spectral_evaluation.png โ† Cohesion/coupling/confusion matrix โ”œโ”€โ”€ 01_fiedler_analysis.png โ† Fiedler vector analysis โ”œโ”€โ”€ 02_ga_convergence.png โ† GA fitness convergence โ”œโ”€โ”€ 02_ga_results.png โ† GA clustering visualization โ”œโ”€โ”€ 02_ga_sensitivity.png โ† GA hyperparameter sensitivity โ”œโ”€โ”€ 02_ga_landscape.png โ† Fitness landscape visualization โ”œโ”€โ”€ 03_louvain_results.png โ† Louvain community detection โ”œโ”€โ”€ 03_resolution_analysis.png โ† Resolution parameter sweep โ”œโ”€โ”€ 03_louvain_hierarchy.png โ† Hierarchical decomposition โ”œโ”€โ”€ 03_final_comparison.png โ† All methods compared โ””โ”€โ”€ *.csv โ† Numerical results per method ``` --- ## ๐Ÿงญ How to Work This Project โ€” Step by Step ### Step 0 โ€” Read the Intro PDF First (New Members) > **File:** `intro_for_new_members.pdf` Covers: software architecture basics, Kubernetes & containers, coupling/cohesion problem, existing approaches, and why we need math. ### Step 1 โ€” Understand the Dataset > **File:** `data/synthetic_dependency_graph.csv` | Column | Description | |--------|-------------| | `source` | Source component (e.g., `auth_00`, `billing_03`) | | `target` | Target component | | `weight` | Dependency strength (0.0โ€“1.0) | | `true_cluster` | Ground-truth cluster label (0โ€“4) or "cross" for inter-cluster edges | The graph has **60 nodes** across **5 services** (auth, billing, catalog, orders, notify) with **320 edges**. ### Step 2 โ€” Run the Three Notebooks #### ๐Ÿ““ Notebook 1 โ€” Spectral Graph Partitioning Uses the **graph Laplacian** $L = D โˆ’ A$ and its eigenvectors. The eigengap heuristic correctly identifies K=5 clusters. ![Eigenvalue Spectrum](reports/01_eigenvalue_spectrum.png) ![Spectral Results](reports/01_spectral_results.png) #### ๐Ÿ““ Notebook 2 โ€” Genetic Algorithm Evolutionary optimization with tournament selection, uniform crossover, and random mutation. Includes sensitivity analysis and fitness landscape visualization. ![GA Convergence](reports/02_ga_convergence.png) ![GA Sensitivity](reports/02_ga_sensitivity.png) #### ๐Ÿ““ Notebook 3 โ€” Louvain Community Detection Greedy modularity maximization with resolution parameter analysis. Includes the final three-method comparison. ![Louvain Hierarchy](reports/03_louvain_hierarchy.png) --- ## ๐Ÿ“ Mathematical Definitions ### Modularity Q $$Q = \frac{1}{2m} \sum_{ij} \left[ A_{ij} - \frac{k_i k_j}{2m} \right] \delta(c_i, c_j)$$ ### Cohesion (intra-cluster density) $$\text{Cohesion}(C_k) = \frac{\sum_{i,j \in C_k} A_{ij}}{|C_k|(|C_k|-1)}$$ ### Coupling (inter-cluster density) $$\text{Coupling}(C_k, C_l) = \frac{\sum_{i \in C_k, j \in C_l} A_{ij}}{|C_k| \cdot |C_l|}$$ --- ## ๐Ÿ“ฆ Dependencies ```bash pip install networkx numpy scipy pandas scikit-learn matplotlib seaborn pyvis plotly python-louvain ``` --- ## ๐Ÿ Deliverables - [x] `README.md` โ€” Project documentation - [x] `intro_for_new_members.pdf` โ€” Onboarding document (7 pages) - [x] `data/synthetic_dependency_graph.csv` โ€” Dataset (320 edges, 60 nodes, 5 clusters) - [x] `data/node_clusters.csv` โ€” Ground-truth labels - [x] `notebooks/01_spectral_clustering.ipynb` โ€” Spectral method (21 cells) - [x] `notebooks/02_metaheuristic_ga.ipynb` โ€” Genetic algorithm (23 cells) - [x] `notebooks/03_community_detection.ipynb` โ€” Louvain + comparison (22 cells) - [x] `reports/*.png` โ€” 13 publication-quality figures - [x] `reports/*.csv` โ€” Numerical results for all methods --- ## ๐Ÿ‘ฅ Team & Roles | Role | Responsibility | |------|---------------| | Intern A | Graph modeling, dataset generation, math formalization | | Intern B | Optimization implementation (notebooks 1 & 2) | | Intern C | Evaluation, visualization, notebook 3 & report | --- ## ๐Ÿ“ฌ Contact **Supervisor:** MSC โ€” INPT, Rabat **Research Team:** R2 > *"A good decomposition is not just clean code โ€” it is a mathematical optimum."*