Loterias - Real-time betting management System

Web application designed to digitize and manage lottery simulations. It orchestrates a multi-tier user hierarchy to coordinate betting flows, manage distributed credits, and process payouts. It replaces manual bookkeeping with a secure, automated digital ledger, ensuring transparency and efficiency.

Loterias - Real-time betting management System

The Problem

Local lottery operations often suffer from: Manual error: Paper tickets and manual calculations lead to mistakes in payouts and balances. Lack of control: Difficulty ensuring sellers stop taking bets before the official lottery results. Financial opacity: Tracking credit flow across multiple levels (Owner → Admin → Seller) is complex and prone to fraud. Scalability issues: expanding to new sellers or lotteries requires significant administrative overhead.

The Solution

Hierarchical Access Control: A strict permission system where Owners manage Admins, and Admins supervise Sellers, mirroring real-world operational structures. Digital Wallet & Credits: A closed-loop financial system. Credits are transferred down the hierarchy, and winnings flow back up or are redeemed. Every transaction is logged for audit. Automated Integrity: Time-Lock Mechanism: Betting windows automatically close 30 minutes before the official play time, enforced by server-side logic in the America/Bogota timezone. Winner Detection: Automated matching of winning numbers against thousands of plays to instantly flag winners and notify the hierarchy.

My Role

Full stack lead developer

Tech Stack

Next.jsTypeScriptPostgreSQL Prisma Tailwind CSSZod VercelSupabase

Key Decisions

  • 1

    Server actions for mutation: Leveraged Next.js Server Actions to handle bets and transfers directly from the UI components. This reduced API boilerplate and ensured end-to-end type safety between the client forms and backend logic.

  • 2

    Atomic transactions: Used prisma.$transaction for all financial operations (e.g., placing a bet requires checking balance, deducting funds, and creating the ticket record simultaneously) to prevent race conditions and double-spending.

  • 3

    Timezone enforcement: Instead of relying on UTC or server time, the system explicitly casts all deadlines to America/Bogota. This prevents issues where a server in a different region might allow a bet after the local lottery has played.

  • 4

    Optimistic UI updates: Implemented revalidatePath strategies to ensure that when a seller places a bet or an admin transfers credits, the dashboards update instantly without a full page reload.

Screenshot Gallery

Loterias - Real-time betting management System Screenshot
Loterias - Real-time betting management System Screenshot