مفتوح المصدر · مفتوح المصدر · 2025

نظام محادثة ذكي (ITSE500)

منصة محادثة متكاملة بخلفية Django REST وواجهة React وتطبيق Flutter مع جلسات الضيوف

Django · Flutter · React · JWT

GitHub | Release v1.0.0 | Live

بطاقة عرض إصدار نظام محادثة ITSE500 v1.0.0 ومعمارية Django REST والمصادقة

نظرة عامة والمشكلة الهندسية

يتطلب بناء منصة محادثة ذكاء اصطناعي متعددة المنصات توحيد إدارة المحادثات، وتوفير آليات مصادقة مرنة تجمع بين الحسابات المسجلة وتجربة الضيوف الفورية، مع الحفاظ على عقود اتصال متسقة بين متصفح الويب وتطبيقات الهاتف.

يمثل نظام المحادثة الذكي (ITSE500) منصة مفتوحة المصدر متكاملة الطبقات، تجمع بين خلفية Django REST مع مصادقة JWT/OAuth، وواجهة ويب تفاعلية بـ React، وتطبيق Android عبر Flutter، مع دعم متكامل لجلسات الضيوف.

تجربة حية ومفتوحة المصدر: يمكن تجربة واجهة الويب المنشورة مباشرة عبر react.itse500-ok.ly والاطلاع على شيفرة الخادم عبر arousi/ITSE500-Django.

المعمارية والقرارات التقنية

تعتمد المنصة على معمارية موجهة بواجهات API تفصل الخادم الموحد عن تعدد العملاء:

  • نواة الخادم (Django REST Framework): تدير طلبات نماذج المحادثة، وحفظ الجلسات، ومنطق المصادقة عبر واجهة برمجية مركزية موحدة.
  • المصادقة المزدوجة وجلسات الضيوف (JWT وOAuth): الجمع بين رموز JWT وتسجيل الدخول عبر OAuth للمستخدمين المسجلين، مع دعم جلسات الضيوف لتمكين التجربة المباشرة دون عوائق التسجيل المسبق.
  • عميل الويب (React): واجهة متصفح حديثة منشورة فعلياً على https://react.itse500-ok.ly تتواصل مع نفس نقاط الاتصال المخصصة لتطبيق الهاتف.
  • عميل الموبايل (Flutter Android): تطبيق Android أصيل يستهلك واجهات JWT/OAuth وجلسات الضيوف نفسها لضمان تجربة متطابقة عبر المنصات.
اتساق العقود البرمجية: يتصل تطبيقا React وFlutter بواجهة Django REST موحدة، مما يضمن اتساق سجل المحادثات وإدارة الجلسات والرموز في جميع الواجهات.

دورة حياة البرمجيات وممارسات الجودة

طُبقت ممارسات هندسية واضحة لضمان تكامل الطبقات الثلاث:

  1. توحيد واجهة API: اعتماد بنية استجابات ومعالجة أخطاء موحدة منعت تشتت منطق الخادم بين عميل الويب وعميل الهاتف.
  2. فصل صلاحيات الجلسات: ضبط حدود واضحة بين جلسات الضيوف المؤقتة والحسابات المصادق عليها عبر JWT وOAuth.
  3. نشر وإتاحة علنية: توفير شيفرة الخلفية بشكل مفتوح المصدر مع نسخة ويب حية جاهزة للاختبار والمراجعة.

التقنيات والمخرجات

الطبقة التقنية / المخرج الدور في المنظومة
الخلفية والمصادقة Django REST وJWT وOAuth إدارة المحادثات، المصادقة، وجلسات الضيوف
واجهة الويب React عميل ويب منشور ومتصل بالخادم (react.itse500-ok.ly)
تطبيق الموبايل Flutter (Android) تطبيق هاتف يتكامل مع نفس واجهات الخادم
الإتاحة والاختبار GitHub (arousi/ITSE500-Django) ورابط حي مستودع مفتوح المصدر ونشر تشغيلي للواجهة

أحدث إصدار: v1.0.0 — Prompeteer Django REST LLM Chat Backend (v1.0.0)

Overview

Prompeteer Server (arousi/ITSE500-Django) is a Django 5.1.7 / Django REST Framework backend for a privacy-focused, multi-provider LLM chat application developed for ITSE500. It powers multi-provider OAuth, JWT & guest/visitor authentication, unified profile and conversation sync, client-side encryption key provisioning, and asynchronous LLM execution, while serving as the canonical OpenAPI contract source (api/schema.yaml) for the Flutter and React clients.

