# nemerald-voip/fspbx architecture

> Architecture diagram of the GitHub repository nemerald-voip/fspbx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nemerald-voip/fspbx
- Repository: https://github.com/nemerald-voip/fspbx

## Overview

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: [`app/Http/Controllers`](https://github.com/nemerald-voip/fspbx/tree/main/app/Http/Controllers) (Controllers), [`app/Services`](https://github.com/nemerald-voip/fspbx/tree/main/app/Services) (Services), [`resources/freeswitch_scripts`](https://github.com/nemerald-voip/fspbx/tree/main/resources/freeswitch_scripts) (FreeSWITCH scripts), [`app/Jobs`](https://github.com/nemerald-voip/fspbx/tree/main/app/Jobs) (Jobs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_backend["Laravel control plane"]
  node_routes["Routes<br/>[web.php]"]
  node_controllers["Controllers"]
  node_services["Services"]
  node_models[("Models")]
  node_jobs["Jobs"]
  node_webhooks["Webhooks<br/>Webhook pipeline"]
  node_auth["Auth layer<br/>Auth & permissions"]
  node_broadcast(("Broadcasting<br/>Realtime events"))
  node_migrations["Schema<br/>Migrations"]
  node_fax_voicemail["Fax & voicemail<br/>Event workflows<br/>[FaxSendService.php]"]
end

subgraph group_grp_telephony["FreeSWITCH runtime"]
  node_freeswitch["FreeSWITCH scripts<br/>Runtime scripts"]
  node_lua["Lua flows<br/>Lua call flows"]
  node_xmlhandler["XML handler<br/>FS provisioning"]
end

subgraph group_grp_frontend["Vue admin UI"]
  node_vue["Admin UI<br/>Inertia/Vue SPA"]
end

subgraph group_grp_integration["Provisioning & providers"]
  node_provisioning["Provisioning<br/>Device templates"]
  node_prov_services["Provisioning svc<br/>Provisioning services"]
  node_messaging["Messaging<br/>SMS pipeline"]
  node_transcription["Transcription"]
end

subgraph group_grp_ops["Operations"]
  node_ops["Ops tooling<br/>Console & install"]
end

subgraph group_grp_docs["Documentation"]
  node_docs["Docs site<br/>Docusaurus docs"]
end

node_routes -->|"dispatches"| node_controllers
node_controllers -->|"orchestrates"| node_services
node_controllers -->|"reads/writes"| node_models
node_services -->|"persists domain"| node_models
node_services -->|"queues work"| node_jobs
node_jobs -->|"emit/consume"| node_webhooks
node_auth -->|"guards"| node_controllers
node_broadcast -->|"updates UI"| node_vue
node_migrations -->|"defines schema"| node_models
node_vue -->|"requests"| node_controllers
node_vue -.->|"subscribes"| node_broadcast
node_controllers -->|"generates config"| node_freeswitch
node_services -->|"drives call flow"| node_freeswitch
node_freeswitch -->|"executes"| node_lua
node_freeswitch -->|"requests XML"| node_xmlhandler
node_provisioning -->|"templates"| node_prov_services
node_prov_services -->|"serves device config"| node_controllers
node_messaging -->|"async delivery"| node_jobs
node_fax_voicemail -->|"async notifications"| node_jobs
node_transcription -->|"async transcribe"| node_jobs
node_ops -->|"maintains system"| node_services
node_ops -->|"bootstraps"| node_freeswitch
node_docs -.->|"documents API"| node_routes
node_docs -.->|"explains workflows"| node_controllers

click node_routes "https://github.com/nemerald-voip/fspbx/blob/main/routes/web.php"
click node_controllers "https://github.com/nemerald-voip/fspbx/tree/main/app/Http/Controllers"
click node_services "https://github.com/nemerald-voip/fspbx/tree/main/app/Services"
click node_models "https://github.com/nemerald-voip/fspbx/tree/main/app/Models"
click node_jobs "https://github.com/nemerald-voip/fspbx/tree/main/app/Jobs"
click node_webhooks "https://github.com/nemerald-voip/fspbx/tree/main/app/Http/Webhooks"
click node_auth "https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Auth"
click node_broadcast "https://github.com/nemerald-voip/fspbx/tree/main/app/Events"
click node_migrations "https://github.com/nemerald-voip/fspbx/tree/main/database/migrations"
click node_vue "https://github.com/nemerald-voip/fspbx/tree/main/resources/js/Pages"
click node_freeswitch "https://github.com/nemerald-voip/fspbx/tree/main/resources/freeswitch_scripts"
click node_lua "https://github.com/nemerald-voip/fspbx/tree/main/resources/lua"
click node_xmlhandler "https://github.com/nemerald-voip/fspbx/tree/main/resources/freeswitch_scripts/app/xml_handler"
click node_provisioning "https://github.com/nemerald-voip/fspbx/tree/main/resources/provisioning"
click node_prov_services "https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Provisioning"
click node_messaging "https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Messaging"
click node_transcription "https://github.com/nemerald-voip/fspbx/tree/main/app/Services/CallTranscription"
click node_fax_voicemail "https://github.com/nemerald-voip/fspbx/blob/main/app/Services/FaxSendService.php"
click node_ops "https://github.com/nemerald-voip/fspbx/tree/main/app/Console/Commands"
click node_docs "https://github.com/nemerald-voip/fspbx/tree/main/documentation/docs/api/v1"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_routes,node_controllers,node_services,node_models,node_jobs,node_webhooks,node_auth,node_broadcast,node_migrations,node_fax_voicemail toneBlue
class node_freeswitch,node_lua,node_xmlhandler toneAmber
class node_vue toneMint
class node_provisioning,node_prov_services,node_messaging,node_transcription toneRose
class node_ops toneIndigo
class node_docs toneTeal
```

## Components

### Laravel control plane

HTTP entrypoints, domain services, queue jobs, and persistence for PBX management.

- [Routes](https://github.com/nemerald-voip/fspbx/blob/main/routes/web.php): HTTP routes · Primary web, API, and v1 API route entrypoints. · `routes/web.php`
- [Controllers](https://github.com/nemerald-voip/fspbx/tree/main/app/Http/Controllers): HTTP controllers · Thin orchestration layer for admin, API, provisioning, and operational workflows. · `app/Http/Controllers`
- [Services](https://github.com/nemerald-voip/fspbx/tree/main/app/Services): Domain services · Business logic boundary for routing, provisioning, messaging, fax, voicemail, and integrations. · `app/Services`
- [Models](https://github.com/nemerald-voip/fspbx/tree/main/app/Models): Eloquent models · Domain entities for tenants, devices, extensions, calls, voicemail, fax, and settings. · `app/Models`
- [Jobs](https://github.com/nemerald-voip/fspbx/tree/main/app/Jobs): Async jobs · Queued work for notifications, exports, transcription, sync, cleanup, and telephony side effects. · `app/Jobs`
- [Webhooks](https://github.com/nemerald-voip/fspbx/tree/main/app/Http/Webhooks): Webhook pipeline · Provider webhook profiles, signature validators, and processing jobs. · `app/Http/Webhooks`
- [Auth layer](https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Auth): Auth & permissions · Fortify, Sanctum, middleware, and permission/session services enforcing tenant scope. · `app/Services/Auth`
- [Broadcasting](https://github.com/nemerald-voip/fspbx/tree/main/app/Events): Realtime events · Events, listeners, and broadcast config supporting live operational UI updates. · `app/Events`
- [Schema](https://github.com/nemerald-voip/fspbx/tree/main/database/migrations): Migrations · Database schema for PBX, messaging, provisioning, billing, and operational records. · `database/migrations`
- [Fax & voicemail](https://github.com/nemerald-voip/fspbx/blob/main/app/Services/FaxSendService.php): Event workflows · 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](https://github.com/nemerald-voip/fspbx/tree/main/resources/freeswitch_scripts): Runtime scripts · Lua and app scripts executed by FreeSWITCH for call handling and XML/directory provisioning. · `resources/freeswitch_scripts`
- [Lua flows](https://github.com/nemerald-voip/fspbx/tree/main/resources/lua): Lua call flows · Top-level Lua call-flow and telephony helper scripts. · `resources/lua`
- [XML handler](https://github.com/nemerald-voip/fspbx/tree/main/resources/freeswitch_scripts/app/xml_handler): FS provisioning · 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](https://github.com/nemerald-voip/fspbx/tree/main/resources/js/Pages): Inertia/Vue SPA · Vue pages, forms, modals, and dashboards for PBX administration. · `resources/js/Pages`

### Provisioning & providers

Endpoint provisioning, messaging, transcription, and third-party telecom integrations.

- [Provisioning](https://github.com/nemerald-voip/fspbx/tree/main/resources/provisioning): Device templates · Vendor templates and phonebook assets for endpoint auto-provisioning. · `resources/provisioning`
- [Provisioning svc](https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Provisioning): Provisioning services · Provisioning logic, vendor routing, phonebook building, and cloud provisioning support. · `app/Services/Provisioning`
- [Messaging](https://github.com/nemerald-voip/fspbx/tree/main/app/Services/Messaging): SMS pipeline · Inbound/outbound SMS abstraction with provider selection, parsing, media ingestion, and retries. · `app/Services/Messaging`
- [Transcription](https://github.com/nemerald-voip/fspbx/tree/main/app/Services/CallTranscription): AI 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](https://github.com/nemerald-voip/fspbx/tree/main/app/Console/Commands): Console & install · 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](https://github.com/nemerald-voip/fspbx/tree/main/documentation/docs/api/v1): Docusaurus docs · Standalone documentation project for tutorials, API reference, and release notes. · `documentation/docs/api/v1`

## Connections

- 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.
