# mahirgul/aipbx architecture

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

- Interactive diagram: https://gitdiagram.com/mahirgul/aipbx
- Repository: https://github.com/mahirgul/aipbx

## Overview

AiPBX is an Asterisk-based IP PBX management portal and unified communications platform. The main administrator workflow enters through the PHP portal, dispatches to routed controllers, and manages PBX configuration; the README identifies Asterisk as the telephony system. For AI calls, the local AI HTTP server dispatches call handling and model operations, with separate voice-request and cloud-language-model capabilities. The tree also shows chat, signaling, and network discovery services. Connections below are limited to README statements and source-index references or excerpts; several subsystem internals were not sampled, so their wiring is omitted.

Main entry points: [`ai/aipbx_ai/server.py`](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/server.py) (AI HTTP server), [`web/index.php`](https://github.com/mahirgul/aipbx/blob/main/web/index.php) (Portal entry), [`ai/aipbx_ai/calls.py`](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/calls.py) (Call orchestration), [`chat/main.go`](https://github.com/mahirgul/aipbx/blob/main/chat/main.go) (Chat service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portal["Portal management"]
  node_portal_entry["Portal entry<br/>[index.php]"]
  node_route_table["Route table<br/>[routes.php]"]
  node_controller_base["Controller base<br/>[BaseController.php]"]
  node_plugin_manager["Plugin manager<br/>[PluginManager.php]"]
  node_portal_helpers["Domain helpers<br/>[helpers.php]"]
  node_database[("Portal database")]
end

subgraph group_telephony["PBX telephony"]
  node_destination_registry["Destination registry"]
  node_dialplan_sync["Dialplan sync"]
  node_asterisk["Asterisk PBX"]
end

subgraph group_ai["AI voice services"]
  node_ai_server["AI HTTP server<br/>[server.py]"]
  node_call_handler["Call orchestration<br/>[calls.py]"]
  node_voice_requests["Voice requests<br/>[voice_requests.py]"]
  node_cloud_llm["Cloud language models<br/>[cloud_llm.py]"]
  node_model_manager["Model registry<br/>[models.py]"]
  node_audio_wav["Audio processing<br/>[wav.py]"]
end

subgraph group_comms["Communications services"]
  node_chat_service["Chat service<br/>[main.go]"]
  node_chat_handlers["Chat handlers<br/>[handlers.go]"]
  node_chat_storage["Chat storage<br/>[storage.go]"]
  node_signaling["Signaling service"]
end

subgraph group_network["Network services"]
  node_network_engine["Network discovery"]
end

node_admin(("Administrator"))

node_admin -->|"uses"| node_portal_entry
node_portal_entry -->|"loads routes"| node_route_table
node_route_table -->|"dispatches controllers"| node_controller_base
node_portal_entry -->|"loads plugins"| node_plugin_manager
node_controller_base -->|"uses helpers"| node_portal_helpers
node_portal_helpers -->|"accesses data"| node_database
node_destination_registry -.->|"configures destinations"| node_dialplan_sync
node_dialplan_sync -.->|"updates PBX config"| node_asterisk
node_ai_server -->|"dispatches calls"| node_call_handler
node_ai_server -->|"manages models"| node_model_manager
node_ai_server -->|"handles requests"| node_voice_requests
node_call_handler -->|"uses language model"| node_cloud_llm
node_call_handler -->|"processes audio"| node_audio_wav
node_voice_requests -->|"uses language model"| node_cloud_llm
node_model_manager -.->|"uses audio"| node_audio_wav
node_chat_service -.->|"serves requests"| node_chat_handlers
node_chat_service -.->|"uses storage"| node_chat_storage

click node_portal_entry "https://github.com/mahirgul/aipbx/blob/main/web/index.php"
click node_route_table "https://github.com/mahirgul/aipbx/blob/main/web/src/routes.php"
click node_controller_base "https://github.com/mahirgul/aipbx/blob/main/web/src/core/BaseController.php"
click node_plugin_manager "https://github.com/mahirgul/aipbx/blob/main/web/src/core/PluginManager.php"
click node_portal_helpers "https://github.com/mahirgul/aipbx/blob/main/web/src/helpers.php"
click node_destination_registry "https://github.com/mahirgul/aipbx/blob/main/web/modules/destinations/DestinationRegistry.php"
click node_dialplan_sync "https://github.com/mahirgul/aipbx/tree/main/web/src/sync"
click node_ai_server "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/server.py"
click node_call_handler "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/calls.py"
click node_voice_requests "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/voice_requests.py"
click node_cloud_llm "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/cloud_llm.py"
click node_model_manager "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/models.py"
click node_audio_wav "https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/wav.py"
click node_chat_service "https://github.com/mahirgul/aipbx/blob/main/chat/main.go"
click node_chat_handlers "https://github.com/mahirgul/aipbx/blob/main/chat/handlers.go"
click node_chat_storage "https://github.com/mahirgul/aipbx/blob/main/chat/storage.go"
click node_signaling "https://github.com/mahirgul/aipbx/tree/main/signaling/aipbx_signaling"
click node_network_engine "https://github.com/mahirgul/aipbx/tree/main/engine/aipbx_engine"

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_portal_entry,node_route_table,node_controller_base,node_plugin_manager,node_portal_helpers,node_database toneBlue
class node_destination_registry,node_dialplan_sync,node_asterisk toneAmber
class node_ai_server,node_call_handler,node_voice_requests,node_cloud_llm,node_model_manager,node_audio_wav toneMint
class node_chat_service,node_chat_handlers,node_chat_storage,node_signaling toneRose
class node_network_engine,node_admin toneIndigo
```

## Components

### Portal management

- [Portal entry](https://github.com/mahirgul/aipbx/blob/main/web/index.php): `web/index.php`
- [Route table](https://github.com/mahirgul/aipbx/blob/main/web/src/routes.php): `web/src/routes.php`
- [Controller base](https://github.com/mahirgul/aipbx/blob/main/web/src/core/BaseController.php): `web/src/core/BaseController.php`
- [Plugin manager](https://github.com/mahirgul/aipbx/blob/main/web/src/core/PluginManager.php): `web/src/core/PluginManager.php`
- [Domain helpers](https://github.com/mahirgul/aipbx/blob/main/web/src/helpers.php): `web/src/helpers.php`
- **Portal database**

### PBX telephony

- [Destination registry](https://github.com/mahirgul/aipbx/blob/main/web/modules/destinations/DestinationRegistry.php): `web/modules/destinations/DestinationRegistry.php`
- [Dialplan sync](https://github.com/mahirgul/aipbx/tree/main/web/src/sync): `web/src/sync`
- **Asterisk PBX**

### AI voice services

- [AI HTTP server](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/server.py): `ai/aipbx_ai/server.py`
- [Call orchestration](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/calls.py): `ai/aipbx_ai/calls.py`
- [Voice requests](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/voice_requests.py): `ai/aipbx_ai/voice_requests.py`
- [Cloud language models](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/cloud_llm.py): `ai/aipbx_ai/cloud_llm.py`
- [Model registry](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/models.py): `ai/aipbx_ai/models.py`
- [Audio processing](https://github.com/mahirgul/aipbx/blob/main/ai/aipbx_ai/wav.py): `ai/aipbx_ai/wav.py`

### Communications services

- [Chat service](https://github.com/mahirgul/aipbx/blob/main/chat/main.go): `chat/main.go`
- [Chat handlers](https://github.com/mahirgul/aipbx/blob/main/chat/handlers.go): `chat/handlers.go`
- [Chat storage](https://github.com/mahirgul/aipbx/blob/main/chat/storage.go): `chat/storage.go`
- [Signaling service](https://github.com/mahirgul/aipbx/tree/main/signaling/aipbx_signaling): `signaling/aipbx_signaling`

### Network services

- [Network discovery](https://github.com/mahirgul/aipbx/tree/main/engine/aipbx_engine): `engine/aipbx_engine`

### Other components

- **Administrator**

## Connections

- Administrator → Portal entry: uses (evidence: `README.md`)
- Portal entry → Route table: loads routes (evidence: `web/index.php`)
- Route table → Controller base: dispatches controllers (evidence: `web/src/routes.php`)
- Portal entry → Plugin manager: loads plugins (evidence: `web/index.php`)
- Controller base → Domain helpers: uses helpers (evidence: `web/src/core/BaseController.php`)
- Domain helpers → Portal database: accesses data (evidence: `web/src/helpers.php`)
- Destination registry → Dialplan sync: configures destinations
- Dialplan sync → Asterisk PBX: updates PBX config
- AI HTTP server → Call orchestration: dispatches calls (evidence: `ai/aipbx_ai/server.py`)
- AI HTTP server → Model registry: manages models (evidence: `ai/aipbx_ai/server.py`)
- AI HTTP server → Voice requests: handles requests (evidence: `ai/aipbx_ai/server.py`)
- Call orchestration → Cloud language models: uses language model (evidence: `ai/aipbx_ai/calls.py`)
- Call orchestration → Audio processing: processes audio (evidence: `ai/aipbx_ai/calls.py`)
- Voice requests → Cloud language models: uses language model (evidence: `ai/aipbx_ai/voice_requests.py`)
- Model registry → Audio processing: uses audio
- Chat service → Chat handlers: serves requests
- Chat service → Chat storage: uses storage
