A serverless application for Bitrix24 that extends the capabilities of the built-in BI Connector with support for MySQL and PostgreSQL databases. This application integrates with Bitrix24's BI Constructor through REST API methods to provide external database connectivity.
- Multi-Database Support: Connect to MySQL and PostgreSQL databases
- Connection Management: Automatic connection validation and availability checks
- Dynamic Table Discovery: Search and retrieve table lists from external databases
- Field Structure Analysis: Get complete table schema information with data types
- Field Name Normalization: Automatically map friendly DB column names like
Created Byto Bitrix-safe codes likeCREATED_BY - Advanced Data Export: Support for filtering, sorting, and pagination
- Performance Optimization: Intelligent caching for table lists and structure data
- Comprehensive Logging: Detailed operation logging with configurable levels
- Production Ready: Docker-based deployment with FrankenPHP server
- Security: Built-in authentication and secure connection handling
When creating datasets, table names must follow strict naming conventions:
- Must start with a letter (a-z)
- Only lowercase Latin letters (a-z), numbers (0-9), and underscores (_) are allowed
- Examples:
users,order_items,customer_data_2024 - ❌ Invalid:
Users,2024_data,order-items,données
Bitrix24 expects field codes in uppercase snake case. This application now normalizes external database column names automatically when possible:
Created By→CREATED_BYCity / Region→CITY_REGIONopened_at→OPENED_AT
For reference, Bitrix-friendly field codes follow these rules:
- Must start with a letter (A-Z)
- Only uppercase Latin letters (A-Z), numbers (0-9), and underscores (_) are allowed
- Examples:
USER_ID,CREATED_AT,ORDER_TOTAL_2024 - ❌ Invalid:
user_id,created-at,2024_total,données_client
ℹ️ Note: the connector keeps an internal mapping between normalized Bitrix field codes and the real DB column names, so Bitrix24 can request
CREATED_BYwhile the database still storesCreated By.
- Docker and Docker Compose
- PHP 8.4+ (for local development)
- Access to a running Bitrix24 portal
-
Clone and configure:
git clone <repository-url> cd biconnector-extension cp .env.example .env
-
Edit configuration: Update
.envfile with your settings:APP_DOMAIN=https://your-domain.com LOG_LEVEL=INFO CACHE_TTL_TABLE_LIST=3600 CACHE_TTL_TABLE_DESCRIPTION=3600
-
Build and start:
make build make start
-
Install on Bitrix24:
- Upload application to your Bitrix24 portal
- The application will automatically register MySQL and PostgreSQL connectors
If you want to install the connector on a real Bitrix24 portal from your local machine, use the built-in CloudPub flow:
- Copy
.env.exampleto.env - Put your CloudPub token into
CLOUDPUB_TOKEN - Run:
make dev-init
- The script will:
- start
appandcloudpub - read the external HTTPS URL from CloudPub logs
- write that URL into
APP_DOMAIN - restart
appwith the updated domain
- start
Then register a Bitrix24 local server application with:
- Handler path:
https://your-cloudpub-domain/ - Initial installation path:
https://your-cloudpub-domain/install.php - Scope:
biconnector
To inspect the tunnel:
make logs-cloudpubIf you want a ready-to-use database for connector testing, start the bundled demo MySQL service:
make start-demo-dbOr start the whole demo stack:
make start-demo-stackThe demo database is available as:
- Docker host for the connector:
mysql-test - Local port for manual inspection:
localhost:3307
Default demo credentials:
TEST_MYSQL_DATABASE=test_db
TEST_MYSQL_USER=test_user
TEST_MYSQL_PASSWORD=test_passSeeded table:
usersfriendly_columns
If you want a ready-to-use PostgreSQL database for connector testing, start the bundled demo PostgreSQL service:
make start-demo-postgresThe demo PostgreSQL database is available as:
- Docker host for the connector:
postgres-test - Local port for manual inspection:
localhost:5433
Default demo credentials:
TEST_POSTGRES_DATABASE=test_db
TEST_POSTGRES_USER=test_user
TEST_POSTGRES_PASSWORD=test_passSeeded table:
officesfriendly_columns
Configure the application through the .env file:
| Variable | Description | Default |
|---|---|---|
APP_DOMAIN |
Public domain where application is hosted | Required |
CLOUDPUB_TOKEN |
CloudPub API token for local public HTTPS tunnel | Optional |
CLOUDPUB_IMAGE |
CloudPub Docker image (latest or latest-arm64) |
cloudpub/cloudpub:latest |
TEST_MYSQL_DATABASE |
Demo MySQL database name | test_db |
TEST_MYSQL_USER |
Demo MySQL user | test_user |
TEST_MYSQL_PASSWORD |
Demo MySQL password | test_pass |
TEST_MYSQL_ROOT_PASSWORD |
Demo MySQL root password | root_pass |
TEST_POSTGRES_DATABASE |
Demo PostgreSQL database name | test_db |
TEST_POSTGRES_USER |
Demo PostgreSQL user | test_user |
TEST_POSTGRES_PASSWORD |
Demo PostgreSQL password | test_pass |
APP_ENV |
Environment (development/production) | development |
LOG_LEVEL |
Logging level (DEBUG, INFO, WARNING, ERROR) | DEBUG |
LOG_PATH |
Directory for log files | /var/log |
LOG_ROTATION_DAYS |
Log file retention period | 7 |
CACHE_TTL_TABLE_LIST |
Table list cache duration (seconds) | 3600 |
CACHE_TTL_TABLE_DESCRIPTION |
Table structure cache duration (seconds) | 3600 |
DB_CONNECTION_TIMEOUT |
Database connection timeout (seconds) | 30 |
Required for REST API integration:
BITRIX24_PHP_SDK_APPLICATION_CLIENT_IDBITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRETBITRIX24_PHP_SDK_APPLICATION_SCOPE
# Build and run
make dev-init # Start local app + CloudPub and update APP_DOMAIN
make build # Build Docker image
make start # Start application
make start-cloudpub # Start application with CloudPub profile
make start-demo-db # Start demo MySQL database only
make start-demo-postgres # Start demo PostgreSQL database only
make start-demo-stack # Start app + demo MySQL + CloudPub
make restart # Restart with rebuild
make stop # Stop application
# Development tools
make test # Run all tests
make lint # Run PHPStan analysis
make fix-code # Fix code style issues
make pipeline # Run full CI pipeline
# Utilities
make logs # View application logs
make logs-cloudpub # View CloudPub logs
make logs-mysql-test # View demo MySQL logs
make logs-postgres-test # View demo PostgreSQL logs
make shell # Access container shell
make clean # Clean up containers and volumes# Run unit tests
make test
# Run specific test suites
composer test:unit
composer test:integration
# Code quality checks
make lint # PHPStan analysis
composer cs-check # Code style check
composer cs-fix # Fix code styleThe application provides four main endpoints that are called by Bitrix24:
Requests can be sent either as:
application/jsonbody- regular form-encoded POST fields
Purpose: Validates database connection and authenticates user Called: When creating/editing connections, creating datasets Request: POST with connection parameters
{
"connection": {
"host": "database_host",
"port": "3306",
"database": "database_name",
"username": "db_user",
"password": "db_password"
}
}Response: HTTP 200 with connection status
Purpose: Returns available tables matching search criteria Called: During dataset creation Request:
{
"searchString": "search_value",
"connection": {
"host": "database_host",
"database": "database_name",
"username": "db_user",
"password": "db_password"
}
}Response:
[
{
"code": "dataset_name",
"title": "external_table_name"
}
]Purpose: Returns table field structure and data types Called: During dataset creation and field synchronization Request:
{
"table": "table_name",
"connection": {
"host": "database_host",
"database": "database_name",
"username": "db_user",
"password": "db_password"
}
}Response:
[
{
"code": "FIELD_NAME",
"name": "Field Display Name",
"type": "string|int|double|date|datetime"
}
]Purpose: Exports table data with filtering, sorting, and pagination Called: During dataset creation, synchronization, and BI Constructor queries Request:
{
"select": ["FIELD1", "FIELD2"],
"filter": {
"FIELD1": "value",
">=FIELD2": "2024-01-01"
},
"limit": 1000,
"table": "table_name",
"connection": {
"host": "database_host",
"database": "database_name",
"username": "db_user",
"password": "db_password"
}
}Response:
[
["FIELD1", "FIELD2", "FIELD3"],
["value1", "value2", "value3"],
["value4", "value5", "value6"]
]Application: Main application class handling installation and webhook processingBiConnector: Database connection management and query executionQueryBuilder: Dynamic SQL query construction with filtering and pagination- Caching Layer: Symfony Cache with filesystem adapter for performance optimization
- Logging System: Monolog with rotating file handlers and detailed context logging
- Runtime: PHP 8.4+ with FrankenPHP server
- SDK: Bitrix24 PHP SDK 1.7.0+
- Database: Doctrine DBAL for MySQL and PostgreSQL
- Caching: Symfony Cache Component
- Logging: Monolog with rotation support
- Testing: PHPUnit with coverage reporting
- Code Quality: PHPStan static analysis and PHP CS Fixer
- Installation: User installs app on Bitrix24 portal
- Connector Registration: App registers MySQL and PostgreSQL connectors via REST API
- Connection Setup: User configures database connection parameters in Bitrix24
- Data Access: Bitrix24 makes requests to app endpoints for data retrieval
- Response Processing: App processes requests and returns formatted JSON responses
- All database connections use prepared statements to prevent SQL injection
- Connection parameters are validated and sanitized
- Authentication tokens are handled securely through Bitrix24 SDK
- Detailed logging for audit and debugging purposes
- Connection timeouts prevent resource exhaustion
- Caching: Table lists and structures are cached to reduce database load
- Connection Pooling: Efficient database connection management
- Query Optimization: Smart SQL generation with proper indexing hints
- Response Streaming: Large datasets are processed in chunks
- Memory Management: Careful resource cleanup and garbage collection
-
Database Connection Errors
- Verify connection parameters in .env file
- Check database server accessibility
- Ensure required PHP extensions are installed
-
Cache Issues
- Clear cache directory:
rm -rf cache/biconnector/* - Verify cache directory permissions
- Clear cache directory:
-
Logging Problems
- Check log directory permissions
- Verify LOG_PATH configuration
Enable detailed logging by setting LOG_LEVEL=DEBUG in .env file.
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature - Make changes and add tests
- Run quality checks:
make pipeline - Submit pull request
This project is licensed under the MIT License - see the LICENSE file for details.