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."
কারণ:
- production এ bad code যাবে না
- security leak ধরা পড়বে
- 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:
duplicate code
huge function
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।
- Rules execute করে
- Issue detect করে
- Report তৈরি করে
✅ Sonar Scanner
Code scan করে server এ পাঠায়।
Types:
- CLI Scanner
- Maven Scanner
- Gradle Scanner
- Docker Scanner
- GitHub Action Scanner
✅ Database
Stores:
- analysis history
- issues
- metrics
Recommended: PostgreSQL
✅ Web Dashboard
Browser এ report দেখবে:
http://localhost:9000
🔥 CI/CD Integration
Real companies manual scan করে না।
Used with:
GitHub Actions
GitLab CI
Jenkins
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:
unused variable
SQL injection
memory leak
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