Compute layer
All business logic runs asfunctions.https.onRequest handlers exported from index.js. There are no long-running servers. Every function is stateless — it reads from databases and external APIs, performs its operation, and returns a response.
Functions are written for Node.js 22 and deployed to Google Cloud via the Firebase CLI:
index.js entry point, organized into logical modules:
| Module | Description |
|---|---|
exchange_rates | Fetch and store BCV exchange rates (USD, EUR vs. Bolívar) |
create_client, create_collaborator, create_staff | User registration by role |
validate_user_*, setSessionId | Authentication and session validation |
tickets_generate, tickets_list_*, tickets_lock, tickets_unlock | Ticket lifecycle management |
order_created, order_process, order_update, order_payout | Order creation and fulfillment |
transactions_generate, transactions_validate | Transaction recording and validation |
conciliation_* | Financial reconciliation against bank records |
money_distribution, total_sales, sold_by_office, number_tickets_sold | Analytics and indicators |
*_seatsio | Seats.io chart and seat management |
stripe_* | Stripe payment intents and webhook handling |
api_mercantil_* | Banco Mercantil debit, credit, and Pago Móvil payments |
conciliation_bdv, mobile_payment_bcv | Banco de Venezuela reconciliation and mobile payments |
billing_emision, generateBillingFromExpenses | TFHKA digital invoice generation |
offline_office_* | Offline ticket office synchronization |
app_* | Mobile app user-facing functions |
Databases
TMT Platform uses two databases with distinct responsibilities.Firestore (real-time operational data)
Firestore is the primary database for all event-driven, real-time data. It stores:- Users —
u_clients,u_collaborators,u_staffcollections, keyed by Firebase Auth UID - Events and tickets — event metadata, ticket inventory, zone assignments
- Orders — order documents that trigger downstream Cloud Functions via Firestore listeners (
onDocumentCreated,onDocumentUpdated) - Exchange rates — current and historical BCV rates in
data/exchange_rates - Notifications and sessions — push notification records and session tokens
config/config.js:
PostgreSQL via Cloud SQL (financial records)
PostgreSQL handles structured financial data that requires relational queries, joins, and aggregations — workloads that are impractical in a document store. It stores:- Transaction records for reconciliation
- Bank statement data loaded from Banco Mercantil and BDV
- Conciliation summaries and adjustment records
- Billing and invoice data
config/dbpostgres.js helper connects using the @google-cloud/cloud-sql-connector and exposes a generic sqltmt function that builds and executes SELECT, INSERT, UPDATE, and DELETE queries:
Each call to
sqltmt opens a new connection pool and closes it when the query completes. This is appropriate for serverless execution where functions are short-lived and connection reuse across invocations is not guaranteed.Authentication
Firebase Authentication manages all user identities. The platform creates Firebase Auth users programmatically during registration:u_clients/{uid}, u_staff/{uid}, etc.), tying the identity record to its Firebase Auth account. Session validation and user type checks are handled by the validate_user_* and setSessionId functions.
Request and response pattern
All HTTP-triggered functions follow a consistent structure:- CORS — enabled via the
corspackage withorigin: "*"for cross-origin web clients - Request body — payloads are wrapped in a
datakey:{ "data": { ... } } - Response — always a JSON object with
message,status, anddatafields
The
exchange_rates and a small number of data-fetch functions use a simpler { result: "..." } response and do not require a request body.Third-party integrations
Stripe
International card payments. Functions:
stripe_create_payment_intent, stripe_confirm_payment, stripe_get_payment_intent, stripe_webhook. Uses the official stripe Node.js SDK (v19).Banco Mercantil
Venezuelan domestic bank payments via the Mercantil API. Supports debit card (
api_mercantil_tdd_pay), credit card (api_mercantil_tdc_pay), and Pago Móvil C2P (api_mercantil_c2p_pay, api_mercantil_c2p_auth, api_mercantil_c2p_search).BCV / Banco de Venezuela
Exchange rate scraping from the BCV website (
exchange_rates), mobile payment processing (mobile_payment_bcv), and bank statement reconciliation (conciliation_bdv).Seats.io
Interactive seating chart management. Functions cover chart publishing, object listing, tag management, seat holds (
hold_seats_seatsio), releases (release_seats_seatsio), and bookings (book_seats_seatsio). Uses the seatsio SDK (v87).TFHKA
Venezuelan digital billing (facturación electrónica). Functions:
billing_emision and generateBillingFromExpenses generate TFHKA-compliant electronic invoices from order data.Firebase Cloud Messaging
Push notifications sent to mobile app users via
send_notifications. Notification records are stored in Firestore and listed with list_notifications.Function categories
User management
Three user roles exist in the platform — clients (event organizers), collaborators (staff attached to a client), and staff (platform administrators). Each role has its own Firestore collection and registration function. Thevalidate_user_platform and validate_user_type functions determine which role a user belongs to at login.
Events and tickets
Tickets are generated in bulk per event zone. The ticket lifecycle includes: generation, locking (reserving for a session), unlocking (releasing), sales assignment, and access control scanning. Both online (tickets_lock, tickets_unlock) and offline office modes (offline_office_tickets, offline_office_tickets_synchronization) are supported.
Orders and transactions
Orders are the central financial document. When an order document is created in Firestore, theorder_created trigger fires. Subsequent updates drive processing (order_process), payout splitting (split_payout), and billing (process_order_billing). The transactions_generate function records individual payment transactions linked to each order.
Financial reconciliation
The conciliation module matches TMT transaction records against bank statement files from Mercantil and BDV. Theconciliation_process function performs automated matching; conciliation_load_cia_manual and conciliation_load_bank_manual allow manual data loading. Results are summarized with conciliation_summary.
Analytics and indicators
A set of indicator functions query Firestore and PostgreSQL to produce dashboards for event organizers and platform administrators:money_distribution— revenue breakdown by currency and payment methodtotal_sales/total_sales_client— aggregate sales figuressold_by_office— sales performance by ticket officenumber_tickets_vs_sold— ticket inventory vs. sales ratiooffices_vs_offices_active— active vs. total office countgeneral_platform_data— platform-wide summary statistics
Deployment topology
All functions are stateless. Shared state lives exclusively in Firestore, PostgreSQL, or external service APIs. This means each function invocation is independent and the platform scales horizontally without configuration.