System design and architecture overview for GitLab Issues Analyzer.
A lightweight, event-driven system that monitors GitLab issues, analyzes them using AI, and sends email notifications. Designed to be simple, stateless, and deployable with minimal infrastructure.
- Stateless: No database, minimal state management
- Event-Driven: Responds to GitLab webhooks or polling events
- Modular: Separate components for monitoring, analysis, and notification
- Resilient: Error handling and retry logic
- Lightweight: Minimal dependencies and resource usage
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitLab Issues Analyzer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββ β
β β Monitor βββββββΆβ Analyzer βββββββΆβ Reporter β β
β β Component β β Component β β Component β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββ β
β β β β β
βββββββββββΌβββββββββββββββββββββββΌββββββββββββββββββββββΌβββββββββ
β β β
βΌ βΌ βΌ
βββββββββββ βββββββββββββββ ββββββββββββ
β GitLab β β OpenRouter β β SMTP β
β API β β API β β Server β
βββββββββββ βββββββββββββββ ββββββββββββ
Responsibility: Detect new GitLab issues
Modes:
- Webhook Mode: HTTP server that receives GitLab webhook events (real-time)
- Polling Mode: Periodically checks GitLab API for new issues
Key Functions:
start_webhook_server(): Start HTTP server for webhook eventspoll_gitlab_issues(): Periodically fetch new issuesvalidate_webhook(): Verify webhook authenticityextract_issue_data(): Parse issue information
State Management: File-based cache (analysis_cache.json) for processed issues
Responsibility: Analyze issues using AI API
Key Functions:
analyze_issue(issue_data): Main analysis functionfetch_comprehensive_issue_data(issue_iid): Fetch all issue dataprepare_prompt(issue_data): Format issue data into AI promptcall_ai_api(prompt, provider, model): Make API requestparse_analysis(response): Extract structured analysis
Supported AI Providers:
- OpenRouter (supports multiple models including DeepSeek with reasoning mode)
- OpenAI (gpt-4, gpt-4-turbo, gpt-3.5-turbo)
Analysis Framework: WWWH-TR (Why, What, Who, How, Test, Reflect)
Responsibility: Generate and send email reports
Key Functions:
generate_email_report(issue_data, analysis): Create email contentformat_html_email(issue_data, analysis): Generate HTML emailformat_text_email(issue_data, analysis): Generate plain text emailsend_email(report): Send via SMTP
Email Template: Includes issue information, WWWH-TR analysis, and footer
1. GitLab β Webhook Event β Monitor Component
2. Monitor β Validate & Extract Issue Data
3. Monitor β Fetch Comprehensive Issue Data
4. Monitor β Analyzer Component
5. Analyzer β AI API β Analysis Response
6. Analyzer β Reporter Component
7. Reporter β Generate Email β SMTP Server
8. Reporter β Email Delivered
1. Monitor β Poll GitLab API (every N minutes)
2. GitLab API β List of Issues
3. Monitor β Filter New Issues (check cache)
4. Monitor β Fetch Comprehensive Issue Data
5. Monitor β Analyzer Component
6. Analyzer β AI API β Analysis Response
7. Analyzer β Reporter Component
8. Reporter β Generate Email β SMTP Server
9. Reporter β Email Delivered
- Language: Python 3.9+
- HTTP Client:
requestslibrary - SMTP:
smtplib(built-in) - Web Framework:
Flask(for webhook mode and dashboard) - Configuration: Environment variables via
python-dotenv
- GitLab API: REST API v4
- OpenRouter API: Unified API for multiple AI models
- OpenAI API: ChatGPT models
- SMTP: Standard SMTP protocol
requests>=2.31.0
flask>=2.3.0
python-dotenv>=1.0.0
pytz>=2023.3
- Environment variables (from
.envfile or system environment) - Default values (for optional settings)
All configuration via environment variables. See Configuration Guide for details.
-
API Errors (GitLab, AI Provider)
- Retry with exponential backoff (3 attempts: 1s, 2s, 4s)
- Log error details
- Continue processing other issues
-
Email Errors (SMTP)
- Retry with exponential backoff
- Log error details
- Store error in cache for manual review
-
Configuration Errors
- Validate on startup
- Fail fast with clear error messages
-
Network Errors
- Retry logic with exponential backoff
- Timeout handling (30 seconds default)
- INFO: Normal operations (issue detected, email sent)
- WARNING: Recoverable errors (retry attempts)
- ERROR: Critical errors (API failures, email failures)
- DEBUG: Detailed debugging information
[TIMESTAMP] [LEVEL] [COMPONENT] MESSAGE
- Console output (stdout)
- Timezone-aware timestamps (configurable via
TIMEZONE)
- Never commit credentials to version control
- Use environment variables for sensitive data
.gitignorefor config files with secrets
- Validate webhook secret tokens
- Verify request signatures (if available)
- Rate limiting on webhook endpoint
- Store API keys securely (environment variables)
- Use HTTPS for all API calls
- Rotate credentials periodically
- No database required
- Minimal state in memory
- Process issues independently
- File-Based Cache:
data/analysis_cache.jsonfor persistence - Tracks processed issue IDs and analysis results
- Persists across restarts
- Webhook processing: < 1 second
- Issue analysis: 30-120 seconds (AI API, depends on model)
- Email sending: 1-5 seconds
- Total: 2-5 minutes per issue
- Memory: < 100MB
- CPU: Low (mostly I/O bound)
- Network: Minimal (API calls only)
- Docker/Docker Compose: Recommended, easy setup
- Cloud Platforms: Any platform supporting Docker
- Local: Direct Python execution
βββββββββββββββββββ
β Deployment β
β Platform β
β (Docker / β
β Cloud / β
β Local) β
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β GitLab Issues β
β Analyzer β
β Application β
ββββββββββ¬ββββββββββ
β
ββββββ΄βββββ
β β
βΌ βΌ
ββββββββββ ββββββββββββ
βGitLab β βOpenRouterβ
β API β β API β
ββββββββββ ββββββββββββ
- All operations logged
- Error tracking
- Performance metrics (optional)
- Health endpoint (
/health) - Configuration validation
- API connectivity checks
- Issue update notifications
- Multiple project support (already supported via global endpoint)
- Custom analysis templates
- Integration with other notification channels (Slack, Teams)
- Dashboard enhancements