Tag Note: Tag v1.0.0 marks the initial release milestone (bbcd3a3). Subsequent updates on main expanded chat_api, environment-gated production infrastructure, CI workflows, and the published api/schema.yaml contract documented below.


Verified Modules & API Surface

All API endpoints are namespaced under /api/v1/<app>/:

Module Base Path Responsibilities & Key Endpoints
auth_api /api/v1/auth_api/ Registration (/register/), login (/login/), logout with refresh-token blacklisting (/logout/), JWT refresh (/token/refresh/), email PIN verification (/verify-email-pin/), password setup (/set-password-after-email-verify/), health check (/health/), and OAuth flows (/google/, /openrouter/, /github/, /microsoft/ /authorize/, /callback/, /oauth/result/<state_value>/).
user_mang /api/v1/user_mang/ UnifiedSyncView (/me/) supporting GET/POST/PATCH/DELETE for profile and conversation sync, guest (temp_id) resolution, CSV/PDF data export, and account soft-delete.
chat_api /api/v1/chat_api/ User-scoped CRUD for conversations/ and conversations/{id}/, paginated conversations/{id}/messages/, and multipart conversations/{id}/messages/{mid}/attachments/ (25 MB cap, server-computed SHA-256 & byte size). Dispatches LLM completions via litellm/openai through a strict pending → streaming → complete / error state machine.
crypto_api /api/v1/crypto_api/ UserUMKView (/umk/) for GET/POST retrieval and one-time provisioning of a base64-encoded 32-byte User Master Key (UMK).
core & prompeteer_server /, /admin/, /api/ Host-aware SPA/landing routing (root_router), /team/, Jazzmin admin (/admin/), and drf-spectacular OpenAPI schema (/api/schema/), Swagger UI (/api/docs/), and ReDoc (/api/redoc/).

Authentication, Security & Guest Architecture

  • JWT Lifecycle: Short-lived 15-minute access tokens (JWT_ACCESS_MINUTES) paired with 7-day refresh tokens (JWT_REFRESH_DAYS), with ROTATE_REFRESH_TOKENS=True and BLACKLIST_AFTER_ROTATION=True backed by Custom_User UUID primary keys.
  • Multi-Provider OAuth + PKCE: Unified authorize/callback/bridge endpoints for Google, OpenRouter, GitHub, and Microsoft with OAuthState TTL tracking and encrypted provider token persistence (ProviderOAuthToken).
  • Privacy-Preserving Guest Mode: Visitors receive a stable temp_id UUID for multi-device conversation sync via UnifiedSyncView without requiring PII.
  • Hardening & Scoping: DRF rate throttling (auth: 10/min, anon: 60/min), user-scoped queryset filtering (returning 404 for non-owned chat resources), and fail-fast startup checks when DJANGO_DEBUG=False without SECRET_KEY or BACKEND_PASSWORD_SALT.

Docker, Compose & Env-Gated Infrastructure

  • Container Runtime: Python 3.13-slim image (Dockerfile) running Gunicorn (prompeteer_server.wsgi:application, 3 workers on port 8000) via entrypoint.sh (migrate --noinput and collectstatic --noinput with WhiteNoise).
  • Production Stack (docker-compose.prod.yml): Orchestrates web (health-checked on /api/v1/auth_api/health/), celery-worker, and celery-beat (plus an optional channels ASGI/Uvicorn service) behind a TLS reverse proxy (Caddy/nginx).
  • Env-Gated Services with Local Fallbacks:
    • PostgreSQL (DB_HOST set) → falls back to SQLite.
    • Redis (REDIS_URL set) → falls back to LocMemCache / InMemoryChannelLayer.
    • MinIO / S3 Media (AWS_S3_ENDPOINT_URL set) → falls back to local FileSystemStorage.
    • Celery (CELERY_BROKER_URL / REDIS_URL set) → falls back to synchronous inline execution (CELERY_TASK_ALWAYS_EAGER=True).

Known Issues

The following limitations from the initial v1.0.0 release are preserved for transparency and open contributions:

  • OTP Email Dispatch: Email dispatch for OTPs requires thorough debugging.
  • Password Reset: Password reset functionality is coupled to OTP delivery and is impacted by the OTP email dispatch issue.
  • Account Verification: Account verification depends on receiving OTPs from the email dispatcher.
  • Chat Data Storage: Chat data storage in the initial v1.0.0 snapshot exhibits edge-case bugs that require debugging.
  • Key Rotation (crypto_api): POST /api/v1/crypto_api/umk/?rotate=true currently returns 400 (Rotation not implemented).