How dm1tryandreev1ch/flex-n-roll-pro works
1. Repository shape
This is a Dockerized Node.js monorepo for a label-printing business. The central external system is Bitrix24 CRM; most services either consume Bitrix events, call Bitrix REST APIs, or read CRM data for reporting. The only non-CRM user-facing apps are the calculator SPA and the analytics dashboard.
2. Core control plane: webhook/
fnr-webhook is the main event ingress. It receives Bitrix24 OAuth callbacks and subscribed CRM events, authenticates/rate-limits them, and then fans out work to other services. It is the orchestration layer for:
- lead classification and manager routing,
- event forwarding to call analysis,
- event forwarding to marking,
- event binding/subscription management during install.
3. Lead routing flow
Incoming Bitrix lead events are classified by webhook using a local LLM endpoint via LM Studio (host.docker.internal:1234). Based on the classification, the service assigns leads to managers, using Redis for state such as round-robin counters and possibly deduplication/rate limiting. This is the main “automation brain” of the platform.
4. Call analysis subsystem: commanalysis/
fnr-commanalysis handles call-related events from Bitrix. Its pipeline is:
- receive call end events or batch jobs,
- fetch audio / call metadata from Bitrix,
- transcribe with OpenAI Whisper,
- score or summarize with GPT-based prompts (sentiment, scriptCheck, dataExtract),
- emit metrics, logs, and reports.
A separate scheduler/dailyBatch.js job generates daily summaries, so this service has both request-driven and cron-driven execution paths.
5. Marking subsystem: marking/
fnr-marking is the integration boundary for Честный ЗНАК / GIS MT workflows. It processes CRM deal updates, manages product codes, and generates DataMatrix codes. The repo structure suggests a split between:
- route layer (routes/marking.js, routes/webhook.js),
- Bitrix adapter,
- domain services for code management and MDLP integration,
- utility-level DataMatrix generation.
It also persists marking-related files/state locally in its data volume.
6. Telegram order status bot: fnr-status-bot/
This service is a long-polling Telegram bot. It provides a lightweight lookup channel for deal/order status against Bitrix24. The code is organized as:
- bot bootstrap,
- scene-based conversation flow (scenes/checkOrder.js),
- Bitrix integration service,
- formatting and keyboard helpers.
It is user-facing, but it is not part of the web frontend stack.
7. Calculator subsystem: calculator/
The calculator is a two-part service:
- a React + Vite SPA served by Nginx,
- a small Express API (server.js) used for Bitrix integration and server-side calculations.
The frontend is organized around a multi-step calculator flow (StepOne, StepTwo, StepThree, PriceResult, LeadForm) with shared pricing logic in utils/priceCalc.ts and hooks like useCalculator and useBitrix. This is a separate compose stack from the main backend services.
8. Analytics dashboard: fnr-analytics/
fnr-analytics is another React + Vite SPA, focused on reporting rather than transactions. It pulls data from Bitrix through src/api/bitrix.ts and renders pages for:
- dashboard,
- deals,
- contacts,
- activities,
- managers report,
- finance report,
- settings/login.
It appears to be a read-heavy front end with export support (ExportButton, exportExcel.ts) and role-based access.
9. Shared infrastructure: Redis, Docker Compose, and networking
The main stack runs on a Docker bridge network (fnr-net). Services talk to each other by container name. Redis is a shared infrastructure dependency for caching, counters, and rate limiting, especially in webhook/routing logic. The repo uses multiple compose files:
- docker-compose.yml for the core backend services,
- docker-compose.calculator.yml for the calculator stack,
- docker-compose.monitoring.yml for Prometheus/Grafana.
10. Observability boundary
Several backend services expose /metrics, and the monitoring/ directory provisions Prometheus scraping plus Grafana dashboards. This is a cross-cutting subsystem rather than business logic. Dashboard provisioning is committed in-repo, so monitoring is treated as part of the application architecture, not an external add-on.
11. Integration boundaries
The biggest external dependencies are:
- Bitrix24 as CRM/system of record,
- LM Studio as the local LLM endpoint used by webhook routing,
- OpenAI APIs for commanalysis,
- Telegram Bot API for status lookup,
- GIS MT / Честный ЗНАК for marking.
These are separated into service-specific adapters rather than being called directly from the UI.
12. Diagramming the repo
If drawing the architecture, center everything around Bitrix24 + webhook orchestration + Redis. Then show four major consumers:
- commanalysis for call intelligence,
- marking for production marking,
- fnr-status-bot for human status lookup,
- calculator and fnr-analytics as browser-facing applications.
Overlay Prometheus/Grafana as shared observability, and treat Docker Compose as the deployment boundary that glues all containers together.
Main entry points: src/server.js fnr-commanalysis · src/server.js fnr-webhook · prometheus.yml Prometheus · docker-compose.yml Core compose
Components 29
External systems
Third-party and local services the repository integrates with
- Bitrix24 · System of record for leads, deals, calls, and status data
- Redis · Shared counters, deduplication, and rate limiting state
- LM Studio · Local classification endpoint used by lead routing
- OpenAI · Whisper and GPT-based analysis for call intelligence
- Telegram · Long-polling chat channel for order status lookup
- GIS MT · Честный ЗНАК / MDLP integration boundary
Control plane
Backend services that ingest Bitrix events and orchestrate automation
- fnr-webhook · Bitrix ingress, lead routing, event fan-out, and install flow
webhook/src/server.js - Auth/rate limit · OAuth validation and request throttling for webhook ingress
webhook/src/middleware/auth.js - Routing engine · Lead classification, manager assignment, and automation decisions
webhook/src/services/routing.js - Event binder · Installs and binds CRM event subscriptions
webhook/src/services/eventBinder.js - fnr-commanalysis · Call transcription, scoring, summaries, and batch reporting
commanalysis/src/server.js - Transcription · Fetches audio and runs Whisper transcription
commanalysis/src/services/whisper.js - Call analysis · Prompt-driven sentiment, script checks, and data extraction
commanalysis/src/services/callAnalyzer.js - Daily batch · Cron-style daily summaries and batch execution
commanalysis/scheduler/dailyBatch.js - fnr-marking · CRM-driven marking workflows and DataMatrix generation
marking/src/server.js - Code manager · Manages product codes and marking state
marking/src/services/codeManager.js - MDLP adapter · Boundary to marking workflow services and local file state
marking/src/services/mdlp.js - DataMatrix · Generates printable marking codes
marking/src/utils/datamatrix.js - Bitrix API client · Shared client layer for CRM reads and writes
webhook/src/services/bitrix.js
User apps
Browser and bot interfaces used by customers and staff
- fnr-status-bot · Long-polling order status lookup bot
fnr-status-bot/src/bot.js - Order lookup · Conversation flow for checking deal or order status
fnr-status-bot/src/scenes/checkOrder.js - Calculator SPA · Customer-facing pricing calculator with Bitrix lead handoff
calculator/src/App.tsx - Calculator API · Server-side calculations and Bitrix integration for the calculator
calculator/server.js - Analytics dashboard · Reporting UI for deals, contacts, managers, and finance
fnr-analytics/src/App.tsx
Operations
Shared deployment and observability stack
- Core compose · Main container stack for backend services
docker-compose.yml - Calculator compose · Separate stack for the calculator application
docker-compose.calculator.yml - Monitoring compose · Stack for metrics collection and dashboards
docker-compose.monitoring.yml - Prometheus · Scrapes service metrics and monitoring targets
monitoring/prometheus/prometheus.yml - Grafana · Provisioned dashboards for platform visibility
monitoring/grafana/dashboards/fnr-overview.json
Connections 36
- fnr-webhook → Auth/rate limit: protects · Validates and throttles incoming CRM callbacks
- fnr-webhook → Routing engine: classifies · Dispatches lead automation and manager assignment
- fnr-webhook → Event binder: binds · Manages install-time webhook and event subscriptions
- fnr-webhook → Bitrix API client: calls · Uses Bitrix REST APIs for CRM operations
- Routing engine → LM Studio: asks · Sends lead text to local LLM classification
- Routing engine → Redis: uses · Stores counters and routing state
- Routing engine → Bitrix24: updates · Assigns or updates CRM lead ownership
- fnr-webhook → fnr-commanalysis: forwards · Sends call-related events for analysis
- fnr-commanalysis → Bitrix24: reads · Fetches call metadata and audio from CRM
- fnr-commanalysis → Transcription: transcribes · Runs speech-to-text on call recordings
- fnr-commanalysis → Call analysis: scores · Applies prompt-based sentiment and content checks
- Call analysis → OpenAI: uses · Calls GPT-based analysis services
- Daily batch → fnr-commanalysis: triggers · Runs scheduled batch summaries
- fnr-commanalysis → Prometheus: exposes metrics · Publishes runtime and pipeline metrics
- fnr-marking → Bitrix24: reads/writes · Processes CRM deal updates and marking events
- fnr-marking → Code manager: coordinates · Manages marking codes and product state
- Code manager → MDLP adapter: integrates · Bridges domain operations with marking workflow services
- Code manager → DataMatrix: generates · Creates printable DataMatrix codes
- MDLP adapter → GIS MT: connects · Talks to GIS MT / Честный ЗНАК boundary
- fnr-marking → Prometheus: exposes metrics · Publishes service metrics
- fnr-status-bot → Telegram: polls · Receives updates through the Telegram Bot API
- fnr-status-bot → Bitrix24: reads · Looks up order and deal status in CRM
- fnr-status-bot → Order lookup: runs · Routes the user conversation through a status-check scene
- Calculator SPA → Calculator API: uses · Frontend submits calculations and lead forms to the API
- Calculator API → Bitrix24: creates leads · Hands off calculator submissions into CRM
- Calculator API → Redis: uses · Can share cached or runtime state with backend services
- Analytics dashboard → Bitrix24: reads · Fetches reporting data from CRM
- Analytics dashboard → Prometheus: exposes metrics · Frontend/server observability where applicable
- Core compose → fnr-webhook: deploys · Core backend deployment includes the webhook orchestrator
- Core compose → fnr-commanalysis: deploys · Core backend deployment includes call analysis
- Core compose → fnr-marking: deploys · Core backend deployment includes marking services
- Core compose → fnr-status-bot: deploys · Core backend deployment includes the Telegram bot
- Calculator compose → Calculator SPA: deploys · Calculator stack runs the SPA and API
- Monitoring compose → Prometheus: deploys · Monitoring stack provisions scraping
- Monitoring compose → Grafana: deploys · Monitoring stack provisions dashboards
- Prometheus → Grafana: feeds · Metrics data is visualized in Grafana