الطبقات
- Frontend: Next.js 14 (App Router) + React 18 + TypeScript + custom CSS. Hosted على VPS عبر PM2.
- Backend: NestJS 11 + TypeScript + Prisma 6. يعمل محلياً على Mac M5 Max port 3010، يُكشف للإنترنت عبر SSH tunnel للـ VPS.
- Database: PostgreSQL 16 — 20+ جدول مع علاقات FK + cascade.
- Cache + Queues: Redis 7 — 4 BullMQ queues.
- LLM: Ollama محلياً (qwen2.5:32b افتراضياً) + قابلية الاتصال بـ Anthropic/OpenAI.
الـ Modules الرئيسية في Backend
AgentsModule+ sub-modules لـ 12 قسم.HermesModule— orchestrator + queue service + agent worker.CommunicationsModule— WhatsApp + email.AutoReplyModule— AI auto-reply لـ WhatsApp.AutomationModule— workflow engine + 5 triggers + 7 actions.PmModule— clients + projects + tasks.RashidModule— المدير العام الذكي.
مبدأ المعمارية
كل module مستقل. الاعتمادات تتم عبر
forwardRef عند الحاجة لتجنّب الـ circular dependencies. الأحداث بين modules عبر EventEmitter2 wildcard bus — تكوين loose.تدفّق طلب نموذجي
- متصفّح → Frontend page (مثلاً
/automation/workflows/new). - الـ page يطلق fetch لـ Backend عبر
fetchAPI. - Backend (NestJS) → JwtAuthGuard → controller → service.
- Service → Prisma → Postgres.
- Response → page → React render.
النشر
- Frontend:
npm run build→ rsync إلى VPS →pm2 restart operix-v3. - Backend: يعمل محلياً عبر
node dist/src/main.js— لا rsync. - DB + Redis: محلياً على Mac.
تنبيه
Backend “عكسي” (محلي مع tunnel) للسرعة وتقليل التكلفة. لو السيرفر تعطّل، كل الـ API يتأثّر. لإنتاج جدّي، رحّل Backend لـ VPS.