Skip to main content

sprout_backend

NestJS-based microservice providing REST API and background job processing for the Sprout platform.

Overview

The sprout_backend is the core API service that provides:

  • REST API endpoints for the frontend
  • Background job processing with BullMQ
  • Event matching and pricing logic
  • Inventory management
  • User authentication

Technology Stack

  • Framework: NestJS 10.x
  • Language: TypeScript 5.x
  • Database: PostgreSQL with Prisma ORM
  • Queue: BullMQ with Redis
  • Search: MeiliSearch
  • Monitoring: Prometheus, Sentry, OpenTelemetry
  • Logging: Pino

Getting Started

Prerequisites

  • Node.js 18+
  • Bun (preferred) or npm
  • Docker (for PostgreSQL and Redis)
  • Doppler CLI (for environment variables)

Setup

  1. Install dependencies:

    bun install
  2. Start Docker services:

    docker-compose up -d
  3. Run database migrations:

    doppler run -- npx prisma migrate dev
  4. Start development server:

    doppler run -- bun run start:dev
  5. Start background worker (separate terminal):

    doppler run -- bun run worker:dev

Key Commands

See Detailed Commands Reference for complete command reference.

Development

  • bun run start:dev - Start API server
  • bun run worker:dev - Start background worker
  • bun run build - Build for production

Code Quality

  • bun run type:check - Type checking
  • bun run lint - Lint with auto-fix
  • bun run format - Format code

Testing

  • bun test - Run tests
  • bun run test:cov - Coverage report
  • bun run test:e2e - E2E tests

Architecture

The service has three main entry points:

  1. Main API Server (src/main.ts) - Port 3000
  2. Background Worker (src/worker.ts) - Port 4001
  3. CLI Interface (src/cli.ts) - Command-line tools

Core Modules

  • modules/data/ - Data processing (event-matcher, skybox, ticketmaster, tickops)
  • modules/db/ - Database service
  • modules/worker/ - Background job processing
  • modules/cache/ - Redis caching
  • scrapers/ - Web scraping services

Database

Uses Prisma ORM with PostgreSQL. Schema includes:

  • Event data (TicketmasterEvent, SkyboxResult, CombinedResult)
  • Inventory (SkyboxInventory, SkyboxSoldInventory)
  • Purchases (AssignedSoldInventory)
  • Monitoring (MonitoredListing, MonitoredListingPriceHistory)
  • Pipeline tracking (EventRun, EventRunItem)

Queue System

Uses BullMQ with Redis:

  • ETL_QUEUE (concurrency: 5) - Data processing
  • EVENT_MATCHER_QUEUE (concurrency: 1) - Event matching

View queue dashboard at: http://localhost:3000/queues

API Endpoints

  • GET /health - Health check
  • GET /metrics - Prometheus metrics
  • GET /queues - Bull Board UI
  • REST API endpoints for event and inventory management

Environment Variables

All environment variables are in Doppler. See Environment Variables for complete list.

Key variables:

  • DATABASE_URL - PostgreSQL connection
  • REDIS_URL - Redis connection
  • MEILISEARCH_HOST - MeiliSearch URL
  • SKYBOX_* - Skybox API credentials
  • TICKETMASTER_API_KEY - Ticketmaster API key

Monitoring

  • Metrics: Prometheus at /metrics
  • Logging: Structured logging with Pino
  • Tracing: OpenTelemetry integration
  • Error Tracking: Sentry

Documentation