סקירה מקיפה של הארכיטקטורה, מבנה השכבות, רכיבים מרכזיים ו-Design Patterns של מערכת Communication Hub.
מערכת Communication Hub בנויה בארכיטקטורת Layered Architecture (ארכיטקטורה שכבתית) עם הפרדה ברורה בין שכבות. המערכת מיישמת מספר Design Patterns מוכרים לשמירה על קוד נקי, ניתן לתחזוקה והרחבה.
HTML Templates, JavaScript Manager, Bootstrap 5 RTL
Flask Blueprints, RESTful Endpoints, WebSocket
CommunicationHubService, QueueManager, TemplateEngine
EmailAdapter, WhatsAppAdapter, SMSAdapter, PushAdapter
SQLAlchemy Models, PostgreSQL, Redis Cache
שכבת הממשק האחראית על הצגת הנתונים למשתמש ואיסוף קלט.
| רכיב | תיאור | טכנולוגיה |
|---|---|---|
| HTML Templates | 6 עמודי Jinja2 templates | Jinja2, Bootstrap 5 RTL |
| JavaScript Manager | CommunicationHubManager class | ES6+, Chart.js |
| CSS Styles | עיצוב מותאם RTL | Custom CSS, Bootstrap 5 |
// דוגמת אתחול JavaScript Manager
class CommunicationHubManager {
constructor() {
this.pageType = this.detectPageType();
this.initPage();
this.setupWebSocket();
}
detectPageType() {
const path = window.location.pathname;
if (path.includes('dashboard')) return 'dashboard';
if (path.includes('messages')) return 'messages';
// ...
}
}
שכבת ה-API מספקת ממשק RESTful לתקשורת בין ה-Frontend ל-Backend.
מרכז את כל ה-endpoints של המערכת
תמיכה בעדכונים בזמן אמת
הלב של המערכת - מכיל את כל הלוגיקה העסקית והתזמור בין הרכיבים.
# CommunicationHubService - שירות מרכזי
class CommunicationHubService:
def __init__(self):
self.adapters = {
'email': EmailAdapter(),
'whatsapp': WhatsAppAdapter(),
'sms': SMSAdapter(),
'push': PushAdapter()
}
self.queue_manager = MessageQueueManager()
self.template_engine = TemplateEngine()
def send_message(self, channel, recipient, content, **kwargs):
"""שליחת הודעה דרך ערוץ ספציפי"""
adapter = self.adapters.get(channel)
if not adapter:
raise ValueError(f"Unknown channel: {channel}")
# עיבוד תבנית אם יש
if kwargs.get('template_id'):
content = self.template_engine.render(
kwargs['template_id'],
kwargs.get('variables', {})
)
# הוספה לתור
return self.queue_manager.enqueue(
adapter=adapter,
recipient=recipient,
content=content,
priority=kwargs.get('priority', 'normal')
)
שכבת ה-Adapters מיישמת את דפוס ה-Adapter Pattern ליצירת ממשק אחיד לכל ערוצי התקשורת.
# Base Adapter Interface
class BaseChannelAdapter(ABC):
@abstractmethod
def send(self, recipient: str, content: str, **kwargs) -> dict:
"""שליחת הודעה"""
pass
@abstractmethod
def get_status(self, message_id: str) -> str:
"""בדיקת סטטוס הודעה"""
pass
@abstractmethod
def validate_recipient(self, recipient: str) -> bool:
"""אימות כתובת נמען"""
pass
# Email Adapter Implementation
class EmailAdapter(BaseChannelAdapter):
def __init__(self, config=None):
self.config = config or self._load_config()
self.smtp_client = None
def send(self, recipient, content, **kwargs):
subject = kwargs.get('subject', 'הודעה חדשה')
html_content = kwargs.get('html_content', content)
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = self.config['from_email']
msg['To'] = recipient
# ... SMTP sending logic
return {'message_id': msg_id, 'status': 'sent'}
שכבת הנתונים אחראית על שמירה ואחזור מידע מבסיס הנתונים.
המערכת מיישמת מספר Design Patterns מוכרים:
מאפשר ממשק אחיד לכל ערוצי התקשורת. כל Adapter מיישם את אותו interface בעוד הוא מתממשק לשירות חיצוני שונה.
adapter = self.adapters[channel]
adapter.send(recipient, content)
יצירת Adapters לפי סוג הערוץ. המערכת יודעת ליצור את ה-Adapter המתאים בהתאם לקונפיגורציה.
def get_adapter(channel_type):
return ADAPTER_FACTORY[channel_type]()
ניהול תור הודעות עם תמיכה בעדיפויות, ניסיונות חוזרים ועיבוד אסינכרוני.
queue_manager.enqueue(message, priority='high')
queue_manager.process_batch()
עיבוד תבניות עם משתנים דינמיים. מאפשר החלפת משתנים בתוכן ההודעה.
template.render({
'customer_name': 'ישראל',
'order_id': '12345'
})
עדכונים בזמן אמת דרך WebSocket. כל שינוי בסטטוס הודעה משודר לכל הצופים המעוניינים.
socketio.emit('message_status_changed', {
'message_id': msg_id,
'status': 'delivered'
})
CommunicationHubService מיושם כ-Singleton לוודא מופע יחיד במערכת.
hub = get_communication_hub() # Always same instance
app/
├── services/
│ └── communication_hub_service.py # שירות מרכזי
│
├── adapters/
│ ├── base_adapter.py # Base class
│ ├── email_adapter.py # Email implementation
│ ├── whatsapp_adapter.py # WhatsApp implementation
│ ├── sms_adapter.py # SMS implementation
│ └── push_adapter.py # Push implementation
│
├── models/
│ └── models_communication_hub.py # Database models
│
├── routes/
│ └── api_communication_hub.py # API endpoints
│
├── templates/
│ ├── communication-hub-dashboard.html
│ ├── communication-hub-messages.html
│ ├── communication-hub-templates.html
│ ├── communication-hub-channels.html
│ ├── communication-hub-campaigns.html
│ └── communication-hub-analytics.html
│
└── static/
├── js/
│ └── modules/
│ └── communication-hub-manager.js
│
└── docs/
└── communication-hub/ # תיעוד זה
├── index.html
├── architecture.html
├── database.html
├── api-reference.html
├── channels.html
├── templates.html
└── ui-guide.html