How billrun/system works
Purpose and runtime
BillRun is a telecom and usage-based enterprise billing platform: it ingests usage and payment data, rates and aggregates it, manages prepaid/postpaid balances, runs billing cycles, and produces invoices, collections, reports, and integrations. The backend is PHP on Yaf with bundled Zend components; persistent state is MongoDB, including sharding/replica-oriented deployment support. Core bootstrap and HTTP entry points are public/index.php, application/Bootstrap.php, and application/yaf.php.
Access surfaces
The system exposes several server-side control planes: legacy/general APIs and action endpoints (application/controllers/Api.php, application/controllers/Action/Api.php), versioned v3 actions (application/controllers/Action/v3/Bill.php), and the Billapi module’s entity CRUD/import/export interface (application/modules/Billapi/controllers/Billapi.php, application/modules/Billapi/Models/Entity.php). Separate controllers support CLI/cron, queues, realtime traffic, OAuth2, payment pages, and administration. The React/Redux operator UI enters at front-end/src/index.js, routes through front-end/src/routes/Routes.js, and calls backend APIs via front-end/src/common/Api.js; compiled assets are served from public/.
Usage ingestion and mediation
Inbound usage can arrive as files, FTP/SSH sources, inline data, realtime requests, or external sources. Receiver abstractions acquire input (library/Billrun/Receiver.php, library/Billrun/Receiver/Ftp.php); parsers decode CSV, JSON, XML, GGSN, and TAP3 formats (library/Billrun/Parser.php, library/Billrun/Parser/Tap3.php); processors normalize and persist usage or payment records (library/Billrun/Processor/Usage.php, library/Billrun/Processor/Realtime.php). Input processors are configurable in the UI (front-end/src/components/InputProcessor/InputProcessor.js) and backend plugins extend this pipeline (application/plugins/ggsn.php, application/plugins/tap3.php).
Rating, balances, and subscriber domain
The central domain models cover subscribers, services, plans, rates, balances, discounts, taxes, and bills. Rating applies usage-type-specific calculators and customer pricing (library/Billrun/Calculator.php, library/Billrun/Calculator/Rate.php, library/Billrun/Calculator/CustomerPricing.php). It feeds prepaid/postpaid balance handling (library/Billrun/Balance/Prepaid.php, library/Billrun/Balance/Postpaid.php) and subscriber/service action managers (library/Billrun/ActionManagers/Subscribers/Action.php, library/Billrun/ActionManagers/Services/Action.php). Mongo-oriented persistence is encapsulated in library/Billrun/Db.php and the local document layer under library/Mongodloid/.
Billing-cycle orchestration
Batch billing is a staged workflow: select cycle scope/accounts/subscribers, aggregate rated lines and recurring charges, calculate billing artifacts, then confirm/generate. Cycle-specific aggregation and account invoice logic sit in library/Billrun/Cycle/Aggregator.php, library/Billrun/Cycle/Account/Invoice.php, and library/Billrun/Cycle/Subscriber/Invoice.php. Long-running work is represented as jobs (library/Billrun/Job/Cycle.php, library/Billrun/Job/Generate.php) and managed through queue models/controllers (application/models/Jobsqueue.php, application/controllers/Queue.php). Cron and worker action entry points permit asynchronous or scheduled execution (application/controllers/Cron.php, application/controllers/Action/Worker.php).
Financial outputs and collections
Bills and payment records support multiple payment types (library/Billrun/Bill.php, library/Billrun/Bill/Payment.php). Invoice rendering uses PHP templates and a dedicated view adapter (library/Billrun/View/Invoice.php, application/views/invoices/invoice.phtml), with PDF generation/signing capabilities (library/Billrun/Generator/Pdf.php, library/Billrun/Signer/JsignpdfSigner.php). Collections execute configured steps and notify through HTTP, email, or SMS (library/Billrun/CollectionSteps.php, library/Billrun/CollectionSteps/Notifiers/Http.php).
External boundaries and extensibility
Payment is isolated behind gateway implementations, including Stripe, PayPal, CreditGuard, Payrexx, and Tranzila (library/Billrun/PaymentGateway.php, library/Billrun/PaymentGateway/Stripe.php, library/Billrun/PaymentGateway/CreditGuard.php). Other integration boundaries include FTP/SFTP, HTTP/SOAP subscriber sources, SMS, email, webhooks, and network-specific plugins. The plugin layer is the principal extension seam (library/Billrun/Plugin/BillrunPluginBase.php, application/plugins/webhooks.php); configuration defines tenant, API, realtime, payment, and billing behavior under conf/ (for example conf/container.ini, conf/realtime/conf.ini).
Deployment and data operations
Container definitions support PHP 5.6 through 8.0 variants, Nginx/PHP-FPM, MongoDB 5/replica setups, and test/cluster compositions (docker/billrun-docker/docker-compose-php74.yml, docker/billrun-docker/docker-compose-php74-mongodb5.0.yml, docker/billrun-docker/nginx.conf). Mongo initialization, sharding, and migrations are repository-managed (mongo/create.js, mongo/sharding.js, application/migrations/). Operational scripts run cycles/generation and maintain Mongo data (scripts/cycle_cron.sh, scripts/run_generate.sh).
Main entry points: Aggregator.php Cycle aggregation and invoicing · Api.php API and action controllers · Db.php Mongo document persistence · Usage.php Usage and payment processors
Components 19
Access surfaces
- Yaf HTTP bootstrap
public/index.php - Operator UI · Routes requests through the backend API client.
front-end/src/index.js - API and action controllers · Legacy, action, and versioned billing endpoints.
application/controllers/Api.php - Billapi entity interface · Entity CRUD, import, and export boundary.
application/modules/Billapi/controllers/Billapi.php
Usage mediation
- Usage receivers · Accepts files, FTP/SSH, inline, realtime, and external inputs.
library/Billrun/Receiver.php - Format parsers · Decodes CSV, JSON, XML, GGSN, and TAP3.
library/Billrun/Parser.php - Usage and payment processors · Normalizes and persists incoming records.
library/Billrun/Processor/Usage.php - Plugin extension layer · Extends mediation and integration behavior.
library/Billrun/Plugin/BillrunPluginBase.php
Billing domain
- Rating calculators · Applies rates and customer pricing to usage.
library/Billrun/Calculator/Rate.php - Subscriber and service actions · Manages subscribers, services, plans, and related actions.
library/Billrun/ActionManagers/Subscribers/Action.php - Prepaid and postpaid balances
library/Billrun/Balance/Prepaid.php
Cycle and outputs
- Cycle aggregation and invoicing · Scopes accounts, aggregates charges, and calculates invoice artifacts.
library/Billrun/Cycle/Aggregator.php - Cycle and generation jobs · Represents long-running billing and generation work.
library/Billrun/Job/Cycle.php - Queue, cron, and workers · Schedules and executes asynchronous jobs.
application/models/Jobsqueue.php - Invoice rendering and PDF · Renders templates and generates or signs PDFs.
library/Billrun/View/Invoice.php - Collections and notifications · Executes collection steps through HTTP, email, and SMS.
library/Billrun/CollectionSteps.php - Payment gateways · Gateway abstraction for Stripe, PayPal, CreditGuard, and others.
library/Billrun/PaymentGateway.php
Data and operations
- Mongo document persistence · Mongo-oriented database and document layer.
library/Billrun/Db.php - MongoDB deployment and schema ops · Initialization, sharding, replica support, and migrations.
mongo/sharding.js
Connections 22
- Operator UI → API and action controllers: API calls
- Yaf HTTP bootstrap → API and action controllers: routes requests
- API and action controllers → Billapi entity interface: entity operations
- API and action controllers → Usage receivers: submits input
- Usage receivers → Format parsers: raw input
- Format parsers → Usage and payment processors: decoded records
- Plugin extension layer → Usage receivers: extends sources
- Plugin extension layer → Format parsers: adds formats
- Usage and payment processors → Rating calculators: normalized usage
- Usage and payment processors → Mongo document persistence: persists records
- Rating calculators → Prepaid and postpaid balances: rated charges
- Subscriber and service actions → Prepaid and postpaid balances: service context
- Prepaid and postpaid balances → Mongo document persistence: stores balances
- Rating calculators → Cycle aggregation and invoicing: rated lines
- Cycle aggregation and invoicing → Cycle and generation jobs: creates cycle work
- Queue, cron, and workers → Cycle and generation jobs: dispatches
- Cycle and generation jobs → Cycle aggregation and invoicing: executes aggregation
- Cycle aggregation and invoicing → Invoice rendering and PDF: billing artifacts
- Invoice rendering and PDF → Collections and notifications: outstanding bills
- Collections and notifications → Payment gateways: payment collection
- Cycle aggregation and invoicing → Mongo document persistence: stores bills and invoices
- Mongo document persistence → MongoDB deployment and schema ops: Mongo storage