fbm admin panel

Internal Tool

Overview

Centralized control center for the fbmhdl.com affiliate program and the podruga.ai chatbot codebase. Connects to production databases as read-only by default - all write operations blocked at model level, with selective exceptions for content management.

Covers real-time analytics, algorithmic fraud detection with risk scoring, an LLM testing playground, payment aggregation across 6 processors, centralized logging with Telegram/email alerts, and blog content management with cross-server synchronization.

Screenshots

Dashboard - Analytics overview

Dashboard with real-time metrics, user growth charts, and activity heatmaps

Centralized logging

Centralized log aggregation with filtering, search, and real-time streaming

LLM Testing Playground

LLM Testing Playground for API experimentation and model comparison

Tech Stack

Backend

  • Ruby on Rails
  • PostgreSQL (multi-schema)
  • Solid Queue / Cache / Cable

Frontend

  • Hotwire
  • Chartkick

Data Architecture

  • Read-only external DBs
  • Thread-safe tenant switching
  • PostgreSQL schema isolation
  • Cross-database queries

Infrastructure

  • DigitalOcean + Nginx
  • CloudFlare CDN + SSL
  • systemd services
  • Zero-downtime deploys

Multi-Tenant Architecture

Thread-safe tenant context switching with PostgreSQL schema-based isolation. Each tenant (app + locale combination) operates in its own schema with dynamic SET search_path routing. Session-persisted tenant selection with real-time UI switching.

Read-only database protection via abstract base class pattern - all write operations blocked at model level, with selective WritableBase exceptions for authorized content management.

# Thread-safe tenant switching with schema isolation
around_action :with_tenant_schema

def with_tenant_schema
  PodrugaBase.connection_pool.with_connection do |conn|
    conn.execute("SET search_path TO #{current_tenant.schema}")
    yield
  end
end

# Read-only protection with selective writes
class PodrugaBase < ActiveRecord::Base
  def readonly? = true
  def save(*) = raise ActiveRecord::ReadOnlyRecord
end

class BlogPost < PodrugaWritableBase  # Exception for CMS
end

Technical Challenges

Multi-Database Transaction Isolation

Rails 8 changed connection pool management, causing connection leaks when switching databases. Implemented explicit pool management with with_connection blocks and proper schema path setting per request.

Fraud Detection at Scale

Identifying multi-account abuse across thousands of users without performance impact. Efficient SQL aggregations in single queries, subnet-aware IP detection, computation caching, and lazy evaluation of detailed analysis.