"""Render source-grounded conceptual architecture in the site's SVG palette."""
from html import escape
from pathlib import Path
ROOT = Path(__file__).resolve().parents[2]
OUT = ROOT / 'projects/finance-dashboard/assets'
for mode in ('light', 'dark'):
    bg, ink, muted, line = ('#f7f5ee','#26322f','#68746e','#d5d9d1') if mode == 'light' else ('#202826','#e1e8e2','#acb9b0','#43534b')
    fills = ['#dbe7df','#e6ddce','#dce5ed','#e4ddeb'] if mode == 'light' else ['#314e40','#514735','#324755','#4a3d54']
    parts = [f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 580"><title>From fragmented financial sources to decisions</title><rect width="1000" height="580" fill="{bg}"/>']
    def text(x,y,s,size=17,color=ink):
        parts.append(f'<text x="{x}" y="{y}" font-family="sans-serif" font-size="{size}" fill="{color}">{escape(s)}</text>')
    text(42,48,'A shared model between sources and screens',27)
    text(42,79,'Conceptual architecture • Kellen Finance feature branch',15,muted)
    nodes = [
        ('01  INGEST','Plaid / CSV / PDF',['Sync changes and balances','Parse supported statements']),
        ('02  NORMALIZE','Account + Transaction',['Align signs and identifiers','Retain source and import status']),
        ('03  PERSIST','Local JSON cache',['Hash files; merge duplicates','Store holdings and snapshots']),
        ('04  ANALYZE','Pure TypeScript functions',['Classify spending and transfers','Prepare trends and summaries']),
    ]
    for i,(eyebrow,title,lines) in enumerate(nodes):
        x = 42 + i*238
        parts.append(f'<rect x="{x}" y="120" width="218" height="205" rx="13" fill="{fills[i]}"/>')
        text(x+16,151,eyebrow,13,muted);text(x+16,190,title,17)
        for j,s in enumerate(lines):text(x+16,235+j*27,s,13)
        if i<3: text(x+222,223,'→',18,muted)
    parts.append(f'<path d="M865 326v38H510v31" fill="none" stroke="{muted}" stroke-width="2"/><rect x="42" y="399" width="916" height="123" rx="13" fill="none" stroke="{line}" stroke-width="2"/>')
    text(64,431,'05  RENDER / INSPECT',13,muted)
    text(64,467,'React pages + lightweight SVG charts + transaction detail',23)
    text(64,499,'Overview → account views → source-level review → saved manual exclusions',15,muted)
    text(42,555,'Server routes ingest and persist; the browser applies presentation filters and analytics.',14,muted)
    parts.append('</svg>')
    (OUT/f'architecture-{mode}.svg').write_text(''.join(parts))
print('Wrote architecture SVGs in both themes.')
