lines = []
lines.append('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 960 700">')
lines.append('  <style>')
lines.append('    text { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; }')
lines.append('  </style>')
lines.append('  <defs>')
lines.append('    <marker id="arrow-claude" markerWidth="8" markerHeight="8" refX="7" refY="4" orient="auto">')
lines.append('      <polygon points="0 0, 8 4, 0 8" fill="#5a5a5a"/>')
lines.append('    </marker>')
lines.append('    <filter id="shadow-soft">')
lines.append('      <feDropShadow dx="0" dy="2" stdDeviation="4" flood-color="#000000" flood-opacity="0.05"/>')
lines.append('    </filter>')
lines.append('  </defs>')
lines.append('  <rect width="960" height="700" fill="#f8f6f3"/>')
lines.append('  <text x="480" y="40" text-anchor="middle" fill="#1a1a1a" font-size="22" font-weight="700">Canifa AI Platform Architecture</text>')

# Layer labels
lines.append('  <text x="40" y="120" fill="#6a6a6a" font-size="14" font-weight="600">Client</text>')
lines.append('  <text x="40" y="240" fill="#6a6a6a" font-size="14" font-weight="600">Interface</text>')
lines.append('  <text x="40" y="360" fill="#6a6a6a" font-size="14" font-weight="600">Gateway</text>')
lines.append('  <text x="40" y="480" fill="#6a6a6a" font-size="14" font-weight="600">Module</text>')
lines.append('  <text x="40" y="600" fill="#6a6a6a" font-size="14" font-weight="600">Data</text>')

# Nodes
# Client Layer
lines.append('  <rect x="380" y="80" width="200" height="80" rx="12" fill="#a8c5e6" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="480" y="115" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">Web Browser</text>')
lines.append('  <text x="480" y="135" text-anchor="middle" fill="#6a6a6a" font-size="13">Static Entry Points</text>')

# Interface Layer
lines.append('  <rect x="380" y="200" width="200" height="80" rx="12" fill="#a8c5e6" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="480" y="235" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">Micro-Frontends</text>')
lines.append('  <text x="480" y="255" text-anchor="middle" fill="#6a6a6a" font-size="13">Independent Namespaces</text>')

# Gateway Layer
lines.append('  <rect x="380" y="320" width="200" height="80" rx="12" fill="#f4e4c1" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="480" y="355" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">FastAPI Gateway</text>')
lines.append('  <text x="480" y="375" text-anchor="middle" fill="#6a6a6a" font-size="13">api_router &amp; Middleware</text>')

# Module Layer
lines.append('  <rect x="380" y="440" width="200" height="80" rx="12" fill="#9dd4c7" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="480" y="475" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">Business Modules</text>')
lines.append('  <text x="480" y="495" text-anchor="middle" fill="#6a6a6a" font-size="13">36+ Agents &amp; Event Bus</text>')

# Data Layer
lines.append('  <rect x="180" y="560" width="180" height="80" rx="12" fill="#e8e6e3" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="270" y="595" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">Postgres DB</text>')
lines.append('  <text x="270" y="615" text-anchor="middle" fill="#6a6a6a" font-size="13">db_pool management</text>')

lines.append('  <rect x="390" y="560" width="180" height="80" rx="12" fill="#e8e6e3" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="480" y="595" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">Redis Cache</text>')
lines.append('  <text x="480" y="615" text-anchor="middle" fill="#6a6a6a" font-size="13">redis_cache module</text>')

lines.append('  <rect x="600" y="560" width="180" height="80" rx="12" fill="#e8e6e3" stroke="#4a4a4a" stroke-width="2.5" filter="url(#shadow-soft)"/>')
lines.append('  <text x="690" y="595" text-anchor="middle" fill="#1a1a1a" font-size="16" font-weight="600">OLAP (StarRocks)</text>')
lines.append('  <text x="690" y="615" text-anchor="middle" fill="#6a6a6a" font-size="13">Analytic Engine</text>')

# Arrows
lines.append('  <line x1="480" y1="160" x2="480" y2="200" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')
lines.append('  <line x1="480" y1="280" x2="480" y2="320" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')
lines.append('  <line x1="480" y1="400" x2="480" y2="440" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')

lines.append('  <path d="M 480 520 L 480 540 L 270 540 L 270 560" fill="none" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')
lines.append('  <path d="M 480 520 L 480 560" fill="none" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')
lines.append('  <path d="M 480 520 L 480 540 L 690 540 L 690 560" fill="none" stroke="#5a5a5a" stroke-width="2" marker-end="url(#arrow-claude)"/>')

lines.append('</svg>')

output_path = "backend/static/cookbook/data/01-architecture/diagram.svg"
with open(output_path, "w", encoding="utf-8") as f:
    f.write("\n".join(lines))
print(f"SVG generated at {output_path}")
