elevenlabs-webhook-nodejs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +27 -0
- package/.dockerignore +6 -0
- package/.env.example +43 -0
- package/BEFORE-PRODUCTION.md +32 -0
- package/Dockerfile +23 -0
- package/SYSTEM_OVERVIEW.md +942 -0
- package/SYSTEM_STATUS.md +332 -0
- package/backup_script/main.py +146 -0
- package/baileys/.dockerignore +7 -0
- package/baileys/Dockerfile +13 -0
- package/baileys/README.md +412 -0
- package/baileys/index.js +499 -0
- package/baileys/package-lock.json +2532 -0
- package/baileys/package.json +25 -0
- package/baileys/server.js +96 -0
- package/baileys/src/config.js +55 -0
- package/baileys/src/middleware/api-key.js +16 -0
- package/baileys/src/routes/accounts.js +51 -0
- package/baileys/src/routes/chats.js +103 -0
- package/baileys/src/routes/webhooks.js +34 -0
- package/baileys/src/services/account-store.js +259 -0
- package/baileys/src/services/webhook-dispatcher.js +161 -0
- package/baileys/src/services/worker-manager.js +597 -0
- package/baileys/src/utils/jid.js +79 -0
- package/baileys/src/utils/logger.js +16 -0
- package/baileys/src/utils/use-mongodb-auth-state.js +122 -0
- package/baileys/worker.js +721 -0
- package/dist/app.d.ts +1 -0
- package/dist/app.js +84 -0
- package/dist/app.js.map +1 -0
- package/dist/config/agentPrompts.json +19 -0
- package/dist/config/database.d.ts +1 -0
- package/dist/config/database.js +26 -0
- package/dist/config/database.js.map +1 -0
- package/dist/config/env.d.ts +41 -0
- package/dist/config/env.js +81 -0
- package/dist/config/env.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.js +73 -0
- package/dist/config/index.js.map +1 -0
- package/dist/controllers/webhook.controller.d.ts +10 -0
- package/dist/controllers/webhook.controller.js +128 -0
- package/dist/controllers/webhook.controller.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +13 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/hooks/webhookValidator.d.ts +2 -0
- package/dist/hooks/webhookValidator.js +47 -0
- package/dist/hooks/webhookValidator.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -0
- package/dist/index.js.map +1 -0
- package/dist/migrations/001_session-architecture.d.ts +3 -0
- package/dist/migrations/001_session-architecture.js +119 -0
- package/dist/migrations/001_session-architecture.js.map +1 -0
- package/dist/migrations/002_agent-ref.d.ts +3 -0
- package/dist/migrations/002_agent-ref.js +55 -0
- package/dist/migrations/002_agent-ref.js.map +1 -0
- package/dist/migrations/003_shift-schedule.d.ts +3 -0
- package/dist/migrations/003_shift-schedule.js +48 -0
- package/dist/migrations/003_shift-schedule.js.map +1 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.d.ts +3 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js +27 -0
- package/dist/migrations/004_invert-shift-to-clinic-hours.js.map +1 -0
- package/dist/migrations/005_composite-baileys-chat-ids.d.ts +3 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js +47 -0
- package/dist/migrations/005_composite-baileys-chat-ids.js.map +1 -0
- package/dist/migrations/migration.model.d.ts +18 -0
- package/dist/migrations/migration.model.js +45 -0
- package/dist/migrations/migration.model.js.map +1 -0
- package/dist/migrations/migration.routes.d.ts +2 -0
- package/dist/migrations/migration.routes.js +37 -0
- package/dist/migrations/migration.routes.js.map +1 -0
- package/dist/migrations/migration.runner.d.ts +19 -0
- package/dist/migrations/migration.runner.js +74 -0
- package/dist/migrations/migration.runner.js.map +1 -0
- package/dist/models/ConversationClaim.d.ts +13 -0
- package/dist/models/ConversationClaim.js +44 -0
- package/dist/models/ConversationClaim.js.map +1 -0
- package/dist/models/ConversationEvaluation.d.ts +23 -0
- package/dist/models/ConversationEvaluation.js +92 -0
- package/dist/models/ConversationEvaluation.js.map +1 -0
- package/dist/models/Summary.d.ts +37 -0
- package/dist/models/Summary.js +78 -0
- package/dist/models/Summary.js.map +1 -0
- package/dist/models/Transcription.d.ts +34 -0
- package/dist/models/Transcription.js +71 -0
- package/dist/models/Transcription.js.map +1 -0
- package/dist/models/WhatsAppRecipient.d.ts +23 -0
- package/dist/models/WhatsAppRecipient.js +53 -0
- package/dist/models/WhatsAppRecipient.js.map +1 -0
- package/dist/modules/admin/admin.routes.d.ts +2 -0
- package/dist/modules/admin/admin.routes.js +1966 -0
- package/dist/modules/admin/admin.routes.js.map +1 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js +158 -0
- package/dist/modules/admin/elevenlabs-test-chat.routes.js.map +1 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.d.ts +2 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js +204 -0
- package/dist/modules/admin/whatsapp-test-chat.routes.js.map +1 -0
- package/dist/modules/agents/agent.model.d.ts +38 -0
- package/dist/modules/agents/agent.model.js +92 -0
- package/dist/modules/agents/agent.model.js.map +1 -0
- package/dist/modules/agents/agent.routes.d.ts +2 -0
- package/dist/modules/agents/agent.routes.js +61 -0
- package/dist/modules/agents/agent.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.model.d.ts +76 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js +118 -0
- package/dist/modules/appointment-validation/appointment-validation.model.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.d.ts +2 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js +202 -0
- package/dist/modules/appointment-validation/appointment-validation.routes.js.map +1 -0
- package/dist/modules/appointment-validation/appointment-validation.service.d.ts +53 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js +827 -0
- package/dist/modules/appointment-validation/appointment-validation.service.js.map +1 -0
- package/dist/modules/auth/auth.model.d.ts +17 -0
- package/dist/modules/auth/auth.model.js +64 -0
- package/dist/modules/auth/auth.model.js.map +1 -0
- package/dist/modules/auth/auth.routes.d.ts +2 -0
- package/dist/modules/auth/auth.routes.js +202 -0
- package/dist/modules/auth/auth.routes.js.map +1 -0
- package/dist/modules/auth/auth.service.d.ts +28 -0
- package/dist/modules/auth/auth.service.js +183 -0
- package/dist/modules/auth/auth.service.js.map +1 -0
- package/dist/modules/auth/refresh-token.model.d.ts +13 -0
- package/dist/modules/auth/refresh-token.model.js +52 -0
- package/dist/modules/auth/refresh-token.model.js.map +1 -0
- package/dist/modules/billing/billing-alert.model.d.ts +16 -0
- package/dist/modules/billing/billing-alert.model.js +47 -0
- package/dist/modules/billing/billing-alert.model.js.map +1 -0
- package/dist/modules/billing/billing-period-snapshot.model.d.ts +35 -0
- package/dist/modules/billing/billing-period-snapshot.model.js +68 -0
- package/dist/modules/billing/billing-period-snapshot.model.js.map +1 -0
- package/dist/modules/billing/billing.model.d.ts +18 -0
- package/dist/modules/billing/billing.model.js +62 -0
- package/dist/modules/billing/billing.model.js.map +1 -0
- package/dist/modules/billing/billing.routes.d.ts +2 -0
- package/dist/modules/billing/billing.routes.js +63 -0
- package/dist/modules/billing/billing.routes.js.map +1 -0
- package/dist/modules/billing/billing.service.d.ts +69 -0
- package/dist/modules/billing/billing.service.js +498 -0
- package/dist/modules/billing/billing.service.js.map +1 -0
- package/dist/modules/billing/payment.model.d.ts +24 -0
- package/dist/modules/billing/payment.model.js +57 -0
- package/dist/modules/billing/payment.model.js.map +1 -0
- package/dist/modules/calls/call.model.d.ts +41 -0
- package/dist/modules/calls/call.model.js +97 -0
- package/dist/modules/calls/call.model.js.map +1 -0
- package/dist/modules/calls/call.routes.d.ts +2 -0
- package/dist/modules/calls/call.routes.js +103 -0
- package/dist/modules/calls/call.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.model.d.ts +45 -0
- package/dist/modules/campaigns/campaign.model.js +98 -0
- package/dist/modules/campaigns/campaign.model.js.map +1 -0
- package/dist/modules/campaigns/campaign.routes.d.ts +2 -0
- package/dist/modules/campaigns/campaign.routes.js +323 -0
- package/dist/modules/campaigns/campaign.routes.js.map +1 -0
- package/dist/modules/campaigns/campaign.service.d.ts +11 -0
- package/dist/modules/campaigns/campaign.service.js +86 -0
- package/dist/modules/campaigns/campaign.service.js.map +1 -0
- package/dist/modules/google-calendar/google-calendar.routes.d.ts +2 -0
- package/dist/modules/google-calendar/google-calendar.routes.js +32 -0
- package/dist/modules/google-calendar/google-calendar.routes.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call-config.model.d.ts +20 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js +68 -0
- package/dist/modules/inbound-call/inbound-call-config.model.js.map +1 -0
- package/dist/modules/inbound-call/inbound-call.routes.d.ts +2 -0
- package/dist/modules/inbound-call/inbound-call.routes.js +243 -0
- package/dist/modules/inbound-call/inbound-call.routes.js.map +1 -0
- package/dist/modules/leads/lead.model.d.ts +24 -0
- package/dist/modules/leads/lead.model.js +54 -0
- package/dist/modules/leads/lead.model.js.map +1 -0
- package/dist/modules/leads/lead.routes.d.ts +2 -0
- package/dist/modules/leads/lead.routes.js +201 -0
- package/dist/modules/leads/lead.routes.js.map +1 -0
- package/dist/modules/plans/plan.model.d.ts +25 -0
- package/dist/modules/plans/plan.model.js +59 -0
- package/dist/modules/plans/plan.model.js.map +1 -0
- package/dist/modules/surveys/survey.model.d.ts +30 -0
- package/dist/modules/surveys/survey.model.js +75 -0
- package/dist/modules/surveys/survey.model.js.map +1 -0
- package/dist/modules/surveys/survey.routes.d.ts +2 -0
- package/dist/modules/surveys/survey.routes.js +153 -0
- package/dist/modules/surveys/survey.routes.js.map +1 -0
- package/dist/modules/tenants/tenant.model.d.ts +86 -0
- package/dist/modules/tenants/tenant.model.js +127 -0
- package/dist/modules/tenants/tenant.model.js.map +1 -0
- package/dist/modules/tenants/tenant.routes.d.ts +2 -0
- package/dist/modules/tenants/tenant.routes.js +65 -0
- package/dist/modules/tenants/tenant.routes.js.map +1 -0
- package/dist/modules/users/user.routes.d.ts +2 -0
- package/dist/modules/users/user.routes.js +106 -0
- package/dist/modules/users/user.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.d.ts +20 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js +85 -0
- package/dist/modules/webhooks/elevenlabs-tool.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.d.ts +11 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js +360 -0
- package/dist/modules/webhooks/elevenlabs-tool.service.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.routes.d.ts +2 -0
- package/dist/modules/webhooks/elevenlabs.routes.js +34 -0
- package/dist/modules/webhooks/elevenlabs.routes.js.map +1 -0
- package/dist/modules/webhooks/elevenlabs.service.d.ts +6 -0
- package/dist/modules/webhooks/elevenlabs.service.js +512 -0
- package/dist/modules/webhooks/elevenlabs.service.js.map +1 -0
- package/dist/modules/webhooks/unipile.routes.d.ts +2 -0
- package/dist/modules/webhooks/unipile.routes.js +780 -0
- package/dist/modules/webhooks/unipile.routes.js.map +1 -0
- package/dist/modules/whatsapp/appointment.model.d.ts +27 -0
- package/dist/modules/whatsapp/appointment.model.js +58 -0
- package/dist/modules/whatsapp/appointment.model.js.map +1 -0
- package/dist/modules/whatsapp/operator-request.model.d.ts +29 -0
- package/dist/modules/whatsapp/operator-request.model.js +65 -0
- package/dist/modules/whatsapp/operator-request.model.js.map +1 -0
- package/dist/modules/whatsapp/stt-usage.model.d.ts +16 -0
- package/dist/modules/whatsapp/stt-usage.model.js +53 -0
- package/dist/modules/whatsapp/stt-usage.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js +55 -0
- package/dist/modules/whatsapp/whatsapp-chat.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.d.ts +23 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js +54 -0
- package/dist/modules/whatsapp/whatsapp-contact-profile.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-message.model.d.ts +30 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js +52 -0
- package/dist/modules/whatsapp/whatsapp-message.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp-session.model.d.ts +33 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js +65 -0
- package/dist/modules/whatsapp/whatsapp-session.model.js.map +1 -0
- package/dist/modules/whatsapp/whatsapp.routes.d.ts +2 -0
- package/dist/modules/whatsapp/whatsapp.routes.js +1237 -0
- package/dist/modules/whatsapp/whatsapp.routes.js.map +1 -0
- package/dist/plugins/cors.d.ts +3 -0
- package/dist/plugins/cors.js +11 -0
- package/dist/plugins/cors.js.map +1 -0
- package/dist/plugins/jwt.d.ts +3 -0
- package/dist/plugins/jwt.js +22 -0
- package/dist/plugins/jwt.js.map +1 -0
- package/dist/plugins/rawBody.d.ts +3 -0
- package/dist/plugins/rawBody.js +16 -0
- package/dist/plugins/rawBody.js.map +1 -0
- package/dist/plugins/rbac.d.ts +5 -0
- package/dist/plugins/rbac.js +29 -0
- package/dist/plugins/rbac.js.map +1 -0
- package/dist/routes/admin.routes.d.ts +2 -0
- package/dist/routes/admin.routes.js +169 -0
- package/dist/routes/admin.routes.js.map +1 -0
- package/dist/routes/health.routes.d.ts +2 -0
- package/dist/routes/health.routes.js +16 -0
- package/dist/routes/health.routes.js.map +1 -0
- package/dist/routes/webhook.routes.d.ts +2 -0
- package/dist/routes/webhook.routes.js +17 -0
- package/dist/routes/webhook.routes.js.map +1 -0
- package/dist/services/ai/base.ai.d.ts +19 -0
- package/dist/services/ai/base.ai.js +120 -0
- package/dist/services/ai/base.ai.js.map +1 -0
- package/dist/services/ai/gemini.service.d.ts +11 -0
- package/dist/services/ai/gemini.service.js +43 -0
- package/dist/services/ai/gemini.service.js.map +1 -0
- package/dist/services/ai/index.d.ts +2 -0
- package/dist/services/ai/index.js +26 -0
- package/dist/services/ai/index.js.map +1 -0
- package/dist/services/ai/openai.service.d.ts +11 -0
- package/dist/services/ai/openai.service.js +50 -0
- package/dist/services/ai/openai.service.js.map +1 -0
- package/dist/services/elevenlabs.service.d.ts +52 -0
- package/dist/services/elevenlabs.service.js +447 -0
- package/dist/services/elevenlabs.service.js.map +1 -0
- package/dist/services/google-calendar.service.d.ts +60 -0
- package/dist/services/google-calendar.service.js +494 -0
- package/dist/services/google-calendar.service.js.map +1 -0
- package/dist/services/inbound-call-schedule.service.d.ts +11 -0
- package/dist/services/inbound-call-schedule.service.js +162 -0
- package/dist/services/inbound-call-schedule.service.js.map +1 -0
- package/dist/services/netgsm.service.d.ts +41 -0
- package/dist/services/netgsm.service.js +89 -0
- package/dist/services/netgsm.service.js.map +1 -0
- package/dist/services/unipile.service.d.ts +41 -0
- package/dist/services/unipile.service.js +149 -0
- package/dist/services/unipile.service.js.map +1 -0
- package/dist/services/whatsapp-agent.service.d.ts +139 -0
- package/dist/services/whatsapp-agent.service.js +2055 -0
- package/dist/services/whatsapp-agent.service.js.map +1 -0
- package/dist/services/whatsapp.service.d.ts +26 -0
- package/dist/services/whatsapp.service.js +206 -0
- package/dist/services/whatsapp.service.js.map +1 -0
- package/dist/templates/index.d.ts +39 -0
- package/dist/templates/index.js +35 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/receptionist.d.ts +2 -0
- package/dist/templates/receptionist.js +39 -0
- package/dist/templates/receptionist.js.map +1 -0
- package/dist/templates/survey.d.ts +2 -0
- package/dist/templates/survey.js +41 -0
- package/dist/templates/survey.js.map +1 -0
- package/dist/types/index.d.ts +173 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.js +105 -0
- package/dist/utils/logger.js.map +1 -0
- package/docker-compose.nestjs.yml +89 -0
- package/docker-compose.yml +78 -0
- package/docs/AI_AGENT_ENHANCEMENT_PLAN.md +164 -0
- package/docs/API.md +1193 -0
- package/docs/API_ENDPOINTS.md +344 -0
- package/docs/ARCHITECTURE.md +305 -0
- package/docs/AUTH_API.md +252 -0
- package/docs/BILLING_SMS_ALERTS.md +94 -0
- package/docs/CHAT_ASSIGNMENT_SYSTEM.md +118 -0
- package/docs/CLIENT_TOOLS_AND_FEATURES.md +337 -0
- package/docs/ELEVENLABS_WEBHOOK_TOOLS.md +644 -0
- package/docs/FRONTEND_CHECKLIST.md +227 -0
- package/docs/IMPLEMENTATION_STATUS.md +470 -0
- package/docs/MIGRATION_GUIDE.md +96 -0
- package/docs/MISSINGS_REPORT.md +507 -0
- package/docs/NESTJS_MIGRATION_REFERENCE.md +5136 -0
- package/docs/PROJECT_DESCRIPTION.md +1038 -0
- package/docs/SCALING.md +148 -0
- package/docs/SESSION_SUMMARY_2026_03_17.md +135 -0
- package/docs/WHATSAPP_AGENT.md +1086 -0
- package/docs/architecture/00-SYSTEM-OVERVIEW.md +318 -0
- package/docs/architecture/01-DATABASE-SCHEMA.md +2564 -0
- package/docs/architecture/02-AUTHENTICATION.md +1040 -0
- package/docs/architecture/03-MULTI-CLINIC.md +742 -0
- package/docs/architecture/04-WHATSAPP-AGENT.md +608 -0
- package/docs/architecture/05-OPERATOR-WORKFLOW.md +444 -0
- package/docs/architecture/06-BAILEYS-MICROSERVICE.md +616 -0
- package/docs/architecture/07-APPOINTMENTS.md +849 -0
- package/docs/architecture/08-VOICE-CALLS.md +470 -0
- package/docs/architecture/09-OUTBOUND-CAMPAIGNS.md +542 -0
- package/docs/architecture/10-CLIENT-TOOLS.md +665 -0
- package/docs/architecture/11-BILLING.md +458 -0
- package/docs/architecture/12-SECURITY.md +216 -0
- package/docs/architecture/13-LOGGING-AUDIT.md +549 -0
- package/docs/architecture/14-META-BUSINESS-API.md +454 -0
- package/docs/architecture/15-AI-MODULE.md +479 -0
- package/docs/architecture/16-BACKGROUND-JOBS.md +469 -0
- package/docs/architecture/17-REALTIME-LIVECHAT.md +447 -0
- package/docs/architecture/18-FILE-STORAGE.md +410 -0
- package/docs/architecture/19-PATIENTS.md +1034 -0
- package/docs/architecture/20-TREATMENTS-AND-PLANS.md +774 -0
- package/docs/architecture/21-BEFORE-AFTER-PHOTOS.md +519 -0
- package/docs/database.md +456 -0
- package/docs/ornek-randevu-onay.csv +3 -0
- package/ecosystem.config.js +16 -0
- package/elevenlabs-convai-api-reference.md +1171 -0
- package/frontend/.dockerignore +2 -0
- package/frontend/Dockerfile +24 -0
- package/frontend/README.md +75 -0
- package/frontend/components.json +25 -0
- package/frontend/eslint.config.js +23 -0
- package/frontend/index.html +13 -0
- package/frontend/nginx.conf +37 -0
- package/frontend/package-lock.json +8709 -0
- package/frontend/package.json +71 -0
- package/frontend/public/favicon.svg +1 -0
- package/frontend/public/icons.svg +24 -0
- package/frontend/src/App.tsx +125 -0
- package/frontend/src/components/error-boundary.tsx +50 -0
- package/frontend/src/components/shared/activity-timeline.tsx +66 -0
- package/frontend/src/components/shared/appointment-calendar.css +80 -0
- package/frontend/src/components/shared/appointment-calendar.tsx +245 -0
- package/frontend/src/components/shared/chat-bubble.tsx +72 -0
- package/frontend/src/components/shared/combobox.tsx +119 -0
- package/frontend/src/components/shared/confirm-dialog.tsx +57 -0
- package/frontend/src/components/shared/data-table-pagination.tsx +97 -0
- package/frontend/src/components/shared/data-table-toolbar.tsx +39 -0
- package/frontend/src/components/shared/empty-state.tsx +27 -0
- package/frontend/src/components/shared/file-upload.tsx +140 -0
- package/frontend/src/components/shared/index.ts +20 -0
- package/frontend/src/components/shared/language-switcher.tsx +29 -0
- package/frontend/src/components/shared/notification-dropdown.tsx +115 -0
- package/frontend/src/components/shared/page-header.tsx +23 -0
- package/frontend/src/components/shared/stat-card.tsx +37 -0
- package/frontend/src/components/shared/status-badge.tsx +70 -0
- package/frontend/src/components/shared/status-dot.tsx +43 -0
- package/frontend/src/components/ui/alert-dialog.tsx +187 -0
- package/frontend/src/components/ui/alert.tsx +76 -0
- package/frontend/src/components/ui/avatar.tsx +109 -0
- package/frontend/src/components/ui/badge.tsx +52 -0
- package/frontend/src/components/ui/breadcrumb.tsx +125 -0
- package/frontend/src/components/ui/button.tsx +60 -0
- package/frontend/src/components/ui/calendar.tsx +219 -0
- package/frontend/src/components/ui/card.tsx +103 -0
- package/frontend/src/components/ui/chart.tsx +371 -0
- package/frontend/src/components/ui/checkbox.tsx +29 -0
- package/frontend/src/components/ui/collapsible.tsx +19 -0
- package/frontend/src/components/ui/command.tsx +194 -0
- package/frontend/src/components/ui/dialog.tsx +158 -0
- package/frontend/src/components/ui/dropdown-menu.tsx +268 -0
- package/frontend/src/components/ui/input-group.tsx +156 -0
- package/frontend/src/components/ui/input.tsx +20 -0
- package/frontend/src/components/ui/label.tsx +20 -0
- package/frontend/src/components/ui/pagination.tsx +130 -0
- package/frontend/src/components/ui/popover.tsx +90 -0
- package/frontend/src/components/ui/progress.tsx +83 -0
- package/frontend/src/components/ui/radio-group.tsx +36 -0
- package/frontend/src/components/ui/scroll-area.tsx +54 -0
- package/frontend/src/components/ui/select.tsx +199 -0
- package/frontend/src/components/ui/separator.tsx +23 -0
- package/frontend/src/components/ui/sheet.tsx +138 -0
- package/frontend/src/components/ui/sidebar.tsx +723 -0
- package/frontend/src/components/ui/skeleton.tsx +13 -0
- package/frontend/src/components/ui/sonner.tsx +47 -0
- package/frontend/src/components/ui/switch.tsx +30 -0
- package/frontend/src/components/ui/table.tsx +114 -0
- package/frontend/src/components/ui/tabs.tsx +82 -0
- package/frontend/src/components/ui/textarea.tsx +18 -0
- package/frontend/src/components/ui/toggle-group.tsx +89 -0
- package/frontend/src/components/ui/toggle.tsx +43 -0
- package/frontend/src/components/ui/tooltip.tsx +64 -0
- package/frontend/src/hooks/use-mobile.ts +19 -0
- package/frontend/src/i18n/index.ts +20 -0
- package/frontend/src/i18n/locales/en.json +786 -0
- package/frontend/src/i18n/locales/tr.json +786 -0
- package/frontend/src/index.css +134 -0
- package/frontend/src/layouts/admin-layout.tsx +111 -0
- package/frontend/src/layouts/app-header.tsx +130 -0
- package/frontend/src/layouts/app-layout.tsx +19 -0
- package/frontend/src/layouts/app-sidebar.tsx +212 -0
- package/frontend/src/layouts/auth-guard.tsx +31 -0
- package/frontend/src/layouts/mobile-sidebar.tsx +120 -0
- package/frontend/src/lib/api.ts +68 -0
- package/frontend/src/lib/hooks/use-appointments.ts +224 -0
- package/frontend/src/lib/hooks/use-availability-blocks.ts +83 -0
- package/frontend/src/lib/hooks/use-chats.ts +236 -0
- package/frontend/src/lib/hooks/use-clinic-detail.ts +171 -0
- package/frontend/src/lib/hooks/use-clinics.ts +37 -0
- package/frontend/src/lib/hooks/use-doctor-calendar.ts +80 -0
- package/frontend/src/lib/hooks/use-examinations.ts +89 -0
- package/frontend/src/lib/hooks/use-medical-history.ts +52 -0
- package/frontend/src/lib/hooks/use-patients.ts +296 -0
- package/frontend/src/lib/hooks/use-photo-sets.ts +118 -0
- package/frontend/src/lib/hooks/use-treatment-plans.ts +152 -0
- package/frontend/src/lib/hooks/use-treatments.ts +125 -0
- package/frontend/src/lib/hooks/use-users.ts +172 -0
- package/frontend/src/lib/utils.ts +6 -0
- package/frontend/src/main.tsx +17 -0
- package/frontend/src/pages/admin/agents/detail.tsx +774 -0
- package/frontend/src/pages/admin/agents/import.tsx +280 -0
- package/frontend/src/pages/admin/agents/index.tsx +245 -0
- package/frontend/src/pages/admin/ai-playground.tsx +543 -0
- package/frontend/src/pages/appointments/create-appointment-dialog.tsx +390 -0
- package/frontend/src/pages/appointments/index.tsx +860 -0
- package/frontend/src/pages/audit/index.tsx +24 -0
- package/frontend/src/pages/auth/login.tsx +194 -0
- package/frontend/src/pages/billing/index.tsx +24 -0
- package/frontend/src/pages/calendar/index.tsx +704 -0
- package/frontend/src/pages/calendar-connections/index.tsx +295 -0
- package/frontend/src/pages/calls/index.tsx +24 -0
- package/frontend/src/pages/campaigns/index.tsx +24 -0
- package/frontend/src/pages/chats/index.tsx +981 -0
- package/frontend/src/pages/clinics/index.tsx +224 -0
- package/frontend/src/pages/clinics/settings.tsx +412 -0
- package/frontend/src/pages/components-showcase.tsx +773 -0
- package/frontend/src/pages/connections/index.tsx +328 -0
- package/frontend/src/pages/dashboard.tsx +50 -0
- package/frontend/src/pages/leads/index.tsx +24 -0
- package/frontend/src/pages/my-schedule/index.tsx +496 -0
- package/frontend/src/pages/patients/create-patient-dialog.tsx +358 -0
- package/frontend/src/pages/patients/detail.tsx +1195 -0
- package/frontend/src/pages/patients/edit-patient-dialog.tsx +387 -0
- package/frontend/src/pages/patients/examinations-tab.tsx +460 -0
- package/frontend/src/pages/patients/index.tsx +381 -0
- package/frontend/src/pages/patients/medical-history-dialog.tsx +207 -0
- package/frontend/src/pages/patients/photo-sets-tab.tsx +616 -0
- package/frontend/src/pages/patients/timeline-tab.tsx +164 -0
- package/frontend/src/pages/patients/treatment-plans-tab.tsx +598 -0
- package/frontend/src/pages/phone-numbers/detail.tsx +427 -0
- package/frontend/src/pages/phone-numbers/index.tsx +455 -0
- package/frontend/src/pages/platform/index.tsx +454 -0
- package/frontend/src/pages/settings/index.tsx +126 -0
- package/frontend/src/pages/treatments/index.tsx +487 -0
- package/frontend/src/pages/users/doctor-profile.tsx +672 -0
- package/frontend/src/pages/users/edit.tsx +329 -0
- package/frontend/src/pages/users/index.tsx +407 -0
- package/frontend/src/pages/validation/index.tsx +24 -0
- package/frontend/src/stores/auth.store.ts +108 -0
- package/frontend/src/stores/ui.store.ts +41 -0
- package/frontend/tsconfig.app.json +32 -0
- package/frontend/tsconfig.json +13 -0
- package/frontend/tsconfig.node.json +26 -0
- package/frontend/vite.config.ts +29 -0
- package/nestjs/.dockerignore +5 -0
- package/nestjs/.env.docker +64 -0
- package/nestjs/.prettierrc +4 -0
- package/nestjs/Dockerfile +36 -0
- package/nestjs/README.md +98 -0
- package/nestjs/eslint.config.mjs +35 -0
- package/nestjs/nest-cli.json +8 -0
- package/nestjs/package-lock.json +13390 -0
- package/nestjs/package.json +114 -0
- package/nestjs/prisma/migrations/20260409161536_add_message_metadata_fields/migration.sql +1746 -0
- package/nestjs/prisma/migrations/20260410140436_add_agent_ai_fields/migration.sql +36 -0
- package/nestjs/prisma/migrations/20260410175519_add_agent_clinic_assignments/migration.sql +21 -0
- package/nestjs/prisma/migrations/20260412094344_make_agent_tenant_optional/migration.sql +2 -0
- package/nestjs/prisma/migrations/20260412110008_add_admin_chat_sessions/migration.sql +47 -0
- package/nestjs/prisma/migrations/migration_lock.toml +3 -0
- package/nestjs/prisma/schema.prisma +1843 -0
- package/nestjs/prisma/seed.ts +375 -0
- package/nestjs/prisma.config.ts +14 -0
- package/nestjs/src/admin/admin.controller.ts +27 -0
- package/nestjs/src/admin/admin.module.ts +16 -0
- package/nestjs/src/admin/admin.service.ts +91 -0
- package/nestjs/src/admin/ai-chat-session.service.ts +454 -0
- package/nestjs/src/admin/ai-test.controller.ts +191 -0
- package/nestjs/src/admin/superadmin.controller.ts +106 -0
- package/nestjs/src/agents/agents.controller.ts +262 -0
- package/nestjs/src/agents/agents.module.ts +13 -0
- package/nestjs/src/agents/agents.service.ts +733 -0
- package/nestjs/src/agents/dto/create-agent.dto.ts +99 -0
- package/nestjs/src/agents/dto/index.ts +2 -0
- package/nestjs/src/agents/dto/update-agent.dto.ts +148 -0
- package/nestjs/src/app.module.ts +115 -0
- package/nestjs/src/appointment-validation/appointment-validation.controller.ts +194 -0
- package/nestjs/src/appointment-validation/appointment-validation.module.ts +16 -0
- package/nestjs/src/appointment-validation/appointment-validation.service.ts +450 -0
- package/nestjs/src/appointment-validation/dto/create-batch.dto.ts +105 -0
- package/nestjs/src/appointment-validation/dto/index.ts +1 -0
- package/nestjs/src/appointment-validation/processors/validation-dispatch.processor.ts +26 -0
- package/nestjs/src/appointment-validation/processors/validation-sync.processor.ts +23 -0
- package/nestjs/src/appointments/appointments.controller.ts +268 -0
- package/nestjs/src/appointments/appointments.module.ts +13 -0
- package/nestjs/src/appointments/appointments.service.ts +773 -0
- package/nestjs/src/appointments/dto/create-appointment.dto.ts +72 -0
- package/nestjs/src/appointments/dto/index.ts +4 -0
- package/nestjs/src/appointments/dto/query-appointments.dto.ts +60 -0
- package/nestjs/src/appointments/dto/update-appointment.dto.ts +43 -0
- package/nestjs/src/appointments/dto/update-status.dto.ts +18 -0
- package/nestjs/src/appointments/processors/reminder.processor.ts +243 -0
- package/nestjs/src/audit/audit.controller.ts +84 -0
- package/nestjs/src/audit/audit.decorator.ts +20 -0
- package/nestjs/src/audit/audit.interceptor.ts +67 -0
- package/nestjs/src/audit/audit.interfaces.ts +15 -0
- package/nestjs/src/audit/audit.module.ts +12 -0
- package/nestjs/src/audit/audit.service.ts +177 -0
- package/nestjs/src/auth/auth.controller.ts +116 -0
- package/nestjs/src/auth/auth.module.ts +25 -0
- package/nestjs/src/auth/auth.service.ts +612 -0
- package/nestjs/src/auth/dto/change-password.dto.ts +13 -0
- package/nestjs/src/auth/dto/forgot-password.dto.ts +8 -0
- package/nestjs/src/auth/dto/index.ts +6 -0
- package/nestjs/src/auth/dto/login.dto.ts +13 -0
- package/nestjs/src/auth/dto/refresh.dto.ts +8 -0
- package/nestjs/src/auth/dto/register.dto.ts +28 -0
- package/nestjs/src/auth/dto/reset-password.dto.ts +13 -0
- package/nestjs/src/auth/permissions.config.ts +85 -0
- package/nestjs/src/availability-blocks/availability-blocks.controller.ts +83 -0
- package/nestjs/src/availability-blocks/availability-blocks.module.ts +10 -0
- package/nestjs/src/availability-blocks/availability-blocks.service.ts +202 -0
- package/nestjs/src/billing/billing.controller.ts +104 -0
- package/nestjs/src/billing/billing.module.ts +12 -0
- package/nestjs/src/billing/billing.service.ts +398 -0
- package/nestjs/src/billing/dto/index.ts +2 -0
- package/nestjs/src/billing/dto/query-billing.dto.ts +29 -0
- package/nestjs/src/billing/dto/record-payment.dto.ts +60 -0
- package/nestjs/src/billing/processors/alerts.processor.ts +216 -0
- package/nestjs/src/billing/processors/snapshot.processor.ts +181 -0
- package/nestjs/src/calls/calls.controller.ts +92 -0
- package/nestjs/src/calls/calls.module.ts +10 -0
- package/nestjs/src/calls/calls.service.ts +359 -0
- package/nestjs/src/calls/dto/index.ts +1 -0
- package/nestjs/src/calls/dto/query-calls.dto.ts +46 -0
- package/nestjs/src/clinics/clinics.controller.ts +226 -0
- package/nestjs/src/clinics/clinics.module.ts +11 -0
- package/nestjs/src/clinics/clinics.service.ts +203 -0
- package/nestjs/src/clinics/dto/create-clinic.dto.ts +40 -0
- package/nestjs/src/clinics/dto/create-meta-connection.dto.ts +44 -0
- package/nestjs/src/clinics/dto/index.ts +4 -0
- package/nestjs/src/clinics/dto/update-clinic.dto.ts +133 -0
- package/nestjs/src/clinics/dto/update-meta-connection.dto.ts +22 -0
- package/nestjs/src/clinics/meta-connections.service.ts +210 -0
- package/nestjs/src/common/decorators/accessible-clinics.decorator.ts +9 -0
- package/nestjs/src/common/decorators/current-user.decorator.ts +10 -0
- package/nestjs/src/common/decorators/features.decorator.ts +7 -0
- package/nestjs/src/common/decorators/index.ts +4 -0
- package/nestjs/src/common/decorators/permissions.decorator.ts +13 -0
- package/nestjs/src/common/gateways/events.gateway.ts +157 -0
- package/nestjs/src/common/guards/clinic-access.guard.ts +40 -0
- package/nestjs/src/common/guards/features.guard.ts +38 -0
- package/nestjs/src/common/guards/index.ts +5 -0
- package/nestjs/src/common/guards/jwt-auth.guard.ts +54 -0
- package/nestjs/src/common/guards/permissions.guard.ts +50 -0
- package/nestjs/src/common/guards/superadmin.guard.ts +35 -0
- package/nestjs/src/common/interceptors/request-context.interceptor.ts +32 -0
- package/nestjs/src/common/interceptors/superadmin-tenant.interceptor.ts +42 -0
- package/nestjs/src/common/interfaces/jwt-payload.interface.ts +11 -0
- package/nestjs/src/config/config.module.ts +13 -0
- package/nestjs/src/database/database.module.ts +9 -0
- package/nestjs/src/database/prisma.service.ts +20 -0
- package/nestjs/src/database/tenant-context.ts +27 -0
- package/nestjs/src/google-calendar/google-calendar.controller.ts +259 -0
- package/nestjs/src/google-calendar/google-calendar.module.ts +10 -0
- package/nestjs/src/google-calendar/google-calendar.service.ts +811 -0
- package/nestjs/src/integrations/ai/ai.interface.ts +74 -0
- package/nestjs/src/integrations/ai/ai.module.ts +11 -0
- package/nestjs/src/integrations/ai/ai.service.ts +148 -0
- package/nestjs/src/integrations/ai/providers/anthropic.provider.ts +146 -0
- package/nestjs/src/integrations/ai/providers/openai.provider.ts +158 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.module.ts +8 -0
- package/nestjs/src/integrations/elevenlabs/elevenlabs.service.ts +226 -0
- package/nestjs/src/integrations/encryption/encryption.module.ts +9 -0
- package/nestjs/src/integrations/encryption/encryption.service.ts +31 -0
- package/nestjs/src/integrations/image/image.module.ts +9 -0
- package/nestjs/src/integrations/image/image.service.ts +61 -0
- package/nestjs/src/integrations/meta-business/meta-business.module.ts +10 -0
- package/nestjs/src/integrations/meta-business/meta-instagram.service.ts +94 -0
- package/nestjs/src/integrations/meta-business/meta-webhook.service.ts +52 -0
- package/nestjs/src/integrations/meta-business/meta-whatsapp.service.ts +254 -0
- package/nestjs/src/integrations/minio/minio.module.ts +9 -0
- package/nestjs/src/integrations/minio/minio.service.ts +88 -0
- package/nestjs/src/integrations/netgsm/netgsm.module.ts +8 -0
- package/nestjs/src/integrations/netgsm/netgsm.service.ts +17 -0
- package/nestjs/src/integrations/tektippay/tektippay.module.ts +8 -0
- package/nestjs/src/integrations/tektippay/tektippay.service.ts +23 -0
- package/nestjs/src/leads/dto/index.ts +2 -0
- package/nestjs/src/leads/dto/query-leads.dto.ts +50 -0
- package/nestjs/src/leads/dto/update-lead.dto.ts +26 -0
- package/nestjs/src/leads/leads.controller.ts +184 -0
- package/nestjs/src/leads/leads.module.ts +10 -0
- package/nestjs/src/leads/leads.service.ts +375 -0
- package/nestjs/src/logging/logging.controller.ts +82 -0
- package/nestjs/src/logging/logging.module.ts +11 -0
- package/nestjs/src/logging/logging.service.ts +180 -0
- package/nestjs/src/main.ts +86 -0
- package/nestjs/src/outbound-campaigns/dto/create-campaign.dto.ts +47 -0
- package/nestjs/src/outbound-campaigns/dto/index.ts +3 -0
- package/nestjs/src/outbound-campaigns/dto/update-campaign.dto.ts +31 -0
- package/nestjs/src/outbound-campaigns/dto/upload-entries.dto.ts +35 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.controller.ts +307 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.module.ts +13 -0
- package/nestjs/src/outbound-campaigns/outbound-campaigns.service.ts +471 -0
- package/nestjs/src/outbound-campaigns/processors/campaign-dispatch.processor.ts +366 -0
- package/nestjs/src/patients/documents.service.ts +231 -0
- package/nestjs/src/patients/dto/create-examination.dto.ts +34 -0
- package/nestjs/src/patients/dto/create-note.dto.ts +14 -0
- package/nestjs/src/patients/dto/create-patient.dto.ts +86 -0
- package/nestjs/src/patients/dto/create-photo-set.dto.ts +32 -0
- package/nestjs/src/patients/dto/index.ts +10 -0
- package/nestjs/src/patients/dto/update-examination.dto.ts +29 -0
- package/nestjs/src/patients/dto/update-medical-history.dto.ts +47 -0
- package/nestjs/src/patients/dto/update-patient.dto.ts +87 -0
- package/nestjs/src/patients/dto/update-photo-set.dto.ts +28 -0
- package/nestjs/src/patients/dto/upload-document.dto.ts +31 -0
- package/nestjs/src/patients/dto/upload-photo.dto.ts +27 -0
- package/nestjs/src/patients/examinations.service.ts +271 -0
- package/nestjs/src/patients/medical-history.service.ts +149 -0
- package/nestjs/src/patients/notes.service.ts +172 -0
- package/nestjs/src/patients/patients.controller.ts +485 -0
- package/nestjs/src/patients/patients.module.ts +22 -0
- package/nestjs/src/patients/patients.service.ts +412 -0
- package/nestjs/src/patients/photo-sets.service.ts +389 -0
- package/nestjs/src/phone-numbers/dto/create-phone-number.dto.ts +57 -0
- package/nestjs/src/phone-numbers/dto/index.ts +3 -0
- package/nestjs/src/phone-numbers/dto/update-phone-number.dto.ts +38 -0
- package/nestjs/src/phone-numbers/dto/update-schedule.dto.ts +39 -0
- package/nestjs/src/phone-numbers/phone-numbers.controller.ts +125 -0
- package/nestjs/src/phone-numbers/phone-numbers.module.ts +10 -0
- package/nestjs/src/phone-numbers/phone-numbers.service.ts +209 -0
- package/nestjs/src/plans/dto/create-plan.dto.ts +70 -0
- package/nestjs/src/plans/dto/index.ts +2 -0
- package/nestjs/src/plans/dto/update-plan.dto.ts +80 -0
- package/nestjs/src/plans/plans.controller.ts +50 -0
- package/nestjs/src/plans/plans.module.ts +10 -0
- package/nestjs/src/plans/plans.service.ts +115 -0
- package/nestjs/src/platform/dto/create-tenant.dto.ts +36 -0
- package/nestjs/src/platform/dto/index.ts +2 -0
- package/nestjs/src/platform/dto/update-tenant-platform.dto.ts +44 -0
- package/nestjs/src/platform/platform.controller.ts +79 -0
- package/nestjs/src/platform/platform.module.ts +10 -0
- package/nestjs/src/platform/platform.service.ts +301 -0
- package/nestjs/src/queue/queue.module.ts +56 -0
- package/nestjs/src/redis/redis.module.ts +20 -0
- package/nestjs/src/tenants/dto/index.ts +1 -0
- package/nestjs/src/tenants/dto/update-tenant.dto.ts +15 -0
- package/nestjs/src/tenants/tenants.controller.ts +45 -0
- package/nestjs/src/tenants/tenants.module.ts +10 -0
- package/nestjs/src/tenants/tenants.service.ts +41 -0
- package/nestjs/src/tools/adapters/elevenlabs-http.adapter.ts +51 -0
- package/nestjs/src/tools/adapters/elevenlabs-ws.adapter.ts +59 -0
- package/nestjs/src/tools/handlers/calendar.tools.ts +441 -0
- package/nestjs/src/tools/handlers/notification.tools.ts +34 -0
- package/nestjs/src/tools/handlers/operator.tools.ts +303 -0
- package/nestjs/src/tools/handlers/patient.tools.ts +242 -0
- package/nestjs/src/tools/handlers/payment.tools.ts +43 -0
- package/nestjs/src/tools/handlers/validation.tools.ts +152 -0
- package/nestjs/src/tools/tool-registry.service.ts +221 -0
- package/nestjs/src/tools/tool.decorator.ts +16 -0
- package/nestjs/src/tools/tool.interfaces.ts +26 -0
- package/nestjs/src/tools/tools.module.ts +50 -0
- package/nestjs/src/treatments/dto/create-plan-item.dto.ts +27 -0
- package/nestjs/src/treatments/dto/create-treatment-plan.dto.ts +69 -0
- package/nestjs/src/treatments/dto/create-treatment.dto.ts +59 -0
- package/nestjs/src/treatments/dto/index.ts +6 -0
- package/nestjs/src/treatments/dto/update-plan-item.dto.ts +23 -0
- package/nestjs/src/treatments/dto/update-treatment-plan.dto.ts +22 -0
- package/nestjs/src/treatments/dto/update-treatment.dto.ts +70 -0
- package/nestjs/src/treatments/treatment-plans.service.ts +362 -0
- package/nestjs/src/treatments/treatments.controller.ts +265 -0
- package/nestjs/src/treatments/treatments.module.ts +14 -0
- package/nestjs/src/treatments/treatments.service.ts +165 -0
- package/nestjs/src/users/doctor-profiles.service.ts +202 -0
- package/nestjs/src/users/dto/index.ts +4 -0
- package/nestjs/src/users/dto/invite-user.dto.ts +52 -0
- package/nestjs/src/users/dto/update-clinic-assignments.dto.ts +9 -0
- package/nestjs/src/users/dto/update-doctor-profile.dto.ts +49 -0
- package/nestjs/src/users/dto/update-user.dto.ts +41 -0
- package/nestjs/src/users/users.controller.ts +142 -0
- package/nestjs/src/users/users.module.ts +11 -0
- package/nestjs/src/users/users.service.ts +250 -0
- package/nestjs/src/webhooks/elevenlabs-tool.controller.ts +66 -0
- package/nestjs/src/webhooks/elevenlabs-webhook.controller.ts +60 -0
- package/nestjs/src/webhooks/meta-webhook.controller.ts +178 -0
- package/nestjs/src/webhooks/processors/elevenlabs-webhook.processor.ts +28 -0
- package/nestjs/src/webhooks/webhooks.module.ts +17 -0
- package/nestjs/src/whatsapp/chat-context.service.ts +281 -0
- package/nestjs/src/whatsapp/dto/add-blacklist.dto.ts +13 -0
- package/nestjs/src/whatsapp/dto/index.ts +2 -0
- package/nestjs/src/whatsapp/dto/send-message.dto.ts +14 -0
- package/nestjs/src/whatsapp/listeners/meta-message.listener.ts +579 -0
- package/nestjs/src/whatsapp/meta-auth.controller.ts +268 -0
- package/nestjs/src/whatsapp/meta-instagram-auth.controller.ts +244 -0
- package/nestjs/src/whatsapp/operator.service.ts +692 -0
- package/nestjs/src/whatsapp/processors/cost-sweep.processor.ts +130 -0
- package/nestjs/src/whatsapp/processors/grace.processor.ts +191 -0
- package/nestjs/src/whatsapp/processors/message-buffer.processor.ts +138 -0
- package/nestjs/src/whatsapp/processors/message-cleanup.processor.ts +148 -0
- package/nestjs/src/whatsapp/processors/meta-token-refresh.processor.ts +114 -0
- package/nestjs/src/whatsapp/processors/operator-expiry.processor.ts +105 -0
- package/nestjs/src/whatsapp/processors/profile-update.processor.ts +234 -0
- package/nestjs/src/whatsapp/processors/session-cleanup.processor.ts +178 -0
- package/nestjs/src/whatsapp/processors/session-labels.processor.ts +248 -0
- package/nestjs/src/whatsapp/whatsapp-agent.service.ts +2506 -0
- package/nestjs/src/whatsapp/whatsapp-recovery.service.ts +117 -0
- package/nestjs/src/whatsapp/whatsapp.controller.ts +398 -0
- package/nestjs/src/whatsapp/whatsapp.module.ts +51 -0
- package/nestjs/src/whatsapp/whatsapp.service.ts +592 -0
- package/nestjs/test/app.e2e-spec.ts +25 -0
- package/nestjs/test/jest-e2e.json +9 -0
- package/nestjs/tsconfig.build.json +4 -0
- package/nestjs/tsconfig.json +25 -0
- package/nginx.example.conf +18 -0
- package/package.json +47 -0
- package/scripts/addRecipient.ts +48 -0
- package/scripts/listRecipients.ts +31 -0
- package/scripts/migrate-agent-ref.ts +86 -0
- package/scripts/migrate-sessions.ts +183 -0
- package/scripts/promote.ts +27 -0
- package/scripts/retrigger.ts +84 -0
- package/scripts/seed.ts +435 -0
- package/scripts/testSend.ts +63 -0
- package/src/app.ts +85 -0
- package/src/config/agentPrompts.json +19 -0
- package/src/config/database.ts +21 -0
- package/src/config/env.ts +94 -0
- package/src/config/index.ts +86 -0
- package/src/controllers/webhook.controller.ts +150 -0
- package/src/errors/index.ts +9 -0
- package/src/hooks/webhookValidator.ts +55 -0
- package/src/index.ts +68 -0
- package/src/migrations/001_session-architecture.ts +138 -0
- package/src/migrations/002_agent-ref.ts +65 -0
- package/src/migrations/003_shift-schedule.ts +55 -0
- package/src/migrations/004_invert-shift-to-clinic-hours.ts +30 -0
- package/src/migrations/005_composite-baileys-chat-ids.ts +60 -0
- package/src/migrations/migration.model.ts +27 -0
- package/src/migrations/migration.routes.ts +40 -0
- package/src/migrations/migration.runner.ts +112 -0
- package/src/models/ConversationClaim.ts +17 -0
- package/src/models/ConversationEvaluation.ts +91 -0
- package/src/models/Summary.ts +77 -0
- package/src/models/Transcription.ts +68 -0
- package/src/models/WhatsAppRecipient.ts +37 -0
- package/src/modules/admin/admin.routes.ts +2385 -0
- package/src/modules/admin/elevenlabs-test-chat.routes.ts +193 -0
- package/src/modules/admin/whatsapp-test-chat.routes.ts +244 -0
- package/src/modules/agents/agent.model.ts +93 -0
- package/src/modules/agents/agent.routes.ts +65 -0
- package/src/modules/appointment-validation/appointment-validation.model.ts +163 -0
- package/src/modules/appointment-validation/appointment-validation.routes.ts +275 -0
- package/src/modules/appointment-validation/appointment-validation.service.ts +1028 -0
- package/src/modules/auth/auth.model.ts +42 -0
- package/src/modules/auth/auth.routes.ts +199 -0
- package/src/modules/auth/auth.service.ts +210 -0
- package/src/modules/auth/refresh-token.model.ts +26 -0
- package/src/modules/billing/billing-alert.model.ts +28 -0
- package/src/modules/billing/billing-period-snapshot.model.ts +68 -0
- package/src/modules/billing/billing.model.ts +42 -0
- package/src/modules/billing/billing.routes.ts +67 -0
- package/src/modules/billing/billing.service.ts +562 -0
- package/src/modules/billing/payment.model.ts +42 -0
- package/src/modules/calls/call.model.ts +102 -0
- package/src/modules/calls/call.routes.ts +118 -0
- package/src/modules/campaigns/campaign.model.ts +111 -0
- package/src/modules/campaigns/campaign.routes.ts +402 -0
- package/src/modules/campaigns/campaign.service.ts +99 -0
- package/src/modules/google-calendar/google-calendar.routes.ts +31 -0
- package/src/modules/inbound-call/inbound-call-config.model.ts +49 -0
- package/src/modules/inbound-call/inbound-call.routes.ts +289 -0
- package/src/modules/leads/lead.model.ts +40 -0
- package/src/modules/leads/lead.routes.ts +246 -0
- package/src/modules/logs/log.model.ts +27 -0
- package/src/modules/logs/log.routes.ts +102 -0
- package/src/modules/plans/plan.model.ts +45 -0
- package/src/modules/surveys/survey.model.ts +70 -0
- package/src/modules/surveys/survey.routes.ts +187 -0
- package/src/modules/tenants/tenant.model.ts +181 -0
- package/src/modules/tenants/tenant.routes.ts +78 -0
- package/src/modules/users/user.routes.ts +126 -0
- package/src/modules/webhooks/elevenlabs-tool.routes.ts +94 -0
- package/src/modules/webhooks/elevenlabs-tool.service.ts +491 -0
- package/src/modules/webhooks/elevenlabs.routes.ts +34 -0
- package/src/modules/webhooks/elevenlabs.service.ts +565 -0
- package/src/modules/webhooks/unipile.routes.ts +917 -0
- package/src/modules/whatsapp/appointment.model.ts +47 -0
- package/src/modules/whatsapp/operator-request.model.ts +58 -0
- package/src/modules/whatsapp/stt-usage.model.ts +30 -0
- package/src/modules/whatsapp/whatsapp-chat.model.ts +39 -0
- package/src/modules/whatsapp/whatsapp-contact-profile.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-message.model.ts +41 -0
- package/src/modules/whatsapp/whatsapp-session.model.ts +60 -0
- package/src/modules/whatsapp/whatsapp.routes.ts +1435 -0
- package/src/plugins/cors.ts +7 -0
- package/src/plugins/jwt.ts +18 -0
- package/src/plugins/rawBody.ts +12 -0
- package/src/plugins/rbac.ts +24 -0
- package/src/routes/admin.routes.ts +208 -0
- package/src/routes/health.routes.ts +12 -0
- package/src/routes/webhook.routes.ts +12 -0
- package/src/services/ai/base.ai.ts +132 -0
- package/src/services/ai/gemini.service.ts +41 -0
- package/src/services/ai/index.ts +24 -0
- package/src/services/ai/openai.service.ts +48 -0
- package/src/services/elevenlabs.service.ts +532 -0
- package/src/services/google-calendar.service.ts +656 -0
- package/src/services/inbound-call-schedule.service.ts +174 -0
- package/src/services/netgsm.service.ts +128 -0
- package/src/services/unipile.service.ts +200 -0
- package/src/services/whatsapp-agent.service.ts +2479 -0
- package/src/services/whatsapp.service.ts +245 -0
- package/src/templates/index.ts +71 -0
- package/src/templates/receptionist.ts +44 -0
- package/src/templates/survey.ts +44 -0
- package/src/types/index.ts +218 -0
- package/src/utils/logger.ts +83 -0
- package/tsconfig.json +19 -0
- package/web/.dockerignore +4 -0
- package/web/Dockerfile +18 -0
- package/web/README.md +73 -0
- package/web/components.json +23 -0
- package/web/eslint.config.js +23 -0
- package/web/index.html +14 -0
- package/web/nginx.conf +18 -0
- package/web/package-lock.json +10292 -0
- package/web/package.json +48 -0
- package/web/public/favicon.ico +0 -0
- package/web/public/vite.svg +1 -0
- package/web/src/App.tsx +191 -0
- package/web/src/assets/react.svg +1 -0
- package/web/src/components/Layout.tsx +261 -0
- package/web/src/components/LeadConversation.tsx +251 -0
- package/web/src/components/ProtectedRoute.tsx +20 -0
- package/web/src/components/conversation-review/CardAudioPlayer.tsx +200 -0
- package/web/src/components/conversation-review/CardEvaluation.tsx +351 -0
- package/web/src/components/conversation-review/CardMetadata.tsx +44 -0
- package/web/src/components/conversation-review/ConversationCard.tsx +95 -0
- package/web/src/components/conversation-review/ReviewContainer.tsx +120 -0
- package/web/src/components/conversation-review/ReviewFilters.tsx +88 -0
- package/web/src/components/empty-state.tsx +15 -0
- package/web/src/components/page-header.tsx +19 -0
- package/web/src/components/page-loader.tsx +32 -0
- package/web/src/components/pagination.tsx +38 -0
- package/web/src/components/stat-card.tsx +27 -0
- package/web/src/components/status-badge.tsx +125 -0
- package/web/src/components/ui/alert.tsx +66 -0
- package/web/src/components/ui/badge.tsx +48 -0
- package/web/src/components/ui/button.tsx +64 -0
- package/web/src/components/ui/card.tsx +92 -0
- package/web/src/components/ui/checkbox.tsx +32 -0
- package/web/src/components/ui/dialog.tsx +158 -0
- package/web/src/components/ui/dropdown-menu.tsx +255 -0
- package/web/src/components/ui/input.tsx +21 -0
- package/web/src/components/ui/label.tsx +22 -0
- package/web/src/components/ui/progress.tsx +29 -0
- package/web/src/components/ui/select.tsx +188 -0
- package/web/src/components/ui/separator.tsx +28 -0
- package/web/src/components/ui/sheet.tsx +123 -0
- package/web/src/components/ui/skeleton.tsx +13 -0
- package/web/src/components/ui/sonner.tsx +35 -0
- package/web/src/components/ui/table.tsx +116 -0
- package/web/src/components/ui/tabs.tsx +89 -0
- package/web/src/components/ui/textarea.tsx +18 -0
- package/web/src/components/ui/tooltip.tsx +57 -0
- package/web/src/components/whatsapp/ChatDetail.tsx +417 -0
- package/web/src/components/whatsapp/ChatHeader.tsx +78 -0
- package/web/src/components/whatsapp/ChatList.tsx +107 -0
- package/web/src/components/whatsapp/ChatListItem.tsx +60 -0
- package/web/src/components/whatsapp/MessageBubble.tsx +46 -0
- package/web/src/components/whatsapp/MessageInput.tsx +63 -0
- package/web/src/components/whatsapp/MessageStream.tsx +135 -0
- package/web/src/components/whatsapp/SessionDivider.tsx +65 -0
- package/web/src/components/whatsapp/SessionHistory.tsx +119 -0
- package/web/src/components/whatsapp/settings/AiSettingsTab.tsx +268 -0
- package/web/src/components/whatsapp/settings/CalendarTab.tsx +339 -0
- package/web/src/components/whatsapp/settings/ConnectionTab.tsx +236 -0
- package/web/src/components/whatsapp/settings/NotificationsTab.tsx +109 -0
- package/web/src/components/whatsapp/settings/OperatorTab.tsx +303 -0
- package/web/src/contexts/AuthContext.tsx +103 -0
- package/web/src/index.css +130 -0
- package/web/src/lib/api.ts +92 -0
- package/web/src/lib/utils.ts +6 -0
- package/web/src/main.tsx +10 -0
- package/web/src/pages/AppointmentDetail.tsx +206 -0
- package/web/src/pages/AppointmentValidation.tsx +157 -0
- package/web/src/pages/AppointmentValidationDetail.tsx +617 -0
- package/web/src/pages/AppointmentValidationNew.tsx +1005 -0
- package/web/src/pages/Appointments.tsx +283 -0
- package/web/src/pages/Billing.tsx +126 -0
- package/web/src/pages/CallDetail.tsx +293 -0
- package/web/src/pages/CallSettings.tsx +313 -0
- package/web/src/pages/Calls.tsx +188 -0
- package/web/src/pages/CampaignDetail.tsx +216 -0
- package/web/src/pages/CampaignNew.tsx +277 -0
- package/web/src/pages/CampaignResults.tsx +185 -0
- package/web/src/pages/Campaigns.tsx +171 -0
- package/web/src/pages/Dashboard.tsx +336 -0
- package/web/src/pages/InboundSchedule.tsx +246 -0
- package/web/src/pages/LeadDetail.tsx +183 -0
- package/web/src/pages/Leads.tsx +258 -0
- package/web/src/pages/Login.tsx +99 -0
- package/web/src/pages/Register.tsx +129 -0
- package/web/src/pages/Settings.tsx +133 -0
- package/web/src/pages/SurveyDetail.tsx +232 -0
- package/web/src/pages/SurveyPreview.tsx +179 -0
- package/web/src/pages/Surveys.tsx +207 -0
- package/web/src/pages/Users.tsx +199 -0
- package/web/src/pages/WhatsApp.tsx +147 -0
- package/web/src/pages/WhatsAppSettings.tsx +215 -0
- package/web/src/pages/admin/AdminBaileysMessageLog.tsx +331 -0
- package/web/src/pages/admin/AdminBaileysRawMessages.tsx +318 -0
- package/web/src/pages/admin/AdminConversationReview.tsx +116 -0
- package/web/src/pages/admin/AdminCredits.tsx +467 -0
- package/web/src/pages/admin/AdminElevenLabsAgentDetail.tsx +332 -0
- package/web/src/pages/admin/AdminElevenLabsAgents.tsx +164 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCallDetail.tsx +214 -0
- package/web/src/pages/admin/AdminElevenLabsBatchCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsConversationDetail.tsx +230 -0
- package/web/src/pages/admin/AdminElevenLabsConversations.tsx +228 -0
- package/web/src/pages/admin/AdminElevenLabsInboundCalls.tsx +293 -0
- package/web/src/pages/admin/AdminElevenLabsPhoneNumbers.tsx +506 -0
- package/web/src/pages/admin/AdminElevenLabsTestChat.tsx +258 -0
- package/web/src/pages/admin/AdminElevenLabsWebhooks.tsx +289 -0
- package/web/src/pages/admin/AdminEvaluationDashboard.tsx +520 -0
- package/web/src/pages/admin/AdminLeads.tsx +339 -0
- package/web/src/pages/admin/AdminLogs.tsx +283 -0
- package/web/src/pages/admin/AdminMigrations.tsx +247 -0
- package/web/src/pages/admin/AdminPlans.tsx +313 -0
- package/web/src/pages/admin/AdminSystem.tsx +391 -0
- package/web/src/pages/admin/AdminTenantBillableItems.tsx +464 -0
- package/web/src/pages/admin/AdminTenantDetail.tsx +1317 -0
- package/web/src/pages/admin/AdminTenants.tsx +274 -0
- package/web/src/pages/admin/AdminWhatsApp.tsx +618 -0
- package/web/src/pages/admin/AdminWhatsAppTestChat.tsx +328 -0
- package/web/src/types/index.ts +242 -0
- package/web/tsconfig.app.json +32 -0
- package/web/tsconfig.json +13 -0
- package/web/tsconfig.node.json +26 -0
- package/web/vite.config.ts +23 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# API Endpoints Reference
|
|
2
|
+
|
|
3
|
+
> 174 REST endpoints across 25 controllers
|
|
4
|
+
> Base URL: `/api` (frontend proxy) or direct `:3005`
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Auth (`/auth`) — 10 endpoints
|
|
9
|
+
|
|
10
|
+
| Method | Path | Auth | Description |
|
|
11
|
+
|---|---|---|---|
|
|
12
|
+
| POST | `/auth/login` | — | Login with email + password |
|
|
13
|
+
| POST | `/auth/register` | — | Register new tenant with owner account |
|
|
14
|
+
| POST | `/auth/refresh` | — | Refresh access token |
|
|
15
|
+
| POST | `/auth/logout` | JWT | Logout and invalidate session |
|
|
16
|
+
| POST | `/auth/change-password` | JWT | Change password (requires current) |
|
|
17
|
+
| POST | `/auth/forgot-password` | — | Request password reset link |
|
|
18
|
+
| POST | `/auth/reset-password` | — | Reset password with token |
|
|
19
|
+
| GET | `/auth/me` | JWT | Get current user info + permissions |
|
|
20
|
+
| GET | `/auth/me/schedule` | JWT | Get own doctor working hours |
|
|
21
|
+
| PUT | `/auth/me/schedule` | JWT | Update own doctor working hours |
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Patients (`/patients`) — 28 endpoints
|
|
26
|
+
|
|
27
|
+
| Method | Path | Permission | Description |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| GET | `/patients` | `patients:read` | List patients (paginated, search, clinic filter) |
|
|
30
|
+
| GET | `/patients/search` | `patients:read` | Quick search autocomplete |
|
|
31
|
+
| POST | `/patients` | `patients:create` | Create patient |
|
|
32
|
+
| GET | `/patients/:id` | `patients:read` | Get patient detail |
|
|
33
|
+
| PUT | `/patients/:id` | `patients:update` | Update patient |
|
|
34
|
+
| DELETE | `/patients/:id` | `patients:delete` | Soft-delete patient |
|
|
35
|
+
| GET | `/patients/:id/medical-history` | `patients:read` | Get medical history (decrypted) |
|
|
36
|
+
| PUT | `/patients/:id/medical-history` | `patients:update` | Update medical history |
|
|
37
|
+
| GET | `/patients/:id/notes` | `patients:read` | List notes |
|
|
38
|
+
| POST | `/patients/:id/notes` | `patients:update` | Create note |
|
|
39
|
+
| PUT | `/patients/:id/notes/:noteId` | `patients:update` | Update note |
|
|
40
|
+
| DELETE | `/patients/:id/notes/:noteId` | `patients:update` | Delete note |
|
|
41
|
+
| GET | `/patients/:id/documents` | `patients:read` | List documents |
|
|
42
|
+
| POST | `/patients/:id/documents` | `patients:update` | Upload document (base64) |
|
|
43
|
+
| GET | `/patients/:id/documents/:docId` | `patients:read` | Get document with signed URL |
|
|
44
|
+
| GET | `/patients/:id/documents/:docId/file` | `patients:read` | Stream file (proxy, supports `?token=`) |
|
|
45
|
+
| DELETE | `/patients/:id/documents/:docId` | `patients:update` | Delete document |
|
|
46
|
+
| GET | `/patients/:id/photo-sets` | `patients:read` | List photo sets |
|
|
47
|
+
| POST | `/patients/:id/photo-sets` | `patients:update` | Create photo set |
|
|
48
|
+
| GET | `/patients/:id/photo-sets/:setId` | `patients:read` | Get photo set with signed URLs |
|
|
49
|
+
| PUT | `/patients/:id/photo-sets/:setId` | `patients:update` | Update photo set metadata |
|
|
50
|
+
| DELETE | `/patients/:id/photo-sets/:setId` | `patients:update` | Delete photo set + all photos |
|
|
51
|
+
| POST | `/patients/:id/photo-sets/:setId/photos` | `patients:update` | Upload photo (base64, generates thumbnail) |
|
|
52
|
+
| DELETE | `/patients/:id/photo-sets/:setId/photos/:photoId` | `patients:update` | Delete single photo |
|
|
53
|
+
| GET | `/patients/:id/examinations` | `patients:read` | List examinations |
|
|
54
|
+
| POST | `/patients/:id/examinations` | `patients:update` | Create examination (appointment optional) |
|
|
55
|
+
| GET | `/patients/:id/examinations/:examId` | `patients:read` | Get examination (decrypted) |
|
|
56
|
+
| PUT | `/patients/:id/examinations/:examId` | `patients:update` | Update examination |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Appointments (`/appointments`) — 10 endpoints
|
|
61
|
+
|
|
62
|
+
| Method | Path | Permission | Description |
|
|
63
|
+
|---|---|---|---|
|
|
64
|
+
| GET | `/appointments` | `appointments:read` | List (paginated, status/doctor/date filters) |
|
|
65
|
+
| GET | `/appointments/stats` | `appointments:read` | Stats (today, upcoming, by status/source) |
|
|
66
|
+
| GET | `/appointments/availability` | `appointments:read` | Check available slots (`?clinicId&date&doctorId`) |
|
|
67
|
+
| GET | `/appointments/patient/:patientId` | `appointments:read` | Patient's appointments |
|
|
68
|
+
| GET | `/appointments/doctor/:doctorId` | `appointments:read` | Doctor's schedule |
|
|
69
|
+
| POST | `/appointments` | `appointments:manage` | Create appointment |
|
|
70
|
+
| GET | `/appointments/:id` | `appointments:read` | Get detail |
|
|
71
|
+
| PUT | `/appointments/:id` | `appointments:manage` | Update (reschedule, change doctor) |
|
|
72
|
+
| PUT | `/appointments/:id/status` | `appointments:manage` | Update status (confirm/start/complete/cancel/no-show) |
|
|
73
|
+
| DELETE | `/appointments/:id` | `appointments:manage` | Cancel appointment |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Treatments (`/treatments`) — 6 endpoints
|
|
78
|
+
|
|
79
|
+
| Method | Path | Permission | Description |
|
|
80
|
+
|---|---|---|---|
|
|
81
|
+
| GET | `/treatments` | `treatments:read` | List (optional `?clinicId`) |
|
|
82
|
+
| GET | `/treatments/categories` | `treatments:read` | Distinct categories |
|
|
83
|
+
| POST | `/treatments` | `treatments:manage` | Create treatment |
|
|
84
|
+
| GET | `/treatments/:id` | `treatments:read` | Get single |
|
|
85
|
+
| PUT | `/treatments/:id` | `treatments:manage` | Update |
|
|
86
|
+
| DELETE | `/treatments/:id` | `treatments:manage` | Soft-delete |
|
|
87
|
+
|
|
88
|
+
## Treatment Plans (`/treatment-plans`) — 8 endpoints
|
|
89
|
+
|
|
90
|
+
| Method | Path | Permission | Description |
|
|
91
|
+
|---|---|---|---|
|
|
92
|
+
| GET | `/treatment-plans/patient/:patientId` | `patients:read` | List plans for patient |
|
|
93
|
+
| POST | `/treatment-plans/patient/:patientId` | `treatment_plans:manage` | Create plan |
|
|
94
|
+
| GET | `/treatment-plans/:id` | `patients:read` | Get plan with items |
|
|
95
|
+
| PUT | `/treatment-plans/:id` | `treatment_plans:manage` | Update plan |
|
|
96
|
+
| DELETE | `/treatment-plans/:id` | `treatment_plans:manage` | Delete (no completed items) |
|
|
97
|
+
| POST | `/treatment-plans/:id/items` | `treatment_plans:manage` | Add item |
|
|
98
|
+
| PUT | `/treatment-plans/:id/items/:itemId` | `treatment_plans:manage` | Update item status |
|
|
99
|
+
| DELETE | `/treatment-plans/:id/items/:itemId` | `treatment_plans:manage` | Remove item (not completed) |
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## Users (`/users`) — 10 endpoints
|
|
104
|
+
|
|
105
|
+
| Method | Path | Permission | Description |
|
|
106
|
+
|---|---|---|---|
|
|
107
|
+
| GET | `/users` | `users:read` | List users for tenant |
|
|
108
|
+
| GET | `/users/doctors` | `users:read` | List doctors with profiles |
|
|
109
|
+
| GET | `/users/:id` | `users:read` | Get user |
|
|
110
|
+
| POST | `/users/invite` | `users:invite` | Invite new user |
|
|
111
|
+
| PUT | `/users/:id` | `users:update` | Update user (name, role, permissions) |
|
|
112
|
+
| PUT | `/users/:id/clinics` | `users:update` | Update clinic assignments |
|
|
113
|
+
| DELETE | `/users/:id` | `users:delete` | Deactivate user |
|
|
114
|
+
| GET | `/users/:id/doctor-profile` | `users:read` | Get doctor profile |
|
|
115
|
+
| PUT | `/users/:id/doctor-profile` | `users:update` | Upsert doctor profile |
|
|
116
|
+
| GET | `/users/:id/doctor-profile/availability` | `users:read` | Doctor availability for date |
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## Clinics (`/clinics`) — 10 endpoints
|
|
121
|
+
|
|
122
|
+
| Method | Path | Permission | Description |
|
|
123
|
+
|---|---|---|---|
|
|
124
|
+
| GET | `/clinics` | `clinics:read` | List clinics (scoped by user access) |
|
|
125
|
+
| GET | `/clinics/:id` | `clinics:read` | Get clinic + calendar + meta connections |
|
|
126
|
+
| POST | `/clinics` | `clinics:create` | Create clinic |
|
|
127
|
+
| PUT | `/clinics/:id` | `clinics:update` | Update clinic settings |
|
|
128
|
+
| DELETE | `/clinics/:id` | `clinics:delete` | Soft-delete clinic |
|
|
129
|
+
| GET | `/clinics/:id/meta-connections` | `chats:config` | List WhatsApp/Instagram connections |
|
|
130
|
+
| POST | `/clinics/:id/meta-connections` | `chats:config` | Add connection (encrypted token) |
|
|
131
|
+
| GET | `/clinics/:id/meta-connections/:connId` | `chats:config` | Get connection |
|
|
132
|
+
| PUT | `/clinics/:id/meta-connections/:connId` | `chats:config` | Update connection |
|
|
133
|
+
| DELETE | `/clinics/:id/meta-connections/:connId` | `chats:config` | Disconnect |
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## WhatsApp Chats (`/whatsapp`) — 13 endpoints
|
|
138
|
+
|
|
139
|
+
| Method | Path | Permission | Description |
|
|
140
|
+
|---|---|---|---|
|
|
141
|
+
| GET | `/whatsapp/chats` | `chats:read` / `chats:read_own` | List chats (search, assignedTo, status) |
|
|
142
|
+
| GET | `/whatsapp/chats/:id` | `chats:read` | Get chat detail |
|
|
143
|
+
| GET | `/whatsapp/chats/:id/messages` | `chats:read` | Get messages (decrypted, paginated) |
|
|
144
|
+
| POST | `/whatsapp/chats/:id/takeover` | `chats:takeover` | Human takes over from AI |
|
|
145
|
+
| POST | `/whatsapp/chats/:id/messages` | `chats:send` | Send human message |
|
|
146
|
+
| POST | `/whatsapp/chats/:id/release` | `chats:takeover` | Release back to AI |
|
|
147
|
+
| POST | `/whatsapp/chats/:id/resolve` | `chats:resolve` | Close session |
|
|
148
|
+
| POST | `/whatsapp/chats/:id/assign` | `chats:assign` | Assign chat to user |
|
|
149
|
+
| POST | `/whatsapp/chats/:id/unassign` | `chats:assign` | Remove assignment |
|
|
150
|
+
| GET | `/whatsapp/stats` | `chats:read` | Chat/session statistics |
|
|
151
|
+
| GET | `/whatsapp/blacklist` | `chats:config` | Get blacklisted numbers |
|
|
152
|
+
| POST | `/whatsapp/blacklist` | `chats:config` | Add to blacklist |
|
|
153
|
+
| DELETE | `/whatsapp/blacklist/:phone` | `chats:config` | Remove from blacklist |
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## Availability Blocks (`/availability-blocks`) — 3 endpoints
|
|
158
|
+
|
|
159
|
+
| Method | Path | Permission | Description |
|
|
160
|
+
|---|---|---|---|
|
|
161
|
+
| GET | `/availability-blocks` | `appointments:read` | List blocks (`?clinicId&doctorId&from&to`) |
|
|
162
|
+
| POST | `/availability-blocks` | `appointments:manage` | Create block (holiday/leave/break) |
|
|
163
|
+
| DELETE | `/availability-blocks/:id` | `appointments:manage` | Delete block |
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Google Calendar (`/google-calendar`) — 5 endpoints
|
|
168
|
+
|
|
169
|
+
| Method | Path | Permission | Description |
|
|
170
|
+
|---|---|---|---|
|
|
171
|
+
| GET | `/google-calendar/auth-url` | `calendar:manage` | Get OAuth authorization URL |
|
|
172
|
+
| GET | `/google-calendar/callback` | — | OAuth callback (browser redirect) |
|
|
173
|
+
| POST | `/google-calendar/disconnect` | `calendar:manage` | Disconnect Google Calendar |
|
|
174
|
+
| GET | `/google-calendar/calendars` | `calendar:read` | List available calendars |
|
|
175
|
+
| PUT | `/google-calendar/calendar` | `calendar:manage` | Select calendar to use |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Leads (`/leads`) — 5 endpoints
|
|
180
|
+
|
|
181
|
+
| Method | Path | Permission | Description |
|
|
182
|
+
|---|---|---|---|
|
|
183
|
+
| GET | `/leads` | `leads:read` | List leads (paginated, filterable) |
|
|
184
|
+
| GET | `/leads/today` | `leads:read` | Last 24h leads |
|
|
185
|
+
| GET | `/leads/export` | `leads:export` | Export CSV |
|
|
186
|
+
| GET | `/leads/:id` | `leads:read` | Get lead detail |
|
|
187
|
+
| PATCH | `/leads/:id` | `leads:update` | Update lead status |
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Calls (`/calls`) — 3 endpoints
|
|
192
|
+
|
|
193
|
+
| Method | Path | Permission | Description |
|
|
194
|
+
|---|---|---|---|
|
|
195
|
+
| GET | `/calls` | `calls:read` | List calls (paginated, filterable) |
|
|
196
|
+
| GET | `/calls/stats` | `calls:read` | Call statistics |
|
|
197
|
+
| GET | `/calls/:id` | `calls:read` | Call detail (transcript, summary) |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## Billing (`/billing`) — 5 endpoints
|
|
202
|
+
|
|
203
|
+
| Method | Path | Permission | Description |
|
|
204
|
+
|---|---|---|---|
|
|
205
|
+
| GET | `/billing/usage` | `billing:read` | Current period usage vs quotas |
|
|
206
|
+
| GET | `/billing/daily-trend` | `billing:read` | Daily trend (last N days) |
|
|
207
|
+
| GET | `/billing/snapshots` | `billing:read` | Past period snapshots |
|
|
208
|
+
| GET | `/billing/history` | `billing:read` | Billing events (paginated) |
|
|
209
|
+
| POST | `/billing/payments` | `billing:manage` | Record payment |
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Agents (`/agents`) — 5 endpoints
|
|
214
|
+
|
|
215
|
+
| Method | Path | Permission | Description |
|
|
216
|
+
|---|---|---|---|
|
|
217
|
+
| GET | `/agents` | `agents:read` | List agents |
|
|
218
|
+
| GET | `/agents/:id` | `agents:read` | Get agent |
|
|
219
|
+
| POST | `/agents` | `agents:manage` | Create agent |
|
|
220
|
+
| PUT | `/agents/:id` | `agents:manage` | Update agent |
|
|
221
|
+
| POST | `/agents/:id/toggle` | `agents:manage` | Toggle active |
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Phone Numbers (`/phone-numbers`) — 6 endpoints
|
|
226
|
+
|
|
227
|
+
| Method | Path | Permission | Description |
|
|
228
|
+
|---|---|---|---|
|
|
229
|
+
| GET | `/phone-numbers` | `phone_numbers:read` | List phone numbers |
|
|
230
|
+
| GET | `/phone-numbers/:id` | `phone_numbers:read` | Get phone number |
|
|
231
|
+
| POST | `/phone-numbers` | `phone_numbers:manage` | Create |
|
|
232
|
+
| PUT | `/phone-numbers/:id` | `phone_numbers:manage` | Update |
|
|
233
|
+
| PUT | `/phone-numbers/:id/schedule` | `phone_numbers:manage` | Update inbound schedule |
|
|
234
|
+
| DELETE | `/phone-numbers/:id` | `phone_numbers:manage` | Delete |
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Outbound Campaigns (`/outbound-campaigns`) — 14 endpoints
|
|
239
|
+
|
|
240
|
+
| Method | Path | Permission | Description |
|
|
241
|
+
|---|---|---|---|
|
|
242
|
+
| GET | `/outbound-campaigns` | `campaigns:read` | List campaigns |
|
|
243
|
+
| GET | `/outbound-campaigns/:id` | `campaigns:read` | Get campaign detail |
|
|
244
|
+
| POST | `/outbound-campaigns` | `campaigns:manage` | Create campaign |
|
|
245
|
+
| PUT | `/outbound-campaigns/:id` | `campaigns:manage` | Update (draft only) |
|
|
246
|
+
| DELETE | `/outbound-campaigns/:id` | `campaigns:manage` | Delete (draft only) |
|
|
247
|
+
| POST | `/outbound-campaigns/:id/entries` | `campaigns:manage` | Upload entries |
|
|
248
|
+
| DELETE | `/outbound-campaigns/:id/entries` | `campaigns:manage` | Clear entries (draft only) |
|
|
249
|
+
| POST | `/outbound-campaigns/:id/start` | `campaigns:manage` | Start campaign |
|
|
250
|
+
| POST | `/outbound-campaigns/:id/pause` | `campaigns:manage` | Pause |
|
|
251
|
+
| POST | `/outbound-campaigns/:id/resume` | `campaigns:manage` | Resume |
|
|
252
|
+
| POST | `/outbound-campaigns/:id/stop` | `campaigns:manage` | Stop |
|
|
253
|
+
| POST | `/outbound-campaigns/:id/retry` | `campaigns:manage` | Retry failed entries |
|
|
254
|
+
| GET | `/outbound-campaigns/:id/results` | `campaigns:read` | Get results |
|
|
255
|
+
| GET | `/outbound-campaigns/:id/export` | `campaigns:export` | Export results |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Appointment Validation (`/appointment-validation`) — 8 endpoints
|
|
260
|
+
|
|
261
|
+
| Method | Path | Permission | Description |
|
|
262
|
+
|---|---|---|---|
|
|
263
|
+
| GET | `/appointment-validation` | `validation:read` | List batches |
|
|
264
|
+
| GET | `/appointment-validation/:id` | `validation:read` | Get batch with entries |
|
|
265
|
+
| POST | `/appointment-validation` | `validation:manage` | Create batch |
|
|
266
|
+
| POST | `/appointment-validation/:id/submit` | `validation:manage` | Submit for processing |
|
|
267
|
+
| POST | `/appointment-validation/:id/cancel` | `validation:manage` | Cancel batch |
|
|
268
|
+
| POST | `/appointment-validation/:id/retry` | `validation:manage` | Retry failed entries |
|
|
269
|
+
| POST | `/appointment-validation/:id/entries/:entryId/retry` | `validation:manage` | Retry single entry |
|
|
270
|
+
| GET | `/appointment-validation/:id/export` | `validation:export` | Export results |
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Plans (`/plans`) — 4 endpoints
|
|
275
|
+
|
|
276
|
+
| Method | Path | Permission | Description |
|
|
277
|
+
|---|---|---|---|
|
|
278
|
+
| GET | `/plans` | — | List active plans |
|
|
279
|
+
| GET | `/plans/:id` | — | Get plan |
|
|
280
|
+
| POST | `/plans` | `platform:plans.manage` | Create plan (superadmin) |
|
|
281
|
+
| PUT | `/plans/:id` | `platform:plans.manage` | Update plan (superadmin) |
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Tenants (`/tenants`) — 2 endpoints
|
|
286
|
+
|
|
287
|
+
| Method | Path | Permission | Description |
|
|
288
|
+
|---|---|---|---|
|
|
289
|
+
| GET | `/tenants/me` | — | Get current tenant |
|
|
290
|
+
| PUT | `/tenants/me` | `tenant:update` | Update current tenant |
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Platform (`/platform`) — 6 endpoints (superadmin)
|
|
295
|
+
|
|
296
|
+
| Method | Path | Permission | Description |
|
|
297
|
+
|---|---|---|---|
|
|
298
|
+
| GET | `/platform/tenants` | `platform:tenants.list` | List all tenants |
|
|
299
|
+
| POST | `/platform/tenants` | `platform:tenants.create` | Create tenant + owner |
|
|
300
|
+
| GET | `/platform/tenants/:id` | `platform:tenants.read` | Get tenant overview |
|
|
301
|
+
| PUT | `/platform/tenants/:id` | `platform:tenants.update` | Update limits/features/plan |
|
|
302
|
+
| PUT | `/platform/tenants/:id/deactivate` | `platform:tenants.update` | Deactivate tenant |
|
|
303
|
+
| PUT | `/platform/tenants/:id/reactivate` | `platform:tenants.update` | Reactivate tenant |
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Admin (`/admin`) — 2 endpoints
|
|
308
|
+
|
|
309
|
+
| Method | Path | Permission | Description |
|
|
310
|
+
|---|---|---|---|
|
|
311
|
+
| GET | `/admin/system/health` | `platform:plans.manage` | System health (DB + Redis) |
|
|
312
|
+
| GET | `/admin/system/usage` | `platform:plans.manage` | Global usage stats |
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Audit (`/audit-logs`) — 3 endpoints
|
|
317
|
+
|
|
318
|
+
| Method | Path | Permission | Description |
|
|
319
|
+
|---|---|---|---|
|
|
320
|
+
| GET | `/audit-logs` | `audit:read` | List audit logs (paginated) |
|
|
321
|
+
| GET | `/audit-logs/entity/:entity/:entityId` | `audit:read` | Audit history for entity |
|
|
322
|
+
| GET | `/audit-logs/user/:userId` | `audit:read` | Audit logs for user |
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## Logs (`/admin/logs`) — 4 endpoints
|
|
327
|
+
|
|
328
|
+
| Method | Path | Permission | Description |
|
|
329
|
+
|---|---|---|---|
|
|
330
|
+
| GET | `/admin/logs` | `audit:read` | List logs (paginated, filterable) |
|
|
331
|
+
| GET | `/admin/logs/stats` | `audit:read` | Log count by level |
|
|
332
|
+
| DELETE | `/admin/logs` | superadmin | Delete old logs |
|
|
333
|
+
| GET | `/admin/logs/request/:requestId` | `audit:read` | Logs for a request |
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Webhooks (unauthenticated)
|
|
338
|
+
|
|
339
|
+
| Method | Path | Auth | Description |
|
|
340
|
+
|---|---|---|---|
|
|
341
|
+
| GET | `/webhooks/meta` | Verify token | Meta webhook verification |
|
|
342
|
+
| POST | `/webhooks/meta` | Signature | Incoming WhatsApp/Instagram messages |
|
|
343
|
+
| POST | `/webhooks/elevenlabs` | API key | ElevenLabs post-call webhook |
|
|
344
|
+
| POST | `/webhooks/elevenlabs/tools/:toolName` | API key | ElevenLabs tool call during voice |
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
# Portal Asistan 7/24 — Architecture & Codebase Reference
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Multi-tenant clinic management SaaS with integrated AI assistant. Built with NestJS + React.
|
|
6
|
+
|
|
7
|
+
| Layer | Stack |
|
|
8
|
+
|---|---|
|
|
9
|
+
| **Backend** | NestJS 11 + Fastify + PostgreSQL + Prisma 7 + Redis + BullMQ |
|
|
10
|
+
| **Frontend** | React 19 + Vite 8 + TypeScript + Tailwind v4 + shadcn/ui (Base UI) |
|
|
11
|
+
| **Storage** | MinIO (S3-compatible) for files, thumbnails |
|
|
12
|
+
| **Real-time** | Socket.IO gateway |
|
|
13
|
+
| **Deployment** | Docker Compose (postgres, redis, minio, backend, nginx) |
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Backend — NestJS (`nestjs/`)
|
|
18
|
+
|
|
19
|
+
### Stats
|
|
20
|
+
|
|
21
|
+
| Metric | Count |
|
|
22
|
+
|---|---|
|
|
23
|
+
| Modules | 37 |
|
|
24
|
+
| Controllers | 25 |
|
|
25
|
+
| Services | 45 |
|
|
26
|
+
| DTOs | 55 |
|
|
27
|
+
| REST Endpoints | 174 |
|
|
28
|
+
| Prisma Models | 45 |
|
|
29
|
+
| Prisma Enums | 32 |
|
|
30
|
+
|
|
31
|
+
### Module Map
|
|
32
|
+
|
|
33
|
+
**Infrastructure**
|
|
34
|
+
- `ConfigModule` — env vars
|
|
35
|
+
- `DatabaseModule` — Prisma + PostgreSQL (PrismaPg adapter)
|
|
36
|
+
- `RedisModule` — ioredis
|
|
37
|
+
- `QueueModule` — BullMQ job processor
|
|
38
|
+
- `EncryptionModule` — AES-256-GCM (5 keys for different data types)
|
|
39
|
+
- `ImageModule` — sharp thumbnail generation
|
|
40
|
+
|
|
41
|
+
**Auth & Identity**
|
|
42
|
+
- `AuthModule` — JWT (opaque tokens in Redis), login/refresh/me/schedule
|
|
43
|
+
- `TenantsModule` — multi-tenant isolation
|
|
44
|
+
- `UsersModule` — CRUD, roles, doctor profiles, clinic assignments
|
|
45
|
+
|
|
46
|
+
**Clinic Management**
|
|
47
|
+
- `ClinicsModule` — clinic CRUD, meta connections, calendar connections
|
|
48
|
+
- `PatientsModule` — 6 sub-services (medical history, notes, documents, photos, examinations)
|
|
49
|
+
- `TreatmentsModule` — catalog + treatment plans with items
|
|
50
|
+
- `AppointmentsModule` — scheduling, availability, reminders
|
|
51
|
+
- `AvailabilityBlocksModule` — holidays, leaves, breaks (clinic + doctor)
|
|
52
|
+
|
|
53
|
+
**Communication**
|
|
54
|
+
- `WhatsAppModule` — chat management, session lifecycle, human takeover, assignment
|
|
55
|
+
- `CallsModule` — voice call records
|
|
56
|
+
- `LeadsModule` — lead pipeline
|
|
57
|
+
- `AgentsModule` — AI agent configuration
|
|
58
|
+
- `PhoneNumbersModule` — phone provisioning
|
|
59
|
+
- `GoogleCalendarModule` — OAuth2 + FreeBusy API
|
|
60
|
+
- `OutboundCampaignsModule` — batch outbound calling
|
|
61
|
+
|
|
62
|
+
**Business**
|
|
63
|
+
- `BillingModule` — usage events, payments, period snapshots
|
|
64
|
+
- `PlansModule` — subscription plans with quotas
|
|
65
|
+
- `AppointmentValidationModule` — batch confirmation calls
|
|
66
|
+
|
|
67
|
+
**Platform (superadmin)**
|
|
68
|
+
- `PlatformModule` — tenant CRUD, resource limits
|
|
69
|
+
- `AdminModule` — system health, global usage stats
|
|
70
|
+
|
|
71
|
+
### Request Pipeline
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
Fastify → Helmet → CORS → ValidationPipe → RequestContextInterceptor
|
|
75
|
+
→ JwtAuthGuard → ClinicAccessGuard → PermissionsGuard → FeaturesGuard
|
|
76
|
+
→ ThrottlerGuard (200/60s) → Controller → Service → Prisma/Redis/MinIO
|
|
77
|
+
→ Socket.IO broadcast → Response
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Authentication Flow
|
|
81
|
+
|
|
82
|
+
1. `POST /auth/login` → validates credentials → issues opaque access + refresh tokens
|
|
83
|
+
2. Opaque token stored in Redis mapping to server-side JWT (client never sees JWT)
|
|
84
|
+
3. `JwtAuthGuard` extracts token from `Authorization: Bearer` header or `?token=` query param
|
|
85
|
+
4. Permissions computed: `customPermissions.length > 0 ? customPermissions : roleDefaults`
|
|
86
|
+
5. Superadmin bypasses all permission checks
|
|
87
|
+
|
|
88
|
+
### Roles & Permissions
|
|
89
|
+
|
|
90
|
+
| Role | Key Permissions |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `superadmin` | Bypasses all checks, platform management |
|
|
93
|
+
| `owner` | Full CRM + settings + billing + audit |
|
|
94
|
+
| `admin` | Full CRM + settings (no billing:manage) |
|
|
95
|
+
| `doctor` | Patients, appointments, treatments, users:read |
|
|
96
|
+
| `receptionist` | Patients, appointments, chats, leads, payments |
|
|
97
|
+
| `sales` | chats:read_own, leads, patients:read/create |
|
|
98
|
+
|
|
99
|
+
Custom per-user permissions override role defaults entirely when set.
|
|
100
|
+
|
|
101
|
+
### Data Encryption
|
|
102
|
+
|
|
103
|
+
5 separate AES-256-GCM keys (env vars):
|
|
104
|
+
- `GOOGLE_TOKEN_ENCRYPTION_KEY` — Google OAuth refresh tokens
|
|
105
|
+
- `META_TOKEN_ENCRYPTION_KEY` — Meta API access tokens
|
|
106
|
+
- `MESSAGE_ENCRYPTION_KEY` — WhatsApp/chat messages
|
|
107
|
+
- `PATIENT_PII_ENCRYPTION_KEY` — patient data, medical history, exam notes
|
|
108
|
+
- `PATIENT_SUMMARY_ENCRYPTION_KEY` — AI-generated summaries
|
|
109
|
+
|
|
110
|
+
### Key Database Models
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
Tenant → Clinic → Patient → Appointment
|
|
114
|
+
→ TreatmentPlan → TreatmentPlanItem
|
|
115
|
+
→ PatientDocument
|
|
116
|
+
→ PatientPhotoSet → PatientPhoto
|
|
117
|
+
→ ExaminationRecord
|
|
118
|
+
→ PatientMedicalHistory
|
|
119
|
+
→ PatientNote
|
|
120
|
+
|
|
121
|
+
Clinic → ClinicCalendarConnection (working hours, Google Calendar)
|
|
122
|
+
→ ClinicMetaConnection (WhatsApp/Instagram tokens)
|
|
123
|
+
|
|
124
|
+
User → DoctorProfile (working hours, breaks, duration, holidays)
|
|
125
|
+
→ UserClinicAssignment
|
|
126
|
+
|
|
127
|
+
WhatsappChat → WhatsappSession → WhatsappMessage
|
|
128
|
+
→ chat_assigned_to (User)
|
|
129
|
+
|
|
130
|
+
AvailabilityBlock (clinic-wide or doctor-specific holidays/leaves/breaks)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Frontend — React (`frontend/`)
|
|
136
|
+
|
|
137
|
+
### Stats
|
|
138
|
+
|
|
139
|
+
| Metric | Count |
|
|
140
|
+
|---|---|
|
|
141
|
+
| Pages | 34 files across 21 directories |
|
|
142
|
+
| Hooks | 12 custom hooks |
|
|
143
|
+
| Components | 50 (33 shadcn + 17 shared) |
|
|
144
|
+
| Routes | 26 |
|
|
145
|
+
| i18n Keys | ~630 (Turkish + English) |
|
|
146
|
+
|
|
147
|
+
### Tech Stack
|
|
148
|
+
|
|
149
|
+
| Library | Version | Purpose |
|
|
150
|
+
|---|---|---|
|
|
151
|
+
| React | 19.2 | UI framework |
|
|
152
|
+
| Vite | 8.0 | Build tool |
|
|
153
|
+
| TanStack Query | 5.96 | Server state + caching |
|
|
154
|
+
| Zustand | 5.0 | Client state (auth, UI) |
|
|
155
|
+
| React Hook Form + Zod | 7.72 / 4.3 | Forms + validation |
|
|
156
|
+
| Tailwind CSS | 4.2 | Styling |
|
|
157
|
+
| shadcn/ui (Base UI) | latest | Component library |
|
|
158
|
+
| Schedule-X | 4.3 | Calendar (week/day/month views) |
|
|
159
|
+
| date-fns + TZDate | 4.1 | Date formatting with timezone |
|
|
160
|
+
| i18next | 26.0 | Turkish + English |
|
|
161
|
+
| Axios | 1.14 | HTTP client with interceptors |
|
|
162
|
+
| Sonner | 2.0 | Toast notifications |
|
|
163
|
+
|
|
164
|
+
### Route Map
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
/ ......................... Dashboard
|
|
168
|
+
/login .................... Login page
|
|
169
|
+
/patients ................. Patient list
|
|
170
|
+
/patients/:id ............. Patient detail (8 tabs)
|
|
171
|
+
/appointments ............. Appointment list + calendar toggle
|
|
172
|
+
/calendar ................. Full-screen Schedule-X calendar
|
|
173
|
+
/treatments ............... Treatment catalog
|
|
174
|
+
/chats .................... WhatsApp inbox (sidebar + messages)
|
|
175
|
+
/calls .................... Call history
|
|
176
|
+
/leads .................... Lead pipeline
|
|
177
|
+
/campaigns ................ Outbound campaigns
|
|
178
|
+
/validation ............... Appointment validation batches
|
|
179
|
+
/billing .................. Usage & payments
|
|
180
|
+
/users .................... User list
|
|
181
|
+
/users/:id/edit ........... User edit + permissions grid
|
|
182
|
+
/users/:id/profile ........ Doctor profile (admin manages)
|
|
183
|
+
/my-schedule .............. Doctor self-service schedule
|
|
184
|
+
/clinics .................. Clinic list
|
|
185
|
+
/clinics/:id/settings ..... Clinic settings + meta connections
|
|
186
|
+
/agents ................... AI agent config
|
|
187
|
+
/phone-numbers ............ Phone management
|
|
188
|
+
/settings ................. General settings
|
|
189
|
+
/audit .................... Audit trail
|
|
190
|
+
/logs ..................... System logs
|
|
191
|
+
/platform ................. Superadmin tenant management
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Custom Hooks
|
|
195
|
+
|
|
196
|
+
| Hook | Endpoints Used |
|
|
197
|
+
|---|---|
|
|
198
|
+
| `use-patients` | patients CRUD, notes, documents, appointments |
|
|
199
|
+
| `use-appointments` | appointments CRUD, stats, availability |
|
|
200
|
+
| `use-treatments` | treatments CRUD, categories |
|
|
201
|
+
| `use-treatment-plans` | plans + items CRUD |
|
|
202
|
+
| `use-users` | users CRUD, doctor profiles, clinic assignments |
|
|
203
|
+
| `use-clinics` | clinic list, timezone helper |
|
|
204
|
+
| `use-clinic-detail` | clinic settings, meta connections, Google Calendar |
|
|
205
|
+
| `use-chats` | chat list, messages, takeover, assign |
|
|
206
|
+
| `use-examinations` | examination CRUD |
|
|
207
|
+
| `use-medical-history` | medical history read/update |
|
|
208
|
+
| `use-photo-sets` | photo set + photo CRUD |
|
|
209
|
+
| `use-availability-blocks` | holiday/leave/break CRUD |
|
|
210
|
+
|
|
211
|
+
### State Management
|
|
212
|
+
|
|
213
|
+
- **Auth store** (`stores/auth.store.ts`) — user, tenant, permissions, login/logout/fetchMe
|
|
214
|
+
- **UI store** (`stores/ui.store.ts`) — sidebar state, dark mode, language
|
|
215
|
+
|
|
216
|
+
### Permission-Based UI
|
|
217
|
+
|
|
218
|
+
- Sidebar items filtered by `user.permissions` at render time
|
|
219
|
+
- `useHasPermission()` / `useHasRole()` hooks for component-level checks
|
|
220
|
+
- Doctor role: auto-filtered to own data (calendar, appointments, schedule)
|
|
221
|
+
- Sales role: only sees assigned chats (`chats:read_own`)
|
|
222
|
+
- Superadmin: sees everything + Platform page
|
|
223
|
+
|
|
224
|
+
### Timezone Handling
|
|
225
|
+
|
|
226
|
+
- `useClinicTimezone()` hook reads from clinic settings (`clinic_timezone`)
|
|
227
|
+
- Falls back to `Europe/Istanbul`
|
|
228
|
+
- All date displays use `TZDate` from `@date-fns/tz`
|
|
229
|
+
- Calendar component receives timezone prop
|
|
230
|
+
- Backend stores UTC, frontend converts for display
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Deployment
|
|
235
|
+
|
|
236
|
+
### Docker Compose (`docker-compose.nestjs.yml`)
|
|
237
|
+
|
|
238
|
+
```
|
|
239
|
+
┌─────────────────────────────────────────────┐
|
|
240
|
+
│ External nginx (SSL) → 127.0.0.1:3021 │
|
|
241
|
+
│ │
|
|
242
|
+
│ ┌─────────────────────────────────────────┐ │
|
|
243
|
+
│ │ frontend (nginx:alpine) :80 │ │
|
|
244
|
+
│ │ /api/* → proxy to backend:3005 │ │
|
|
245
|
+
│ │ /* → SPA (index.html) │ │
|
|
246
|
+
│ └────────────────┬────────────────────────┘ │
|
|
247
|
+
│ │ │
|
|
248
|
+
│ ┌────────────────▼────────────────────────┐ │
|
|
249
|
+
│ │ backend (node:22-alpine) :3005 │ │
|
|
250
|
+
│ │ NestJS + Fastify │ │
|
|
251
|
+
│ └──┬──────────┬──────────┬───────────────┘ │
|
|
252
|
+
│ │ │ │ │
|
|
253
|
+
│ ┌──▼──┐ ┌───▼───┐ ┌──▼───┐ │
|
|
254
|
+
│ │ pg │ │ redis │ │ minio│ │
|
|
255
|
+
│ │:5432│ │ :6379 │ │:9000 │ │
|
|
256
|
+
│ └─────┘ └───────┘ └──────┘ │
|
|
257
|
+
│ (all internal — no ports exposed to host) │
|
|
258
|
+
└─────────────────────────────────────────────┘
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Only `127.0.0.1:3021` exposed. External nginx handles SSL termination.
|
|
262
|
+
|
|
263
|
+
### Commands (`cd nestjs/`)
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
npm run docker:up # Build and start everything
|
|
267
|
+
npm run docker:down # Stop all services
|
|
268
|
+
npm run docker:logs # Follow backend logs
|
|
269
|
+
npm run docker:seed # Seed database
|
|
270
|
+
npm run docker:reset # Wipe + re-seed database
|
|
271
|
+
npm run docker:restart # Restart backend only
|
|
272
|
+
npm run docker:rebuild # Rebuild backend + frontend
|
|
273
|
+
npm run docker:ps # Show container status
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Environment
|
|
277
|
+
|
|
278
|
+
Backend reads from `nestjs/.env.docker`:
|
|
279
|
+
- `FRONTEND_URL` — must match actual domain for CORS
|
|
280
|
+
- `DATABASE_URL` — postgres internal hostname
|
|
281
|
+
- `REDIS_URL` — redis internal hostname
|
|
282
|
+
- `MINIO_ENDPOINT` — minio internal hostname
|
|
283
|
+
- 5 encryption keys (generate with `openssl rand -hex 32`)
|
|
284
|
+
- JWT secrets (generate with `openssl rand -hex 64`)
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Seed Data
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
npm run docker:seed
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
Creates 6 users across all roles:
|
|
295
|
+
|
|
296
|
+
| Role | Email | Password |
|
|
297
|
+
|---|---|---|
|
|
298
|
+
| Superadmin | superadmin@portal.dev | superadmin123 |
|
|
299
|
+
| Owner | admin@demo.com | demo123 |
|
|
300
|
+
| Doctor 1 | mehmet@demo.com | doctor123 |
|
|
301
|
+
| Doctor 2 | ayse@demo.com | doctor123 |
|
|
302
|
+
| Receptionist | resepsiyon@demo.com | staff123 |
|
|
303
|
+
| Sales | satis@demo.com | staff123 |
|
|
304
|
+
|
|
305
|
+
Plus: 1 tenant (limits: 3 clinics, 10 users, 5 doctors, 1000 patients), 1 clinic with working hours + breaks, 5 treatments, 5 patients, 14 appointments.
|