1333 lines
61 KiB
HTML
1333 lines
61 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fa" dir="rtl">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>تحلیل جامع معماری راهکار xAi | گزارش فنی</title>
|
||
<style>
|
||
@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;600;700;800&display=swap');
|
||
|
||
:root {
|
||
--primary: #1a365d;
|
||
--primary-light: #2c5282;
|
||
--accent: #c9a961;
|
||
--accent-dark: #a8893f;
|
||
--bg: #faf9f6;
|
||
--card-bg: #ffffff;
|
||
--text: #1a202c;
|
||
--text-muted: #4a5568;
|
||
--border: #e2e8f0;
|
||
--success: #38a169;
|
||
--danger: #e53e3e;
|
||
--warning: #dd6b20;
|
||
--shadow: 0 4px 6px rgba(0,0,0,0.05), 0 10px 30px rgba(26,54,93,0.08);
|
||
}
|
||
|
||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||
|
||
body {
|
||
font-family: 'Vazirmatn', Tahoma, sans-serif;
|
||
background: var(--bg);
|
||
color: var(--text);
|
||
line-height: 1.9;
|
||
font-size: 15px;
|
||
padding: 30px 15px;
|
||
}
|
||
|
||
.document-container {
|
||
max-width: 950px;
|
||
margin: 0 auto;
|
||
background: var(--card-bg);
|
||
box-shadow: var(--shadow);
|
||
border-radius: 12px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.document-header {
|
||
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
|
||
color: white;
|
||
padding: 50px 40px 40px;
|
||
position: relative;
|
||
border-bottom: 4px solid var(--accent);
|
||
}
|
||
|
||
.document-header::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0; right: 0;
|
||
width: 200px; height: 200px;
|
||
background: radial-gradient(circle, rgba(201,169,97,0.15) 0%, transparent 70%);
|
||
border-radius: 50%;
|
||
transform: translate(50%, -50%);
|
||
}
|
||
|
||
.header-top {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 30px;
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
|
||
.company-badge { display: flex; align-items: center; gap: 12px; }
|
||
|
||
.company-logo {
|
||
width: 60px; height: 60px;
|
||
background: var(--accent);
|
||
border-radius: 12px;
|
||
box-shadow: 0 4px 12px rgba(0,0,0,0.2);
|
||
}
|
||
|
||
.doc-meta { text-align: left; font-size: 12px; opacity: 0.9; }
|
||
.doc-meta div { margin-bottom: 3px; }
|
||
|
||
.document-title { text-align: center; position: relative; z-index: 1; padding: 20px 0; }
|
||
|
||
.document-title .label {
|
||
display: inline-block;
|
||
background: rgba(201,169,97,0.2);
|
||
color: var(--accent);
|
||
padding: 4px 16px;
|
||
border-radius: 20px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
margin-bottom: 15px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-title h1 { font-size: 28px; font-weight: 800; margin-bottom: 10px; letter-spacing: -0.5px; }
|
||
.document-title h2 { font-size: 16px; font-weight: 400; opacity: 0.9; }
|
||
|
||
.document-body { padding: 40px; }
|
||
|
||
.intro-text {
|
||
background: linear-gradient(to left, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin-bottom: 35px;
|
||
font-size: 14px;
|
||
color: var(--text-muted);
|
||
}
|
||
|
||
.section { margin-bottom: 40px; page-break-inside: avoid; }
|
||
|
||
.section-header {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 15px;
|
||
padding-bottom: 12px;
|
||
border-bottom: 2px solid var(--border);
|
||
margin-bottom: 20px;
|
||
}
|
||
|
||
.section-number {
|
||
width: 50px; height: 50px;
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
border-radius: 12px;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
font-weight: 800;
|
||
font-size: 20px;
|
||
flex-shrink: 0;
|
||
box-shadow: 0 4px 10px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.section-title { flex: 1; }
|
||
.section-title h3 { font-size: 19px; font-weight: 700; color: var(--primary); margin-bottom: 2px; }
|
||
.section-title .subtitle { font-size: 12px; color: var(--text-muted); }
|
||
|
||
.section-content { padding-right: 10px; }
|
||
.section-content p { margin-bottom: 12px; text-align: justify; text-indent: 20px; }
|
||
.section-content p.no-indent { text-indent: 0; }
|
||
|
||
.highlight-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #f6e05e;
|
||
border-right: 4px solid var(--accent);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
.highlight-box strong { color: var(--accent-dark); }
|
||
|
||
.info-box {
|
||
background: linear-gradient(to left, #ebf8ff, #e6f6ff);
|
||
border: 1px solid #90cdf4;
|
||
border-right: 4px solid var(--primary-light);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.success-box {
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
border: 1px solid #9ae6b4;
|
||
border-right: 4px solid var(--success);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.warning-box {
|
||
background: linear-gradient(to left, #fffaf0, #fef5e7);
|
||
border: 1px solid #fbd38d;
|
||
border-right: 4px solid var(--warning);
|
||
padding: 18px 22px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.styled-table {
|
||
width: 100%;
|
||
border-collapse: collapse;
|
||
margin: 20px 0;
|
||
background: white;
|
||
border-radius: 8px;
|
||
overflow: hidden;
|
||
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
|
||
}
|
||
|
||
.styled-table thead {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
}
|
||
|
||
.styled-table th { padding: 14px 16px; text-align: right; font-weight: 600; font-size: 13px; }
|
||
.styled-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
|
||
.styled-table tbody tr:last-child td { border-bottom: none; }
|
||
.styled-table tbody tr:nth-child(even) { background: #f8fafc; }
|
||
.styled-table .highlight-row { background: #fffaf0 !important; font-weight: 600; }
|
||
|
||
.comparison-grid {
|
||
display: grid;
|
||
grid-template-columns: 1fr 1fr;
|
||
gap: 20px;
|
||
margin: 25px 0;
|
||
}
|
||
|
||
.comparison-card {
|
||
background: #f8fafc;
|
||
border: 2px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 20px;
|
||
position: relative;
|
||
}
|
||
|
||
.comparison-card.recommended {
|
||
border-color: var(--success);
|
||
background: linear-gradient(to left, #f0fff4, #e6fffa);
|
||
}
|
||
|
||
.comparison-card .card-badge {
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 20px;
|
||
background: var(--success);
|
||
color: white;
|
||
padding: 3px 12px;
|
||
border-radius: 15px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.comparison-card h4 {
|
||
font-size: 16px;
|
||
font-weight: 700;
|
||
color: var(--primary);
|
||
margin-bottom: 15px;
|
||
padding-bottom: 10px;
|
||
border-bottom: 2px solid var(--border);
|
||
}
|
||
|
||
.comparison-card.recommended h4 { border-bottom-color: var(--success); }
|
||
|
||
.comparison-card ul { list-style: none; padding: 0; }
|
||
|
||
.comparison-card ul li {
|
||
padding: 8px 0;
|
||
border-bottom: 1px solid var(--border);
|
||
font-size: 13px;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
gap: 10px;
|
||
}
|
||
|
||
.comparison-card ul li:last-child { border-bottom: none; }
|
||
.comparison-card ul li .value { font-weight: 600; color: var(--primary); }
|
||
|
||
.quote-box {
|
||
background: linear-gradient(135deg, #f7fafc, #edf2f7);
|
||
border-right: 4px solid var(--accent);
|
||
padding: 20px 25px;
|
||
border-radius: 8px;
|
||
margin: 20px 0;
|
||
position: relative;
|
||
}
|
||
|
||
.quote-box::before {
|
||
content: '"';
|
||
position: absolute;
|
||
top: -10px;
|
||
right: 15px;
|
||
font-size: 60px;
|
||
color: var(--accent);
|
||
opacity: 0.3;
|
||
font-family: Georgia, serif;
|
||
}
|
||
|
||
.quote-box p { font-style: italic; color: var(--text-muted); margin-bottom: 10px; text-indent: 0 !important; }
|
||
.quote-box .source { font-size: 12px; color: var(--text-muted); text-align: left; font-style: normal; }
|
||
|
||
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 25px 0; }
|
||
|
||
.stat-card {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 20px;
|
||
border-radius: 10px;
|
||
text-align: center;
|
||
box-shadow: 0 4px 12px rgba(26,54,93,0.2);
|
||
}
|
||
|
||
.stat-card .stat-value { font-size: 22px; font-weight: 800; margin-bottom: 5px; color: var(--accent); line-height: 1.3; }
|
||
.stat-card .stat-label { font-size: 12px; opacity: 0.9; }
|
||
|
||
.timeline { position: relative; padding: 20px 0; margin: 25px 0; }
|
||
|
||
.timeline::before {
|
||
content: '';
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 0; bottom: 0;
|
||
width: 3px;
|
||
background: var(--border);
|
||
transform: translateX(50%);
|
||
}
|
||
|
||
.timeline-item { display: flex; margin-bottom: 20px; position: relative; }
|
||
.timeline-item:nth-child(odd) { flex-direction: row-reverse; }
|
||
|
||
.timeline-content {
|
||
width: 45%;
|
||
background: #f8fafc;
|
||
border: 1px solid var(--border);
|
||
border-radius: 8px;
|
||
padding: 15px;
|
||
position: relative;
|
||
}
|
||
|
||
.timeline-item:nth-child(odd) .timeline-content { margin-left: 5%; }
|
||
.timeline-item:nth-child(even) .timeline-content { margin-right: 5%; }
|
||
|
||
.timeline-dot {
|
||
position: absolute;
|
||
right: 50%;
|
||
top: 20px;
|
||
width: 16px; height: 16px;
|
||
background: var(--accent);
|
||
border: 3px solid white;
|
||
border-radius: 50%;
|
||
transform: translateX(50%);
|
||
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
||
z-index: 1;
|
||
}
|
||
|
||
.timeline-content h5 { font-size: 14px; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
|
||
.timeline-content p { font-size: 12px; color: var(--text-muted); text-indent: 0 !important; margin-bottom: 0 !important; }
|
||
|
||
.reference-list { list-style: none; padding: 0; margin: 20px 0; }
|
||
|
||
.reference-list li {
|
||
background: #f8fafc;
|
||
border-right: 3px solid var(--primary-light);
|
||
padding: 15px 20px;
|
||
margin-bottom: 10px;
|
||
border-radius: 6px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
.reference-list li strong { color: var(--primary); display: block; margin-bottom: 5px; }
|
||
.reference-list li .ref-source { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
|
||
|
||
.conclusion-box {
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 30px;
|
||
border-radius: 12px;
|
||
margin: 30px 0;
|
||
text-align: center;
|
||
box-shadow: 0 8px 20px rgba(26,54,93,0.3);
|
||
}
|
||
|
||
.conclusion-box h3 { font-size: 22px; font-weight: 800; margin-bottom: 15px; color: var(--accent); }
|
||
.conclusion-box p { font-size: 14px; line-height: 1.8; text-indent: 0 !important; margin-bottom: 15px; }
|
||
|
||
.conclusion-box .highlight {
|
||
background: rgba(201,169,97,0.2);
|
||
padding: 15px 20px;
|
||
border-radius: 8px;
|
||
margin-top: 20px;
|
||
border: 1px solid rgba(201,169,97,0.4);
|
||
}
|
||
|
||
.document-footer {
|
||
background: var(--primary);
|
||
color: white;
|
||
padding: 25px 40px;
|
||
text-align: center;
|
||
font-size: 12px;
|
||
margin-top: 40px;
|
||
}
|
||
|
||
.document-footer .footer-brand { font-weight: 700; color: var(--accent); margin-bottom: 5px; font-size: 14px; }
|
||
.footer-divider { width: 60px; height: 2px; background: var(--accent); margin: 10px auto; }
|
||
|
||
.page-info {
|
||
text-align: center;
|
||
padding: 15px;
|
||
font-size: 11px;
|
||
color: var(--text-muted);
|
||
border-top: 1px solid var(--border);
|
||
margin-top: 30px;
|
||
}
|
||
|
||
code, .code-inline {
|
||
font-family: 'Consolas', 'Courier New', monospace;
|
||
background: #edf2f7;
|
||
color: #2d3748;
|
||
padding: 1px 6px;
|
||
border-radius: 4px;
|
||
font-size: 12px;
|
||
direction: ltr;
|
||
display: inline-block;
|
||
unicode-bidi: embed;
|
||
}
|
||
|
||
pre.code-block {
|
||
background: #1a202c;
|
||
color: #e2e8f0;
|
||
padding: 16px 20px;
|
||
border-radius: 8px;
|
||
overflow-x: auto;
|
||
font-size: 12px;
|
||
direction: ltr;
|
||
text-align: left;
|
||
line-height: 1.6;
|
||
margin: 15px 0;
|
||
font-family: 'Consolas', 'Courier New', monospace;
|
||
}
|
||
|
||
pre.code-block .kw { color: #f6ad55; }
|
||
pre.code-block .st { color: #9ae6b4; }
|
||
pre.code-block .cm { color: #718096; font-style: italic; }
|
||
|
||
.arch-diagram {
|
||
background: #f8fafc;
|
||
border: 1px solid var(--border);
|
||
border-radius: 10px;
|
||
padding: 25px;
|
||
margin: 20px 0;
|
||
text-align: center;
|
||
direction: ltr;
|
||
overflow-x: auto;
|
||
}
|
||
|
||
.arch-layer {
|
||
display: inline-block;
|
||
background: linear-gradient(135deg, var(--primary), var(--primary-light));
|
||
color: white;
|
||
padding: 10px 18px;
|
||
border-radius: 8px;
|
||
margin: 6px;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.arch-layer.accent { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #1a202c; }
|
||
.arch-layer.success { background: linear-gradient(135deg, var(--success), #2f855a); }
|
||
.arch-arrow { color: var(--text-muted); font-size: 18px; margin: 0 6px; vertical-align: middle; }
|
||
|
||
ul.styled-list { padding-right: 20px; margin-top: 10px; }
|
||
ul.styled-list li { margin-bottom: 8px; }
|
||
|
||
.tag {
|
||
display: inline-block;
|
||
background: #ebf8ff;
|
||
color: var(--primary-light);
|
||
border: 1px solid #90cdf4;
|
||
padding: 2px 10px;
|
||
border-radius: 12px;
|
||
font-size: 11px;
|
||
margin: 2px 3px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.tag.risk { background: #fff5f5; color: var(--danger); border-color: #feb2b2; }
|
||
.tag.ok { background: #f0fff4; color: var(--success); border-color: #9ae6b4; }
|
||
.tag.warn { background: #fffaf0; color: var(--warning); border-color: #fbd38d; }
|
||
|
||
@media print {
|
||
body { background: white; padding: 0; }
|
||
.document-container { box-shadow: none; border-radius: 0; }
|
||
.section { page-break-inside: avoid; }
|
||
}
|
||
|
||
@media (max-width: 768px) {
|
||
.document-body { padding: 25px 20px; }
|
||
.document-header { padding: 30px 20px; }
|
||
.comparison-grid { grid-template-columns: 1fr; }
|
||
.stats-grid { grid-template-columns: 1fr; }
|
||
.header-top { flex-direction: column; gap: 15px; }
|
||
.doc-meta { text-align: center; }
|
||
.timeline::before { right: 20px; }
|
||
.timeline-item { flex-direction: column !important; }
|
||
.timeline-content { width: 85% !important; margin-right: 40px !important; margin-left: 0 !important; }
|
||
.timeline-dot { right: 12px; transform: none; }
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<div class="document-container">
|
||
|
||
<header class="document-header">
|
||
<div class="header-top">
|
||
<div class="company-badge">
|
||
<div class="company-logo"></div>
|
||
</div>
|
||
<div class="doc-meta">
|
||
<div>شماره مستند: ARCH-1405-001</div>
|
||
<div>نسخه: ۱.۰</div>
|
||
<div>تاریخ تهیه: آبان ۱۴۰۵</div>
|
||
<div>طبقهبندی: محرمانه</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="document-title">
|
||
<span class="label">TECHNICAL ARCHITECTURE REPORT</span>
|
||
<h1>تحلیل جامع معماری راهکار xAi</h1>
|
||
<h2>بررسی ساختار، لایهها، جریان داده و ارزیابی فنی راهکار</h2>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="document-body">
|
||
|
||
<div class="intro-text">
|
||
<strong>خواننده محترم،</strong><br>
|
||
این مستند بهعنوان تحلیلی جامع و ساختارمند از معماری راهکار <strong>xAi</strong> (شامل سرویسهای <code class="code-inline">xAiApi</code>، <code class="code-inline">xAiModels</code>، <code class="code-inline">xAiService</code> و <code class="code-inline">xAiMcpServer</code>) تهیه شده است. هدف از این گزارش، تشریح لایهبندی، جریانهای داده، الگوهای طراحی، مزایا و نقاط قابل بهبود این راهکار است تا تصمیمگیریهای فنی و برنامهریزی بلندمدت بر پایه دیدی شفاف و دقیق انجام شود.
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 1: EXECUTIVE SUMMARY
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱</div>
|
||
<div class="section-title">
|
||
<h3>خلاصه اجرایی</h3>
|
||
<div class="subtitle">Executive Summary</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>راهکار <strong>xAi</strong> یک پلتفرم جامع هوش مصنوعی است که با تمرکز بر انعطافپذیری، جداسازی مسئولیتها و قابلیت توسعه، طراحی شده است. این راهکار از یک معماری چندلایه مبتنی بر اصول <em>Clean Architecture</em> بهره میبرد که در آن لایههای ارائه (API)، دامنه (Models)، سرویس و زیرساخت بهصورت شفاف از یکدیگر جدا شدهاند.</p>
|
||
|
||
<div class="stats-grid">
|
||
<div class="stat-card">
|
||
<div class="stat-value">۴</div>
|
||
<div class="stat-label">پروژه اصلی مستقل و یکپارچه</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">۸</div>
|
||
<div class="stat-label">ماژول دامنه در لایه Models</div>
|
||
</div>
|
||
<div class="stat-card">
|
||
<div class="stat-value">۱۵+</div>
|
||
<div class="stat-label">Extractor برای فرمتهای مختلف</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="highlight-box">
|
||
<strong>نتیجه کلیدی:</strong> راهکار xAi با پشتیبانی همزمان از دو الگوی RAG (In-Memory و Persistent)، یکپارچهسازی پروتکل MCP، پشتیبانی از Providers متنوع (OpenAI/Ollama)، و استخراج محتوا از بیش از ۱۵ فرمت فایل، یک پلتفرم بالغ و آماده استفاده سازمانی محسوب میشود.
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">پروژههای اصلی راهکار:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>پروژه</th>
|
||
<th>نقش</th>
|
||
<th>خروجی</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>xAiApi</strong></td>
|
||
<td>بکاند اصلی و نقطه ورود API</td>
|
||
<td>REST API + SSE Streaming</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>xAiModels</strong></td>
|
||
<td>لایه دامنه و موجودیتها</td>
|
||
<td>Entities, DTOs, Repositories</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>xAiService</strong></td>
|
||
<td>پیادهسازی پروتکل MCP</td>
|
||
<td>MCP Server (JSON-RPC)</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>xAiMcpServer</strong></td>
|
||
<td>میزبان ابزارهای MCP</td>
|
||
<td>Endpoint /mcp</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 2: ARCHITECTURE
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۲</div>
|
||
<div class="section-title">
|
||
<h3>معماری کلی و لایهبندی</h3>
|
||
<div class="subtitle">Layered Architecture & Separation of Concerns</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>راهکار xAi بر پایه یک معماری چندلایه با جهت وابستگی یکطرفه (از خارج به داخل) شکل گرفته است. هر لایه مسئولیت مشخصی دارد و از طریق قراردادها (Interfaces) با لایههای دیگر تعامل میکند.</p>
|
||
|
||
<div class="arch-diagram">
|
||
<div>
|
||
<span class="arch-layer accent">Client / Browser / Mobile</span>
|
||
</div>
|
||
<div style="margin: 8px 0;"><span class="arch-arrow">↓</span></div>
|
||
<div>
|
||
<span class="arch-layer">xAiApi</span>
|
||
<span class="arch-layer">xAiMcpServer</span>
|
||
</div>
|
||
<div style="margin: 8px 0;"><span class="arch-arrow">↓</span></div>
|
||
<div>
|
||
<span class="arch-layer success">xAiService</span>
|
||
</div>
|
||
<div style="margin: 8px 0;"><span class="arch-arrow">↓</span></div>
|
||
<div>
|
||
<span class="arch-layer">xAiModels (Domain)</span>
|
||
<span class="arch-layer">xIdentityService</span>
|
||
<span class="arch-layer">xDataService</span>
|
||
</div>
|
||
<div style="margin: 8px 0;"><span class="arch-arrow">↓</span></div>
|
||
<div>
|
||
<span class="arch-layer accent">EF Core / Mongo / InMemory</span>
|
||
</div>
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">پروژههای پایه مشترک:</h4>
|
||
<ul class="styled-list">
|
||
<li><strong>xCommons:</strong> تنظیمات، CORS، Swagger، اعتبارسنجی، Extension Methods پایه</li>
|
||
<li><strong>xDataService:</strong> Abstraction برای EF، Mongo و InMemory با الگوی Repository/Provider</li>
|
||
<li><strong>xIdentityService:</strong> احراز هویت OAuth2 + API Key + Policy-based Authorization</li>
|
||
<li><strong>xPushService:</strong> SignalR Hub برای اعلانهای Real-Time</li>
|
||
<li><strong>xFileService / xTagService / xStringService:</strong> سرویسهای جانبی دامنه</li>
|
||
<li><strong>xExceptions / xModels:</strong> مدیریت خطا و DTOهای پایه مشترک</li>
|
||
</ul>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 مزیت معماری:</strong> جدا بودن لایه دامنه (xAiModels) از لایه ارائه (xAiApi) این امکان را فراهم میکند که همان مدلهای دامنه در چند پروژه مصرفکننده (مثل xAiApi و xAiMcpServer) بدون تکرار کد مورد استفاده قرار گیرند. این موضوع بهطور مستقیم باعث افزایش <em>Reusability</em> و کاهش <em>Coupling</em> میشود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 3: DATA MODEL
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۳</div>
|
||
<div class="section-title">
|
||
<h3>مدل داده و پایگاهداده</h3>
|
||
<div class="subtitle">Data Model & Persistence Layer</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>لایه داده در راهکار xAi از الگوی <strong>Repository + Provider + Service</strong> استفاده میکند که امکان جابجایی بین سه نوع Repository (EF Core / MongoDB / InMemory) را بدون تغییر در لایههای بالاتر فراهم میآورد.</p>
|
||
|
||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">جدولهای اصلی پایگاهداده:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>جدول</th>
|
||
<th>هدف</th>
|
||
<th>کلیدهای مهم</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>AiProjects</strong></td>
|
||
<td>پروژههای AI هر کاربر</td>
|
||
<td>Id, OwnerId, Title, Prompt</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>AiConversations</strong></td>
|
||
<td>گفتگوهای هر پروژه</td>
|
||
<td>Id, ProjectId, OwnerId</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>AiMessages</strong></td>
|
||
<td>پیامهای هر گفتگو</td>
|
||
<td>Id, ConversationId, Role, Content</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>AiVectors</strong></td>
|
||
<td>بردارهای RAG و دانش پایدار</td>
|
||
<td>Id, Identifier (indexed), Type (indexed)</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>AiMcpServers</strong></td>
|
||
<td>سرورهای MCP ثبتشده</td>
|
||
<td>Id, OwnerId, Scope, Endpoint, Enabled</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td>Files / Tags / Strings</td>
|
||
<td colspan="2">جداول سرویسهای جانبی مشترک</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">الگوی Identifier در جدول AiVectors:</h4>
|
||
<p class="no-indent">برای جداسازی دامنه دانش (Knowledge Scope)، از یک الگوی Identifier سلسلهمراتبی استفاده میشود:</p>
|
||
|
||
<pre class="code-block"><span class="cm">// شناسهی هر تکه (Chunk) از یک سند</span>
|
||
conversation/{conversationId}/{fileName}#{chunkIndex}
|
||
project/{projectId}/{fileName}#{chunkIndex}
|
||
user/{ownerId}/{fileName}#{chunkIndex}
|
||
global/{fileName}#{chunkIndex}</pre>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ مزیت طراحی:</strong> با استفاده از <code class="code-inline">StartsWith(prefix)</code> روی ستون Indexed <code class="code-inline">Identifier</code>، جستجوی Scope-Based بسیار سریع انجام میشود و بدون نیاز به Join، جداسازی دادهی کاربران و پروژهها تضمین میگردد.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 4: RAG PIPELINES
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۴</div>
|
||
<div class="section-title">
|
||
<h3>دو مسیر RAG: In-Memory و Persistent</h3>
|
||
<div class="subtitle">ChatWithDocuments vs. Knowledge</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>راهکار xAi دو رویکرد مکمل برای RAG ارائه میدهد که هرکدام برای سناریوی متفاوتی بهینه شدهاند:</p>
|
||
|
||
<div class="comparison-grid">
|
||
<div class="comparison-card">
|
||
<h4>ChatWithDocuments (In-Memory)</h4>
|
||
<ul>
|
||
<li><span>ذخیرهسازی</span> <span class="value">حافظه موقت (ConcurrentDictionary)</span></li>
|
||
<li><span>عمر داده</span> <span class="value">TTL-Based (پیشفرض ۳۰ دقیقه)</span></li>
|
||
<li><span>مناسب برای</span> <span class="value">گفتگوی موقت با فایل</span></li>
|
||
<li><span>پاکسازی</span> <span class="value">BackgroundService</span></li>
|
||
<li><span>Scope</span> <span class="value">Session-Only</span></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="comparison-card recommended">
|
||
<span class="card-badge">توصیه شده برای دانش پایدار ✓</span>
|
||
<h4>Knowledge (Persistent)</h4>
|
||
<ul>
|
||
<li><span>ذخیرهسازی</span> <span class="value">جدول AiVectors در دیتابیس</span></li>
|
||
<li><span>عمر داده</span> <span class="value">دائمی تا حذف دستی</span></li>
|
||
<li><span>مناسب برای</span> <span class="value">پایگاه دانش سازمانی</span></li>
|
||
<li><span>پاکسازی</span> <span class="value">فقط در صورت درخواست</span></li>
|
||
<li><span>Scope</span> <span class="value">Conversation/Project/User/Global</span></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">جریان کامل Ingest (درج داده):</h4>
|
||
<div class="timeline">
|
||
<div class="timeline-item">
|
||
<div class="timeline-content">
|
||
<h5>۱. دریافت فایل</h5>
|
||
<p>آپلود از طریق multipart/form-data با اعتبارسنجی اندازه، تعداد و MIME Type</p>
|
||
</div>
|
||
<div class="timeline-dot"></div>
|
||
<div style="width: 45%;"></div>
|
||
</div>
|
||
<div class="timeline-item">
|
||
<div class="timeline-content">
|
||
<h5>۲. استخراج محتوا</h5>
|
||
<p>انتخاب Extractor مناسب (PDF، Word، Excel، Audio، Vision و ...) و تولید XFileExtractionResult</p>
|
||
</div>
|
||
<div class="timeline-dot"></div>
|
||
<div style="width: 45%;"></div>
|
||
</div>
|
||
<div class="timeline-item">
|
||
<div class="timeline-content">
|
||
<h5>۳. قطعهبندی متن</h5>
|
||
<p>XTextChunker با استراتژی سلسلهمراتبی (Paragraph → Sentence → Word) و Overlap</p>
|
||
</div>
|
||
<div class="timeline-dot"></div>
|
||
<div style="width: 45%;"></div>
|
||
</div>
|
||
<div class="timeline-item">
|
||
<div class="timeline-content">
|
||
<h5>۴. تولید Embedding</h5>
|
||
<p>فراخوانی مدل Embedding (پیشفرض: "Embed") بهصورت Batch و نرمالسازی برداری</p>
|
||
</div>
|
||
<div class="timeline-dot"></div>
|
||
<div style="width: 45%;"></div>
|
||
</div>
|
||
<div class="timeline-item">
|
||
<div class="timeline-content">
|
||
<h5>۵. ذخیرهسازی</h5>
|
||
<p>Upsert به AiVectors (Persistent) یا Add به Session (In-Memory) همراه با Metadata</p>
|
||
</div>
|
||
<div class="timeline-dot"></div>
|
||
<div style="width: 45%;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">جریان Retrieve (بازیابی) در Knowledge:</h4>
|
||
<p class="no-indent">در جستجوی دانش، بازیابی بهصورت <strong>Tiered (لایهای)</strong> انجام میشود تا اولویتبندی طبیعی حفظ شود:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>ترتیب</th>
|
||
<th>لایه (Scope)</th>
|
||
<th>منطق</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>۱</td><td>Conversation</td><td>دقیقترین و مرتبطترین (اگر Conversation داده شود)</td></tr>
|
||
<tr><td>۲</td><td>Project</td><td>دانش عمومی پروژه</td></tr>
|
||
<tr><td>۳</td><td>User</td><td>دانش شخصی کاربر</td></tr>
|
||
<tr><td>۴</td><td>Global</td><td>دانش سازمانی عمومی</td></tr>
|
||
<tr class="highlight-row">
|
||
<td colspan="3"><strong>هر لایه، TopK باقیمانده را پر میکند و از تکرار (Duplicate) جلوگیری میشود.</strong></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 5: AI SERVICE LAYER
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۵</div>
|
||
<div class="section-title">
|
||
<h3>لایه سرویس AI و انتزاع مدلها</h3>
|
||
<div class="subtitle">Model Abstraction & Provider Agnosticism</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>لایه سرویس AI با تکیه بر <code class="code-inline">Microsoft.Extensions.AI</code> یک انتزاع یکپارچه از مدلها ارائه میدهد. این موضوع باعث میشود تعویض Provider (مثلاً از Ollama به OpenAI) تنها با تغییر در Configuration انجام شود، بدون نیاز به تغییر کد.</p>
|
||
|
||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">Providers پشتیبانیشده:</h4>
|
||
<p class="no-indent">
|
||
<span class="tag ok">OpenAI</span>
|
||
<span class="tag ok">Ollama</span>
|
||
<span class="tag warn">DeepSeek (اسکلت)</span>
|
||
<span class="tag warn">HuggingFace (اسکلت)</span>
|
||
</p>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">مسیرهای اصلی سرویس AI:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>متد</th>
|
||
<th>نوع پاسخ</th>
|
||
<th>کاربرد</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>AskTextAsync</td><td>Sync</td><td>سؤال ساده بدون RAG</td></tr>
|
||
<tr><td>AskTextAsEnumerable</td><td>Stream</td><td>پاسخ Streaming ساده</td></tr>
|
||
<tr><td>AskTextFromKnowledgeAsync</td><td>Sync</td><td>RAG بدون تاریخچه</td></tr>
|
||
<tr><td>AskAsync</td><td>Sync</td><td>RAG + Persist Message</td></tr>
|
||
<tr><td>AskAsEnumerable</td><td>Stream</td><td>RAG + Stream + Persist</td></tr>
|
||
<tr class="highlight-row"><td>AskWithFilesAsync</td><td>Sync</td><td>RAG + فایل پیوست</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 نکته کلیدی:</strong> الگوی <code class="code-inline">XPreparedChatContext</code> بهعنوان یک DTO واسط، خروجی همه مراحل آمادهسازی (Project، Conversation، History، Context) را در یک ساختار واحد بستهبندی میکند. این الگو خوانایی و قابلیت تست کد را بهطور چشمگیری بالا میبرد.
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">استراتژی حافظه (Memory Strategy):</h4>
|
||
<p class="no-indent">در متد <code class="code-inline">PrepareMemory</code> تاریخچه گفتگو بههمراه Context و Project Prompt به یک بسته واحد تبدیل میشود:</p>
|
||
|
||
<pre class="code-block"><span class="cm">// System Message = Introduction + RAG Prompt + Context + Project Prompt</span>
|
||
[System]: <span class="st">"شما یک دستیار هوشمند هستید..."</span>
|
||
+ <span class="st">"پاسخ را فقط بر اساس Context زیر بده..."</span>
|
||
+ ContextBlock
|
||
+ Project.Prompt
|
||
|
||
<span class="cm">// سپس تاریخچه گفتگو (به ترتیب زمانی)</span>
|
||
[User]: ... [Assistant]: ... [User]: ...</pre>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 6: MCP INTEGRATION
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۶</div>
|
||
<div class="section-title">
|
||
<h3>یکپارچهسازی پروتکل MCP (Model Context Protocol)</h3>
|
||
<div class="subtitle">MCP Client & Server Integration</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>راهکار xAi هر دو نقش Client و Server پروتکل MCP را پیادهسازی میکند و از این نظر یک راهکار بالغ و آیندهنگر محسوب میشود:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>نقش</th>
|
||
<th>پیادهسازی</th>
|
||
<th>پروژه</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>MCP Client</strong></td>
|
||
<td>اتصال به سرورهای خارجی، کشف ابزارها، فراخوانی</td>
|
||
<td>xAiApi → XAiMcpServerProvider</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>MCP Server</strong></td>
|
||
<td>افشای ابزارهای داخلی از طریق JSON-RPC</td>
|
||
<td>xAiService → XAiMcpHandler</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">نحوه ثبت ابزارها در سمت سرور (Server):</h4>
|
||
<p class="no-indent">با استفاده از سه Attribute ساده، هر متد عمومی میتواند بهعنوان یک MCP Tool در دسترس LLM قرار گیرد:</p>
|
||
|
||
<pre class="code-block"><span class="kw">[XAiMcpToolType]</span>
|
||
<span class="kw">public static class</span> XEchoTools
|
||
{
|
||
<span class="kw">[XAiMcpTool</span>(Description = <span class="st">"Echoes the string back"</span>)]
|
||
<span class="kw">public static string</span> Echo(
|
||
<span class="kw">[XAiMcpToolParam</span>(Description = <span class="st">"message to echo"</span>)]
|
||
<span class="kw">string</span> message)
|
||
{
|
||
<span class="kw">return</span> $<span class="st">"hello {message}"</span>;
|
||
}
|
||
}</pre>
|
||
|
||
<p class="no-indent">فرآیند اسکن (<code class="code-inline">XAiMcpToolScanner</code>) بهصورت Reflection-Based انجام میشود و از <code class="code-inline">Lazy<T></code> برای جلوگیری از اسکن تکراری و بهینهسازی Performance استفاده میکند.</p>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">نحوه استفاده در سمت کلاینت (Client):</h4>
|
||
<p class="no-indent">هنگام فراخوانی مدل AI، ابزارهای تمام سرورهای MCP فعال و مجاز کاربر بهطور خودکار به <code class="code-inline">ChatOptions.Tools</code> تزریق میشوند:</p>
|
||
|
||
<pre class="code-block"><span class="kw">var</span> availableTools = <span class="kw">await</span> mcpServerProvider
|
||
.GetAvailableToolsAsync(userInfo, ct);
|
||
|
||
Options.Tools = [..availableTools.Cast<AITool>()];
|
||
|
||
<span class="kw">var</span> response = <span class="kw">await</span> client.GetResponseAsync(
|
||
options: Options, messages: history);</pre>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ مزیت بزرگ:</strong> ترکیب دو قابلیت <code class="code-inline">UseFunctionInvocation()</code> (از Microsoft.Extensions.AI) و MCP Tools، به LLM این امکان را میدهد که بهصورت خودکار تشخیص دهد چه زمانی باید ابزار را فراخوانی کند و پاسخ را با نتیجه ترکیب نماید.
|
||
</div>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">مدیریت چرخه حیات MCP Client:</h4>
|
||
<ul class="styled-list">
|
||
<li><strong>اتصال تنبل (Lazy):</strong> اتصال به سرورها فقط هنگام اولین نیاز و با <code class="code-inline">SemaphoreSlim</code></li>
|
||
<li><strong>Timeout اختصاصی:</strong> هر سرور Timeout مجزا دارد (حداقل ۳۰ ثانیه)</li>
|
||
<li><strong>Refresh:</strong> Endpoint مستقل برای اتصال مجدد بدون restart سرویس</li>
|
||
<li><strong>Ownership:</strong> هر کاربر فقط به سرورهای خودش یا سرورهای Global (Scope=All) دسترسی دارد</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 7: FILE EXTRACTION
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۷</div>
|
||
<div class="section-title">
|
||
<h3>خط لوله استخراج محتوا از فایل</h3>
|
||
<div class="subtitle">Multi-Format File Content Extraction Pipeline</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>یکی از نقاط قوت بارز راهکار، پشتیبانی از بیش از ۱۵ فرمت فایل با استفاده از الگوی <strong>Composite Extractor</strong> است. هر Extractor مسئول یک یا چند MIME Type است و بهصورت مستقل ثبت میشود.</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Extractor</th>
|
||
<th>فرمتهای پشتیبانیشده</th>
|
||
<th>کتابخانه</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>XPdfFileContentExtractor</td><td>PDF (متنی + اسکنشده)</td><td>PdfPig + PDFtoImage</td></tr>
|
||
<tr><td>XDocxFileContentExtractor</td><td>DOCX</td><td>DocumentFormat.OpenXml</td></tr>
|
||
<tr><td>XExcelFileContentExtractor</td><td>XLSX / XLS</td><td>ExcelDataReader</td></tr>
|
||
<tr><td>XPowerPointFileContentExtractor</td><td>PPTX / PPT</td><td>OpenXML + OfficeIMO</td></tr>
|
||
<tr><td>XOpenDocumentFileContentExtractor</td><td>ODT / ODS / ODP</td><td>OfficeIMO.OpenDocument</td></tr>
|
||
<tr><td>XHtmlFileContentExtractor</td><td>HTML / XHTML</td><td>HtmlAgilityPack</td></tr>
|
||
<tr><td>XEpubFileContentExtractor</td><td>EPUB</td><td>VersOne.Epub</td></tr>
|
||
<tr><td>XRtfFileContentExtractor</td><td>RTF</td><td>RtfPipe</td></tr>
|
||
<tr><td>XCodeFileContentExtractor</td><td>C#، Python، JS، Go، Rust و ...</td><td>StreamReader</td></tr>
|
||
<tr><td>XImageFileContentExtractor</td><td>PNG، JPG، WebP و ...</td><td>Tesseract OCR</td></tr>
|
||
<tr><td>XAudioFileContentExtractor</td><td>MP3، WAV، M4A و ...</td><td>FFMpegCore + Whisper.net</td></tr>
|
||
<tr><td>XVisionFileContentExtractor</td><td>تصاویر و PDF (Vision AI)</td><td>Vision Model</td></tr>
|
||
<tr class="highlight-row"><td>XPlainTextFileContentExtractor</td><td>TXT، MD، CSV، JSON، XML</td><td>StreamReader</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="info-box">
|
||
<strong>💡 Fallback هوشمند PDF:</strong> اگر متن استخراجشده از PDF کوتاهتر از حد آستانه (<code class="code-inline">MinTextLengthThreshold</code>) باشد، سیستم بهطور خودکار به استخراج تصویری Fallback میکند و صفحات را به تصویر تبدیل میکند تا توسط Vision Model پردازش شوند. این رویکرد برای PDFهای اسکنشده حیاتی است.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 8: AUTH & SECURITY
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۸</div>
|
||
<div class="section-title">
|
||
<h3>احراز هویت، مجوزدهی و امنیت</h3>
|
||
<div class="subtitle">Authentication, Authorization & Security</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>لایه امنیتی راهکار xAi بر پایه استانداردهای OAuth2 و ASP.NET Core Identity بنا شده و از چندین مکانیزم موازی پشتیبانی میکند:</p>
|
||
|
||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">مکانیزمهای احراز هویت:</h4>
|
||
<ul class="styled-list">
|
||
<li><strong>OAuth2 Introspection:</strong> اعتبارسنجی توکنهای JWT با استفاده از Introspection Endpoint</li>
|
||
<li><strong>API Key:</strong> اعتبارسنجی توکنهای CLI/Server-to-Server با API Key اختصاصی</li>
|
||
<li><strong>Policy-Based Authorization:</strong> استفاده از Policyهایی مانند <code class="code-inline">EnabledUser</code> و <code class="code-inline">EnabledAdmin</code></li>
|
||
</ul>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">جدول دسترسی پیشفرض:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>Endpoint</th>
|
||
<th>Policy</th>
|
||
<th>سطح دسترسی</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>GET /AskText</td><td>EnabledUser</td><td>کاربر عادی</td></tr>
|
||
<tr><td>POST /Knowledge/Ingest</td><td>EnabledAdmin</td><td>فقط ادمین (Global Scope)</td></tr>
|
||
<tr><td>POST /McpServers</td><td>EnabledUser</td><td>کاربر عادی</td></tr>
|
||
<tr><td>POST /McpServers/Refresh</td><td>EnabledAdmin</td><td>فقط ادمین</td></tr>
|
||
<tr class="highlight-row"><td>GET /Projects</td><td>EnabledUser</td><td>هر کاربر فقط پروژههای خودش</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">کنترل دسترسی در سطح داده (Data-Level ACL):</h4>
|
||
<p class="no-indent">در سرویس <code class="code-inline">XAiRAGService</code>، جداسازی دادهها با چند لایه محافظت انجام میشود:</p>
|
||
<ul class="styled-list">
|
||
<li><strong>User Scope:</strong> هر کاربر فقط به دادههای خودش (<code class="code-inline">user/{userId}/</code>) دسترسی دارد</li>
|
||
<li><strong>Project/Conversation Scope:</strong> بررسی مالکیت با <code class="code-inline">EnsureProjectOwner</code> و <code class="code-inline">EnsureConversationOwner</code></li>
|
||
<li><strong>Global Scope:</strong> خواندن برای همه، نوشتن فقط برای ادمین</li>
|
||
</ul>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠️ نکته امنیتی قابل توجه:</strong> در <code class="code-inline">Startup.cs</code> هر دو پروژه، <code class="code-inline">ServerCertificateCustomValidationCallback</code> بهطور کامل غیرفعال شده است. این تنظیم باعث میشود گواهی SSL سرور OAuth2 اصلاً اعتبارسنجی نشود. این تنظیم مناسب محیط توسعه است، اما در Production توصیه نمیشود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 9: STREAMING & SSE
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۹</div>
|
||
<div class="section-title">
|
||
<h3>پاسخ جریانی (Streaming) با SSE</h3>
|
||
<div class="subtitle">Server-Sent Events Streaming</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>تمام Endpointهای پرسش، نسخه Streaming هم دارند که از پروتکل <strong>SSE (Server-Sent Events)</strong> استفاده میکند. این رویکرد به کاربر این امکان را میدهد که پاسخ را بهصورت بلادرنگ ببیند، بدون نیاز به انتظار برای تکمیل کل پاسخ.</p>
|
||
|
||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">قالب رویدادهای ChatWithDocuments (AskStream):</h4>
|
||
|
||
<pre class="code-block"><span class="cm">// Event 1: Sources</span>
|
||
data: { <span class="st">"text"</span>: <span class="st">""</span>, <span class="st">"sources"</span>: [{<span class="st">"fileName"</span>: <span class="st">"doc.pdf"</span>, <span class="st">"score"</span>: 0.87, ...}] }
|
||
|
||
<span class="cm">// Event 2..N: Text Deltas</span>
|
||
data: { <span class="st">"text"</span>: <span class="st">"پاسخ به"</span> }
|
||
data: { <span class="st">"text"</span>: <span class="st">" سؤال شما"</span> }
|
||
...
|
||
|
||
<span class="cm">// Final Event</span>
|
||
data: { <span class="st">"text"</span>: <span class="st">""</span>, <span class="st">"isFinal"</span>: true }
|
||
|
||
<span class="cm">// End</span>
|
||
data: [DONE]</pre>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">مدیریت خطا در حالت Streaming:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>وضعیت</th>
|
||
<th>رفتار</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>خطا قبل از شروع Stream</td><td>پاسخ HTTP 400/500 استاندارد JSON</td></tr>
|
||
<tr><td>خطا پس از شروع Stream</td><td>ارسال SSE Event حاوی Error</td></tr>
|
||
<tr><td>قطع اتصال کلاینت</td><td>توقف بیصدا و آزادسازی منابع</td></tr>
|
||
<tr class="highlight-row"><td>Cancellation</td><td>پشتیبانی کامل از CancellationToken در همه لایهها</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="success-box">
|
||
<strong>✓ الگوی صحیح:</strong> استفاده از <code class="code-inline">[EnumeratorCancellation]</code> در متدهای <code class="code-inline">IAsyncEnumerable</code> باعث میشود Cancellation Token بهدرستی به تمام لایههای زیرین (حتی HttpClient) منتقل شود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 10: STRENGTHS
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱۰</div>
|
||
<div class="section-title">
|
||
<h3>نقاط قوت راهکار</h3>
|
||
<div class="subtitle">Strengths & Best Practices</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p class="no-indent">در جریان بررسی عمیق کد، موارد متعددی از رعایت اصول مهندسی نرمافزار مشاهده شد:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>نقطه قوت</th>
|
||
<th>مصادیق در کد</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>جداسازی مسئولیتها (SoC)</strong></td>
|
||
<td>Project/Conversation/Message هر یک Service، Repository و Enricher اختصاصی دارند</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>انتزاع Provider-Agnostic</strong></td>
|
||
<td>تعویض OpenAI ↔ Ollama تنها با تغییر config</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>الگوی Composite برای Extractors</strong></td>
|
||
<td>افزودن فرمت جدید = ثبت Extractor جدید، بدون تغییر کد موجود</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>Streaming First-Class</strong></td>
|
||
<td>تمام Endpointها نسخه SSE دارند و CancellationToken در همهجا رعایت شده</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>امنیت چندلایه</strong></td>
|
||
<td>OAuth2 + API Key + Policy + Data-Level Ownership Check</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>MCP Client و Server همزمان</strong></td>
|
||
<td>پشتیبانی کامل از استاندارد نوظهور MCP</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>الگوی Tiered RAG</strong></td>
|
||
<td>اولویتبندی طبیعی دادههای گفتگو/پروژه/کاربر/جهانی</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>Lazy Initialization</strong></td>
|
||
<td>MCP Server و Tool Scanner از Lazy و Semaphore استفاده میکنند</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 11: RISKS & RECOMMENDATIONS
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱۱</div>
|
||
<div class="section-title">
|
||
<h3>ریسکها و پیشنهادهای بهبود</h3>
|
||
<div class="subtitle">Risks & Improvement Recommendations</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p class="no-indent">در کنار نقاط قوت، مواردی نیز وجود دارد که بهبود آنها میتواند بلوغ راهکار را به سطح بالاتری برساند:</p>
|
||
|
||
<h4 style="margin-top: 20px; color: var(--primary); font-size: 16px;">ریسکهای فنی:</h4>
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>ریسک</th>
|
||
<th>توضیح</th>
|
||
<th>اولویت</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>غیرفعالسازی SSL Validation</td>
|
||
<td>در Startup هر دو پروژه، گواهی SSL بکچنل OAuth2 تأیید نمیشود</td>
|
||
<td><span class="tag risk">بالا</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>جستجوی خطی روی AiVectors</td>
|
||
<td>محاسبه Cosine Similarity روی تمام رکوردها بهصورت In-Memory انجام میشود که در مقیاس بزرگ کند خواهد بود</td>
|
||
<td><span class="tag risk">بالا</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>عدم استفاده از Vector Index</td>
|
||
<td>عدم استفاده از pgvector / Qdrant / Azure AI Search برای جستجوی برداری تخصصی</td>
|
||
<td><span class="tag risk">بالا</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>In-Memory Vector Store</td>
|
||
<td>در صورت Restart سرویس، تمام Sessionهای ChatWithDocuments از بین میروند</td>
|
||
<td><span class="tag warn">متوسط</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>عدم وجود Rate Limiting</td>
|
||
<td>Endpointهای پرهزینه (مانند Ask) بدون محدودیت نرخ قابل فراخوانی هستند</td>
|
||
<td><span class="tag warn">متوسط</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>عدم وجود Distributed Cache</td>
|
||
<td>MCP Clients و Tools در حافظه هر Instance جدا نگه داشته میشوند</td>
|
||
<td><span class="tag warn">متوسط</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>لاگ کردن پیامهای حساس</td>
|
||
<td>در برخی Exceptionها متن Prompt کاربر در Log ثبت میشود</td>
|
||
<td><span class="tag warn">متوسط</span></td>
|
||
</tr>
|
||
<tr>
|
||
<td>عدم پیادهسازی DeepSeek/HuggingFace</td>
|
||
<td>در XModelsExtensions این Providers بهصورت اسکلت خالی ماندهاند</td>
|
||
<td><span class="tag">پایین</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h4 style="margin-top: 25px; color: var(--primary); font-size: 16px;">پیشنهادهای بهبود اولویتدار:</h4>
|
||
<ul class="styled-list">
|
||
<li><strong>۱. جایگزینی جستجوی برداری با یک Vector DB تخصصی:</strong> استفاده از pgvector، Qdrant یا Azure AI Search که جستجوی KNN را با عملکرد بالا انجام میدهند.</li>
|
||
<li><strong>۲. توزیعشده کردن MCP Server Cache:</strong> استفاده از Redis برای نگهداری Clients و Tools مشترک بین Instanceها.</li>
|
||
<li><strong>۳. فعالسازی Rate Limiting مبتنی بر Policy:</strong> استفاده از <code class="code-inline">AspNetCore.RateLimiting</code> برای Endpointهای AI با هزینه محاسباتی بالا.</li>
|
||
<li><strong>۴. بازبینی SSL Validation:</strong> محدود کردن غیرفعالسازی به محیط Development با تنظیمات مبتنی بر IWebHostEnvironment.</li>
|
||
<li><strong>۵. پیادهسازی مکانیزم ثبت و تحلیل هزینه:</strong> ثبت مصرف Token برای هر درخواست جهت محاسبه دقیق هزینههای API.</li>
|
||
<li><strong>۶. پیادهسازی Semantic Cache:</strong> ذخیره پاسخهای مشابه با استفاده از Embedding پرسش برای کاهش هزینه و زمان پاسخ.</li>
|
||
<li><strong>۷. پیادهسازی Versioning در Promptها:</strong> امکان A/B Test روی Promptهای مختلف برای بهبود کیفیت پاسخ.</li>
|
||
<li><strong>۸. پیادهسازی مکانیزم Reranking:</strong> استفاده از Cross-Encoder برای بهبود کیفیت نتایج RAG پس از جستجوی اولیه.</li>
|
||
</ul>
|
||
|
||
<div class="warning-box">
|
||
<strong>⚠️ ریسک کلیدی عملیاتی:</strong> با رشد تعداد بردارها در جدول <code class="code-inline">AiVectors</code>، چون Cosine Similarity در حافظه محاسبه میشود، هر درخواست RAG به اندازه کل بردارها حافظه مصرف میکند. توصیه میشود پیش از Scale عملیاتی، حتماً جستجوی برداری به یک راهکار تخصصی منتقل شود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- ============================================================
|
||
SECTION 12: CONCLUSION
|
||
============================================================ -->
|
||
<div class="section">
|
||
<div class="section-header">
|
||
<div class="section-number">۱۲</div>
|
||
<div class="section-title">
|
||
<h3>جمعبندی نهایی</h3>
|
||
<div class="subtitle">Final Summary</div>
|
||
</div>
|
||
</div>
|
||
<div class="section-content">
|
||
<p>راهکار xAi یک پلتفرم هوش مصنوعی بالغ، مدولار و گستردهپذیر است که با رعایت اصول مهندسی نرمافزار مدرن طراحی شده است. نقاط قوت بارز آن را میتوان در سه محور خلاصه کرد:</p>
|
||
|
||
<table class="styled-table">
|
||
<thead>
|
||
<tr>
|
||
<th>محور</th>
|
||
<th>ارزش ایجاد شده</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><strong>انعطافپذیری معماری</strong></td>
|
||
<td>تعویض Provider، Extractor، Repository بدون تغییر در لایههای دیگر</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>پوشش جامع قابلیتها</strong></td>
|
||
<td>دو مسیر RAG، پشتیبانی از ۱۵+ فرمت، MCP دو-نقشه، Streaming کامل</td>
|
||
</tr>
|
||
<tr>
|
||
<td><strong>امنیت و انطباق</strong></td>
|
||
<td>OAuth2، API Key، Policy-Based AuthZ و Data-Level Ownership</td>
|
||
</tr>
|
||
<tr class="highlight-row">
|
||
<td><strong>آمادگی برای رشد</strong></td>
|
||
<td>ساختار قابل توسعه برای افزودن Providers و ابزارهای جدید</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="conclusion-box">
|
||
<h3>🎯 توصیه نهایی</h3>
|
||
<p>راهکار xAi با ساختار مهندسیشده و بالغ خود، آماده استفاده در محیطهای سازمانی است. با این حال، برای ورود به فاز Production در مقیاس بزرگ، پیادهسازی سه بهبود اولویتدار زیر توصیه میشود:</p>
|
||
<div class="highlight">
|
||
<strong>💎 اقدامات پیشنهادی برای Production:</strong><br>
|
||
۱. انتقال جستجوی برداری به Vector DB تخصصی (pgvector / Qdrant)<br>
|
||
۲. توزیعشده کردن Cache سرویس MCP با Redis<br>
|
||
۳. فعالسازی Rate Limiting و Audit Logging برای Endpointهای حساس
|
||
</div>
|
||
</div>
|
||
|
||
<div class="info-box">
|
||
<strong>📞 گام بعدی:</strong> توصیه میشود در گام نخست، یک جلسه فنی جهت بررسی اولویتبندی بهبودها و تهیه Roadmap اجرایی برای رسیدن به نسخه Production-Ready برگزار شود.
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="page-info">
|
||
این مستند محرمانه بوده و صرفاً جهت بررسی فنی داخلی تهیه شده است. هرگونه کپیبرداری یا افشا بدون اجازه کتبی ممنوع است.
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<footer class="document-footer">
|
||
<div class="footer-brand">تحلیل فنی معماری راهکار xAi</div>
|
||
<div class="footer-divider"></div>
|
||
<div>تاریخ تهیه: آبان ۱۴۰۵ | نسخه: ۱.۰ | طبقهبندی: محرمانه</div>
|
||
</footer>
|
||
|
||
</div>
|
||
|
||
</body>
|
||
</html> |