← All presentation pages

Microservice Anti-Pattern Detection Framework

Architecture & implementation walkthrough · MSc dissertation prototype

System Architecture

The design targets AWS serverless (Lambda, EventBridge, S3, RDS). The prototype simulates it locally with Docker Compose: each container plays the part of an AWS service, so it ran without cloud costs.

Input Layer

REST API upload
(CI/CD webhook in design)

API Gateway

FastAPI
Port: 8000

Analysis Engine

Pattern Detection
Tool Orchestration

Storage

PostgreSQL
MinIO S3

Dashboard

HTML/JS (Nginx)
Port: 3000

Key Components

  • ✅ Multi-tool integration (SonarQube, Roslyn, ArchUnit concepts)
  • ✅ Result normalisation into one common issue format
  • ✅ Conflict-resolution design: semantic similarity, location & pattern-type matching
  • ✅ Unified reporting interface
  • ✅ RESTful API for CI/CD integration

Docker Containers (simulating AWS services)

8 containers defined in docker-compose.yml. Started with one command: docker-compose up -d

🔌 API Service

FastAPI backend
≈ API Gateway + Lambda

Port: 8000

📊 Dashboard

HTML/JS via Nginx

Port: 3000

🗄️ PostgreSQL

Results & metadata
≈ Amazon RDS

Port: 5432

📦 MinIO

Artifact storage
≈ Amazon S3

Port: 9000

🔍 SonarQube

Code Analysis

Port: 9002

⚡ Redis

Cache & sessions
≈ ElastiCache

Port: 6379

🛠️ Roslyn

.NET Analysis

Tool container

☕ ArchUnit

Java Analysis

Tool container
The containers ran on the developer machine during the project. This page is a static walkthrough, so it doesn't show live status.

Detection Flow

Analysis Pipeline

1
Project Upload
A project is submitted via POST /api/analysis (FastAPI)
2
Tool Execution
SonarQube, Roslyn and ArchUnit concepts analyse the code (simplified implementations)
3
Pattern Detection
Real code analysis in simple_real_detector.py and dataset_specific_analyzer.py
4
Result Normalization
Each finding converted to one schema: type, severity, file & line, description, fix, confidence (0–1)
5
Conflict Resolution
Design: match duplicates by location, pattern type, description similarity and timing; keep the higher-confidence result
6
Results Display
Results via GET /api/analysis/{id}/results and the dashboard at localhost:3000

Validation Results

Detection Metrics (2 files, 6 known patterns)

Precision: 100%
Recall: 66.7%
F1-Score: 80%

Performance

Execution time: ~5–35 s per project
Cost per analysis (projected): ~£0.04
Yearly, 20 runs/week (projected): ~£42 vs £500+

Example Patterns Detected

  • ✅ Hardcoded connections, endpoints & credentials
  • ✅ Synchronous blocking
  • ✅ Shared persistence
  • ✅ Distributed monolith
  • ✅ Cyclic dependencies / missing API gateway
  • ✅ Inappropriate service intimacy / missing idempotency
  • ✗ Missed in validation: God Service, hardcoded credentials (need deeper analysis)

Test Projects

  • 📁 gs-spring-boot (15 files) → 2 patterns, ~5 s
  • 📁 spring-petclinic-microservices (42 files) → 4 patterns, ~15 s
  • 📁 sock-shop (38 files, polyglot) → 5 patterns, ~20 s
  • 📁 eShopOnContainers (67 files, .NET) → 6 patterns, ~35 s

Code Structure

📁 microservice-antipattern-detector/
├── 📄 docker-compose.yml (Container orchestration)
├── 📄 README.md
├── 📁 services/
│   ├── 📁 api/ (Main API service)
│   │   ├── 📄 Dockerfile
│   │   ├── 📄 requirements.txt
│   │   └── 📁 app/
│   │       ├── 📄 main.py (FastAPI application, API endpoints)
│   │       ├── 📄 real_integrated_analyzer.py (Main analyzer)
│   │       ├── 📄 simple_real_detector.py (Pattern detection)
│   │       ├── 📄 dataset_specific_analyzer.py (Dataset patterns)
│   │       ├── 📄 sonarqube_real.py · archunit_real.py · roslyn_simple.py (Tool concepts)
│   │       └── 📁 sample-microservice/ (Test files)
│   ├── 📁 dashboard/ (Web interface)
│   │   ├── 📄 Dockerfile
│   │   └── 📁 src/
│   │       ├── 📄 index.html
│   │       ├── 📄 dashboard.js
│   │       └── 📄 styles.css
│   ├── 📁 sonarqube/ (SonarQube container)
│   ├── 📁 archunit/ (ArchUnit container)
│   └── 📁 roslyn/ (Roslyn container)
└── 📁 validation/ (Validation results)
    ├── 📄 simple_validation.py
    └── 📄 validation_summary.md

Key Detection Algorithms (in simple_real_detector.py)

  • Keyword Matching: Detects hardcoded connections and database patterns
  • Pattern Analysis: Identifies synchronous blocking operations
  • Regular Expressions: Finds credentials and method counts
  • Dependency Analysis: Detects circular dependencies between services
  • Complexity Metrics: Identifies god services (too many methods/dependencies)
Implementation Files:
• simple_real_detector.py - Core detection algorithms
• real_integrated_analyzer.py - Orchestrates detection
• dataset_specific_analyzer.py - Handles known test datasets

Frontend & Backend

The prototype has a web dashboard (frontend) that talks to a FastAPI service (backend). The screenshots show it running locally on four real projects.

🖥️ Frontend: dashboard

  • Plain HTML, CSS and JavaScript (services/dashboard/src)
  • Served by Nginx in its own container at localhost:3000
  • Shows the headline metrics, lets you pick one of the 4 test projects, and starts the analysis
  • Lists each finding with its severity, tool, file & line and a suggested fix

⚙️ Backend: REST API

  • Python + FastAPI (services/api/app/main.py) at localhost:8000
  • Plays the role of API Gateway + Lambda in the AWS design
  • Runs the detectors and returns results as JSON
GET/api/healthIs the service up?
POST/api/analysisStart an analysis
GET/api/analysis/{id}Analysis status
GET/api/analysis/{id}/resultsDetected anti-patterns

Screenshots: the dashboard on each test project

Click any image to open it full size.

Dashboard with gs-spring-boot selected

gs-spring-boot: dashboard with project selection and headline metrics

gs-spring-boot results

gs-spring-boot → 2 findings: hardcoded connection, synchronous blocking

Dashboard with spring-petclinic selected

spring-petclinic-microservices: analysis started

spring-petclinic results

spring-petclinic → 4 findings: shared persistence, distributed monolith, missing circuit breaker, hardcoded endpoints

Dashboard with sock-shop selected

sock-shop (Java, Node.js, Go): analysis started

sock-shop results

sock-shop → 5 findings: no API gateway, cyclic dependencies, hardcoded credentials, missing health check, synchronous communication

Dashboard with eShopOnContainers selected

eShopOnContainers (.NET): analysis started

eShopOnContainers results

eShopOnContainers → 6 findings, incl. Roslyn-concept checks: service intimacy, missing idempotency, shared libraries, data exposure

Mahyad Mirzabagheri · MSc Software Engineering, Staffordshire University · Source code on GitHub