Development of middleware for 1C-Bitrix integration

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Developing Middleware for 1C-Bitrix Integration

Direct integration between two systems (Bitrix24 ↔ 1C, Bitrix24 ↔ SAP) creates tight coupling: a change in one system's API breaks the other. Middleware is an intermediate layer that receives data from one system, transforms it, and forwards it to another. Both systems only know the middleware — they have no knowledge of each other.

When Middleware is Needed

  • Three or more systems exchange data with each other.
  • Data formats differ substantially and require complex transformation.
  • Buffering is required: one system is unavailable, data accumulates and is delivered later.
  • Auditing is required: a complete history of all data exchanges with the ability to replay any operation.
  • Different teams develop integrations independently.

Middleware Architecture Options

Option 1. PHP middleware inside 1C-Bitrix — a separate module in /local/modules/ that accepts HTTP requests, transforms data, and proxies it onward. Downside: tied to the 1C-Bitrix infrastructure.

Option 2. Independent microservice (Node.js, Python FastAPI, Go) — lives independently; 1C-Bitrix is one of its sources or consumers. Advantage: scales independently, does not consume PHP resources.

Option 3. iPaaS platforms — Make (Integromat), n8n, Apache Camel. Visual transformation builder without code. Suitable for non-developers, but limited for complex transformations.

PHP Middleware: Structure and Contracts

// Central middleware router
class IntegrationBus {
    private array $handlers = [];

    public function register(string $eventType, callable $handler): void {
        $this->handlers[$eventType][] = $handler;
    }

    public function dispatch(string $eventType, array $payload): array {
        $results = [];
        foreach ($this->handlers[$eventType] ?? [] as $handler) {
            try {
                $results[] = $handler($payload);
            } catch (\Throwable $e) {
                $this->logError($eventType, $payload, $e);
                $results[] = ['error' => $e->getMessage()];
            }
        }
        return $results;
    }
}

// Register handlers in init.php
$bus = IntegrationBus::getInstance();

// New order → CRM and accounting system
$bus->register('order.created', [CrmConnector::class, 'handleNewOrder']);
$bus->register('order.created', [AccountingConnector::class, 'createInvoice']);
$bus->register('order.created', [WarehouseConnector::class, 'reserveGoods']);

Data Transformation (Mapping)

Transformation is the most complex part of middleware. Use the Pipeline pattern:

class TransformationPipeline {
    private array $pipes = [];

    public function pipe(callable $transformation): self {
        $this->pipes[] = $transformation;
        return $this;
    }

    public function process(array $data): array {
        return array_reduce(
            $this->pipes,
            fn($carry, $pipe) => $pipe($carry),
            $data
        );
    }
}

// Example: 1C-Bitrix order → SAP format
$pipeline = (new TransformationPipeline())
    ->pipe(fn($d) => normalizeCustomerData($d))       // normalise customer data
    ->pipe(fn($d) => enrichWithAddressData($d))        // enrich with address data
    ->pipe(fn($d) => convertCurrencyFields($d))        // convert currency fields
    ->pipe(fn($d) => mapStatusCodes($d, 'bitrix2sap')) // map status codes
    ->pipe(fn($d) => validateSapSchema($d));            // validate SAP schema

Audit and Replay

Every message is logged before and after transformation:

// Audit table
CREATE TABLE integration_audit (
    id            BIGSERIAL PRIMARY KEY,
    event_type    VARCHAR(100),
    source_system VARCHAR(50),
    target_system VARCHAR(50),
    payload_in    JSONB,
    payload_out   JSONB,
    status        VARCHAR(20), -- success, error, retry
    error_msg     TEXT,
    duration_ms   INT,
    created_at    TIMESTAMP DEFAULT NOW()
);

When a downstream system fails, the operation can be replayed by audit record ID without re-querying the source.

Case Study: Three-way Interaction

A manufacturing company: 1C:ERP (stock and pricing) ↔ 1C-Bitrix website ↔ RetailCRM (order processing). Without middleware, each system pair had its own integration — six bidirectional connections, six points of failure.

After introducing a middleware hub: 3 systems → 3 connectors to middleware. A change in the 1C API affected only the 1C connector, leaving the RetailCRM integration untouched.

Task Effort
Architecture and data schema design 8–16 h
Core: event bus + transformation pipeline 8–12 h
Audit tables and replay 4–6 h
Connector per system 8–12 h each
Monitoring and alerting 4–6 h