Header Ads

Header ADS

SonarQube

 SonarQube কী?

1. SonarQube = Code Quality + Security Analysis Tool

2. SonarQube হলো একটি Static Code Analysis Platform    

👉 Static মানে:

Code run না করেই code analyse করা।

 

সহজভাবে:

তুমি কোড লিখছো → SonarQube তোমার কোড audit করে।

এটা দেখে:

✅ Bug আছে কিনা
✅ Security Vulnerability আছে কিনা
✅ Code Smell আছে কিনা
✅ Maintainability কেমন
✅ Test Coverage
✅ Technical Debt


🔥 Real Life Example

ধরো তুমি Sure Pay বা Event Flow backend লিখছো।

তুমি feature শেষ করেছো।

তখন Senior Engineer বলবে:

"Run SonarQube before merge."

কারণ:

  1. production এ bad code যাবে না
  2. security leak ধরা পড়বে
  3. clean architecture maintain হবে

🎯 SonarQube আসলে কী করে?

SonarQube automatically:

Source Code → Scan → Analyze → Report → Fix Suggestion
 

📊 SonarQube কী কী Detect করে

1️⃣ Bugs

Runtime problem তৈরি করতে পারে।

Example ❌

def divide(a, b):
    return a / b

Problem:

b = 0 হলে crash

SonarQube বলবে:

👉 Possible division by zero


2️⃣ Vulnerabilities (Security)

Example ❌

query = "SELECT * FROM users WHERE id=" + user_input

🔥 SQL Injection

SonarQube detect করবে।


3️⃣ Code Smell

Code কাজ করছে কিন্তু professional না।

Example ❌

if status == True:

Better:

if status:

4️⃣ Technical Debt

মানে:

পরে refactor করতে সময় লাগবে

Example:

  1. duplicate code

  2. huge function

  3. bad naming


5️⃣ Code Coverage

Test কত percent code cover করেছে।

Example:

Coverage: 35%

মানে testing weak।


🏗️ SonarQube Architecture 

Production engineer level concept 👇

Developer Code
      ↓
Sonar Scanner
      ↓
SonarQube Server
      ↓
Database
      ↓
Web Dashboard

Components

✅ SonarQube Server

Main engine।

  1. Rules execute করে
  2. Issue detect করে
  3. Report তৈরি করে

✅ Sonar Scanner

Code scan করে server এ পাঠায়।

Types:

  1. CLI Scanner
  2. Maven Scanner
  3. Gradle Scanner
  4. Docker Scanner
  5. GitHub Action Scanner

✅ Database

Stores:

  1. analysis history
  2. issues
  3. metrics

Recommended:  PostgreSQL

✅ Web Dashboard

Browser এ report দেখবে:

http://localhost:9000

🔥 CI/CD Integration 

Real companies manual scan করে না।

Used with:

  1. GitHub Actions

  2. GitLab CI

  3. Jenkins

  4. Azure DevOps

GitHub Actions Example

- name: SonarQube Scan
  run: sonar-scanner

🧠 Advanced Concepts

✅ Quality Gate

Rule set:

Example:

Coverage > 80%
No vulnerabilities
No critical bugs

Fail করলে merge block।


✅ Rules

SonarQube uses thousands rules:

Example:

  1. unused variable

  2. SQL injection

  3. memory leak

  4. bad naming


✅ Pull Request Analysis

PR open করলে automatically:

Comment → "You introduced 2 bugs"

🔥 Senior engineers love this.


🔥 Best Practice 

✅ Run scan before push
✅ Maintain >80% coverage
✅ Fix vulnerability immediately
✅ Never ignore critical issues



🧩 SonarQube Install using docker 

🧩 SonarQube Dashboard 

🧩 SonarQube Components and WorkFlow

🧩 Quality Gate 

 

 

 

 

 

 



Powered by Blogger.