# lightnet19/lightbill architecture

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

- Interactive diagram: https://gitdiagram.com/lightnet19/lightbill
- Repository: https://github.com/lightnet19/lightbill

## Overview

Light.Bill is a self-hosted ISP billing, CRM, and network-operations platform. Staff and customers use its web/API surfaces to manage subscribers and services, issue invoices, accept payments, and monitor network operations; scheduled jobs automate billing and network checks. Separate product branches cover customer support and messaging, finance and reporting, and field/team operations. README statements establish the broader capabilities; source excerpts and index references support the internal links shown. Unsampled route implementations limit finer-grained control-flow detail.

Main entry points: [`lightbill-app/src/app/api`](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api) (Application APIs), [`lightbill-app/src/lib/prisma.ts`](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/prisma.ts) (Application database), [`lightbill-app/src/lib/payment`](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/lib/payment) (Gateway connectors), [`lightbill-app/src/lib/whatsapp-engine.ts`](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/whatsapp-engine.ts) (WhatsApp engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web and identity"]
  node_web_ui["Staff dashboard"]
  node_client_ui["Customer portal"]
  node_auth["Authentication<br/>[auth.ts]"]
  node_api["Application APIs"]
end

subgraph group_billing["Billing and finance"]
  node_database[("Application database<br/>[prisma.ts]")]
  node_crypto["Credential encryption<br/>[crypto.ts]"]
  node_billing_api["Invoices and billing<br/>[route.ts]"]
  node_payment_engine["Payment verification<br/>[verify.ts]"]
  node_payment_connectors["Gateway connectors"]
  node_receipts[("Receipt storage<br/>[receipt-storage.ts]")]
  node_finance["Finance and reports"]
end

subgraph group_network["Network operations"]
  node_mikrotik["MikroTik integration<br/>[mikrotik.ts]"]
  node_olt["OLT management"]
  node_radius["RADIUS access"]
  node_analytics["Analytics and monitoring"]
end

subgraph group_support["Support and messaging"]
  node_whatsapp["WhatsApp engine<br/>[whatsapp-engine.ts]"]
  node_telegram["Telegram engine<br/>[telegram-engine.ts]"]
  node_helpdesk["Chat and ticketing"]
end

subgraph group_operations["Team operations"]
  node_field_ops["Field and HR operations"]
  node_inventory["Inventory and assets"]
end

node_staff(("ISP staff"))
node_customers(("ISP customers"))
node_cron(("Scheduled jobs"))
node_gateways{{"Payment gateways"}}
node_network_devices{{"Routers and OLTs"}}

node_staff -->|"uses"| node_web_ui
node_customers -->|"uses"| node_client_ui
node_web_ui -.->|"requests"| node_api
node_client_ui -.->|"requests"| node_api
node_api -.->|"authorizes"| node_auth
node_api -.->|"reads and writes"| node_database
node_cron -->|"triggers invoicing"| node_billing_api
node_customers -->|"pays invoices"| node_billing_api
node_billing_api -.->|"creates payment"| node_payment_connectors
node_payment_connectors -->|"requests payment"| node_gateways
node_gateways -->|"sends callbacks"| node_api
node_api -.->|"verifies callbacks"| node_payment_engine
node_payment_connectors -->|"checks signatures"| node_payment_engine
node_payment_connectors -->|"records transaction"| node_database
node_finance -->|"serves receipts"| node_receipts
node_cron -->|"runs network checks"| node_network_devices
node_api -.->|"manages routers"| node_mikrotik
node_api -->|"manages OLTs"| node_olt
node_api -->|"handles access"| node_radius
node_api -->|"serves monitoring"| node_analytics
node_mikrotik -->|"queries customers"| node_database
node_mikrotik -->|"decrypts credentials"| node_crypto
node_database -->|"encrypts fields"| node_crypto
node_api -.->|"configures messaging"| node_whatsapp
node_api -.->|"configures messaging"| node_telegram
node_whatsapp -->|"stores proof images"| node_receipts
node_whatsapp -->|"controls connections"| node_mikrotik
node_whatsapp -.->|"opens conversations"| node_helpdesk
node_telegram -->|"loads tenant token"| node_database
node_staff -->|"manages field work"| node_field_ops
node_staff -->|"manages assets"| node_inventory

click node_web_ui "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/dashboard"
click node_client_ui "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/client"
click node_auth "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/auth.ts"
click node_api "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api"
click node_database "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/prisma.ts"
click node_crypto "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/crypto.ts"
click node_billing_api "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/app/api/invoices/route.ts"
click node_payment_engine "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/payment/verify.ts"
click node_payment_connectors "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/lib/payment"
click node_receipts "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/receipt-storage.ts"
click node_finance "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/finance"
click node_mikrotik "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/mikrotik.ts"
click node_olt "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/lib/olt"
click node_radius "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/radius"
click node_analytics "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/analytics"
click node_whatsapp "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/whatsapp-engine.ts"
click node_telegram "https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/telegram-engine.ts"
click node_helpdesk "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/tickets"
click node_field_ops "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/attendance"
click node_inventory "https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/inventory"

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_web_ui,node_client_ui,node_auth,node_api toneBlue
class node_database,node_crypto,node_billing_api,node_payment_engine,node_payment_connectors,node_receipts,node_finance toneAmber
class node_mikrotik,node_olt,node_radius,node_analytics,node_network_devices toneMint
class node_whatsapp,node_telegram,node_helpdesk toneRose
class node_field_ops,node_inventory,node_staff,node_customers,node_cron,node_gateways toneIndigo
```

## Components

### Web and identity

- [Staff dashboard](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/dashboard): `lightbill-app/src/app/dashboard`
- [Customer portal](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/client): `lightbill-app/src/app/client`
- [Authentication](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/auth.ts): `lightbill-app/src/lib/auth.ts`
- [Application APIs](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api): `lightbill-app/src/app/api`

### Billing and finance

- [Application database](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/prisma.ts): `lightbill-app/src/lib/prisma.ts`
- [Credential encryption](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/crypto.ts): `lightbill-app/src/lib/crypto.ts`
- [Invoices and billing](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/app/api/invoices/route.ts): `lightbill-app/src/app/api/invoices/route.ts`
- [Payment verification](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/payment/verify.ts): `lightbill-app/src/lib/payment/verify.ts`
- [Gateway connectors](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/lib/payment): `lightbill-app/src/lib/payment`
- [Receipt storage](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/receipt-storage.ts): `lightbill-app/src/lib/receipt-storage.ts`
- [Finance and reports](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/finance): `lightbill-app/src/app/api/finance`

### Network operations

- [MikroTik integration](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/mikrotik.ts): `lightbill-app/src/lib/mikrotik.ts`
- [OLT management](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/lib/olt): `lightbill-app/src/lib/olt`
- [RADIUS access](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/radius): `lightbill-app/src/app/api/radius`
- [Analytics and monitoring](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/analytics): `lightbill-app/src/app/api/analytics`

### Support and messaging

- [WhatsApp engine](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/whatsapp-engine.ts): `lightbill-app/src/lib/whatsapp-engine.ts`
- [Telegram engine](https://github.com/lightnet19/lightbill/blob/main/lightbill-app/src/lib/telegram-engine.ts): `lightbill-app/src/lib/telegram-engine.ts`
- [Chat and ticketing](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/tickets): `lightbill-app/src/app/api/tickets`

### Team operations

- [Field and HR operations](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/attendance): `lightbill-app/src/app/api/attendance`
- [Inventory and assets](https://github.com/lightnet19/lightbill/tree/main/lightbill-app/src/app/api/inventory): `lightbill-app/src/app/api/inventory`

### Other components

- **ISP staff**
- **ISP customers**
- **Scheduled jobs**
- **Payment gateways**
- **Routers and OLTs**

## Connections

- ISP staff → Staff dashboard: uses
- ISP customers → Customer portal: uses
- Staff dashboard → Application APIs: requests
- Customer portal → Application APIs: requests
- Application APIs → Authentication: authorizes
- Application APIs → Application database: reads and writes
- Scheduled jobs → Invoices and billing: triggers invoicing
- ISP customers → Invoices and billing: pays invoices
- Invoices and billing → Gateway connectors: creates payment
- Gateway connectors → Payment gateways: requests payment (evidence: `lightbill-app/src/lib/payment/tripay-engine.ts`)
- Payment gateways → Application APIs: sends callbacks
- Application APIs → Payment verification: verifies callbacks
- Gateway connectors → Payment verification: checks signatures (evidence: `lightbill-app/src/lib/payment/tripay-engine.ts`)
- Gateway connectors → Application database: records transaction (evidence: `lightbill-app/src/lib/payment/tripay-engine.ts`)
- Finance and reports → Receipt storage: serves receipts (evidence: `lightbill-app/src/lib/receipt-storage.ts`)
- Scheduled jobs → Routers and OLTs: runs network checks
- Application APIs → MikroTik integration: manages routers
- Application APIs → OLT management: manages OLTs
- Application APIs → RADIUS access: handles access
- Application APIs → Analytics and monitoring: serves monitoring
- MikroTik integration → Application database: queries customers (evidence: `lightbill-app/src/lib/mikrotik.ts`)
- MikroTik integration → Credential encryption: decrypts credentials (evidence: `lightbill-app/src/lib/mikrotik.ts`)
- Application database → Credential encryption: encrypts fields (evidence: `lightbill-app/src/lib/prisma.ts`)
- Application APIs → WhatsApp engine: configures messaging
- Application APIs → Telegram engine: configures messaging
- WhatsApp engine → Receipt storage: stores proof images (evidence: `lightbill-app/src/lib/whatsapp-engine.ts`)
- WhatsApp engine → MikroTik integration: controls connections (evidence: `lightbill-app/src/lib/whatsapp-engine.ts`)
- WhatsApp engine → Chat and ticketing: opens conversations
- Telegram engine → Application database: loads tenant token (evidence: `lightbill-app/src/lib/telegram-engine.ts`)
- ISP staff → Field and HR operations: manages field work
- ISP staff → Inventory and assets: manages assets
