How nemerald-voip/fspbx works
1. This repository is a Laravel-based PBX control plane with a Vue.js/Inertia frontend. It manages telephony configuration, users, devices, calls, voicemail, fax, messaging, provisioning, and operational tooling, while delegating real-time call handling to FreeSWITCH scripts and services.
2. The main runtime boundary is the Laravel application in app/ plus the Vue UI in resources/js/. HTTP requests enter through routes/web.php, routes/api.php, and routes/api_v1.php, then flow into controllers, request validators, services, and Eloquent models. The frontend is a large Inertia/Vue admin console with page components, forms, tables, and modal-driven CRUD workflows.
3. Data access is centered on Eloquent models in app/Models and database migrations in database/migrations. The schema shows a PBX domain model: domains, extensions, devices, ring groups, dialplans, gateways, voicemail, recordings, fax, call blocks, conference rooms, schedules, access control, and multi-tenant permissions. Seeders and observers keep core records consistent as related entities change.
4. The service layer is the real business logic boundary. Classes in app/Services encapsulate device provisioning, dialplan generation, call routing, fax sending, voicemail transcription, messaging delivery, cloud-provider sync, and feature-specific workflows. Controllers are relatively thin and typically orchestrate these services rather than implementing domain logic directly.
5. A substantial part of the system is asynchronous. Jobs in app/Jobs handle outbound side effects and long-running tasks such as voicemail notifications, fax processing, transcription, report exports, TLS renewal, wakeup calls, scheduled announcements, cleanup tasks, and external sync. Laravel Horizon is configured, so queue processing is operationally important, not optional.
6. Telephony integration with FreeSWITCH is a first-class subsystem. resources/freeswitch_scripts/ and resources/lua/ contain the runtime scripts that FreeSWITCH executes for call flows, voicemail, ring groups, call blocking, DID routing, BLF/presence, wakeup calls, fax hangup handling, and XML/directory provisioning. The Laravel app appears to generate configuration and data consumed by these scripts, while scripts call back into app services and webhooks.
7. Provisioning is another major boundary. resources/provisioning/ holds per-vendor templates for phones and related devices, and app/Services/Provisioning plus controllers in the provisioning area generate device configs, phonebooks, and auto-provisioning assets. This is how the app bridges its domain model to endpoint hardware from vendors like Yealink, Poly, Grandstream, Cisco, Snom, Avaya, Fanvil, and others.
8. Messaging/SMS is implemented as a provider abstraction with inbound and outbound paths. Outbound SMS routes through provider-specific classes under app/Services/Messaging/Outbound/Providers, selected by a factory and backed by configuration in config/messaging.php and provider-specific config files. Inbound webhooks are parsed and normalized by provider-specific webhook parsers and jobs under app/Http/Webhooks and app/Services/Messaging/Providers.
9. Fax and voicemail are similarly event-driven. Fax inbox/sent/queue models and controllers are paired with jobs for transmission, queue monitoring, webhook processing, and notification emails. Voicemail has storage, greetings, transcription, escalation, SMS/email delivery, and BLF notification flows, with sound assets and Lua scripts in resources/sounds and resources/freeswitch_scripts/app/voicemail.
10. The app integrates with multiple external services and telecom vendors. Notable integrations include AssemblyAI, OpenAI, Google, Microsoft Azure, IBM Watson for transcription; Mailgun/Postmark for email webhooks and delivery; Stripe/Ceretax for billing or payment-related flows; Ringotel, Sansay, TigerTMS, Polycom, and cloud provisioning providers; plus Slack notifications and S3 for storage/reporting. These integrations are isolated behind services, config files, webhook validators, and dedicated jobs.
11. Authentication and authorization are handled by Laravel Fortify, Sanctum, custom middleware, and permission services. The codebase includes 2FA email challenge support, cookie/bearer token boundaries, session/session invalidation logic, domain-group permissions, and user/domain scoping traits. This matters architecturally because many controllers and services operate within tenant and permission boundaries rather than globally.
12. Real-time or near-real-time operational views are exposed through specialized controllers and Vue pages for active calls, registrations, logs, status dashboards, and queue/agent monitoring. Some of these views are backed by event or broadcast infrastructure (app/Events, app/Listeners, BroadcastServiceProvider, config/reverb.php), suggesting the UI can reflect live PBX state rather than only static configuration.
13. The repository also includes operational tooling and lifecycle scripts. app/Console/Commands contains maintenance, migration, backup, provisioning, update, and diagnostic commands; app/Console/Daemons contains long-running import/services; and the install/ directory holds system bootstrap scripts for Debian, Nginx, PHP, PostgreSQL, Redis, FreeSWITCH, Horizon, Reverb, firewall rules, TLS, and cron jobs. These are part of the deployment architecture, not just developer convenience.
14. The documentation site in documentation/ is a separate Docusaurus-based project that publishes API docs, tutorials, and release notes. It mirrors the product surface area, especially the public API v1 endpoints for devices, domains, extensions, ring groups, voicemails, registrations, active calls, and CDRs, which helps define the external integration boundary of the PBX platform.
Main entry points: Controllers Controllers · Services Services · freeswitch_scripts FreeSWITCH scripts · Jobs Jobs
Components 20
Laravel control plane
HTTP entrypoints, domain services, queue jobs, and persistence for PBX management.
- Routes · Primary web, API, and v1 API route entrypoints.
routes/web.php - Controllers · Thin orchestration layer for admin, API, provisioning, and operational workflows.
app/Http/Controllers - Services · Business logic boundary for routing, provisioning, messaging, fax, voicemail, and integrations.
app/Services - Models · Domain entities for tenants, devices, extensions, calls, voicemail, fax, and settings.
app/Models - Jobs · Queued work for notifications, exports, transcription, sync, cleanup, and telephony side effects.
app/Jobs - Webhooks · Provider webhook profiles, signature validators, and processing jobs.
app/Http/Webhooks - Auth layer · Fortify, Sanctum, middleware, and permission/session services enforcing tenant scope.
app/Services/Auth - Broadcasting · Events, listeners, and broadcast config supporting live operational UI updates.
app/Events - Schema · Database schema for PBX, messaging, provisioning, billing, and operational records.
database/migrations - Fax & voicemail · Fax send/receive, voicemail storage, notifications, BLF, and escalation workflows.
app/Services/FaxSendService.php
FreeSWITCH runtime
Call-flow scripts and XML/Lua handlers executed by FreeSWITCH at runtime.
- FreeSWITCH scripts · Lua and app scripts executed by FreeSWITCH for call handling and XML/directory provisioning.
resources/freeswitch_scripts - Lua flows · Top-level Lua call-flow and telephony helper scripts.
resources/lua - XML handler · FreeSWITCH XML/directory/config generation and lookup scripts.
resources/freeswitch_scripts/app/xml_handler
Vue admin UI
Inertia/Vue screens, forms, tables, and live operational views.
- Admin UI · Vue pages, forms, modals, and dashboards for PBX administration.
resources/js/Pages
Provisioning & providers
Endpoint provisioning, messaging, transcription, and third-party telecom integrations.
- Provisioning · Vendor templates and phonebook assets for endpoint auto-provisioning.
resources/provisioning - Provisioning svc · Provisioning logic, vendor routing, phonebook building, and cloud provisioning support.
app/Services/Provisioning - Messaging · Inbound/outbound SMS abstraction with provider selection, parsing, media ingestion, and retries.
app/Services/Messaging - Transcription · Provider registry and services for voicemail/call transcription across AI vendors.
app/Services/CallTranscription
Operations
Console commands, daemons, and installation scripts for lifecycle management.
- Ops tooling · Maintenance commands, daemons, and system bootstrap scripts for deployment and runtime operations.
app/Console/Commands
Documentation
Separate Docusaurus documentation site and API reference.
- Docs site · Standalone documentation project for tutorials, API reference, and release notes.
documentation/docs/api/v1
Connections 24
- Routes → Controllers: dispatches · HTTP routes hand requests to controller actions.
- Controllers → Services: orchestrates · Controllers delegate PBX logic to service classes.
- Controllers → Models: reads/writes · Controllers persist and retrieve domain records through Eloquent models.
- Services → Models: persists domain · Services implement core state transitions over PBX entities.
- Services → Jobs: queues work · Services enqueue long-running or side-effecting tasks.
- Jobs → Webhooks: emit/consume · Jobs process external webhook events and asynchronous callbacks.
- Auth layer → Controllers: guards · Middleware and permission services protect controller entrypoints.
- Broadcasting → Admin UI: updates UI · Events and listeners support live operational views in the SPA.
- Schema → Models: defines schema · Database migrations shape the domain model stored by Eloquent.
- Admin UI → Controllers: requests · Inertia pages submit CRUD and operational actions back to Laravel.
- Admin UI → Broadcasting: subscribes · Operational pages can reflect near-real-time PBX state.
- Controllers → FreeSWITCH scripts: generates config · Provisioning and telephony controllers prepare assets consumed by FreeSWITCH.
- Services → FreeSWITCH scripts: drives call flow · Core services coordinate call-routing and provisioning data used at runtime.
- FreeSWITCH scripts → Lua flows: executes · FreeSWITCH runs Lua call-flow scripts for PBX behavior.
- FreeSWITCH scripts → XML handler: requests XML · FreeSWITCH pulls directory, dialplan, and configuration XML from handler scripts.
- Provisioning → Provisioning svc: templates · Vendor template assets are rendered by provisioning services.
- Provisioning svc → Controllers: serves device config · Provisioning endpoints expose generated configs and assets.
- Messaging → Jobs: async delivery · Outbound SMS and webhook handling are often executed as queued work.
- Fax & voicemail → Jobs: async notifications · Fax and voicemail workflows rely heavily on queued notifications and processing.
- Transcription → Jobs: async transcribe · Transcription requests and summaries are processed in the background.
- Ops tooling → Services: maintains system · Console commands and daemons invoke services for maintenance and imports.
- Ops tooling → FreeSWITCH scripts: bootstraps · Install scripts provision and configure the FreeSWITCH runtime.
- Docs site → Routes: documents API · Documentation mirrors the public API surface exposed by the Laravel app.
- Docs site → Controllers: explains workflows · Tutorials document the major admin and telephony flows implemented by controllers.