Back to All Projects
Bin Khalid Dairy Farm V2
Family Business ProjectLive

Bin Khalid Dairy Farm V2

Dairy operations, billing, and finances in one secure dashboard.

Next.js 15React 19TypeScriptTailwind CSSshadcn/uiPostgreSQLDrizzle ORMFirebase AuthenticationZod

Problem Statement

A dairy farm deals with customer accounts, supplier purchases, employee salaries, and livestock records every day. When these are scattered across manual records or disconnected tools, billing errors creep in, payments are missed, and the owner cannot see the true financial picture of the business.

Proposed Solution

V2 is a rewrite of my 2025 Flask system into a typed full-stack application. A single dashboard manages customer ledgers, supplier purchases, payroll, and livestock, backed by PostgreSQL through Drizzle ORM with server-side money handling. Access is protected by Firebase session-based authentication, and invoices can be generated and shared straight from a phone.

Key Features

  • Customer billing and ledger tracking with detailed statements and payment history.
  • Supplier purchase management, payment tracking, and monthly statements.
  • Employee payroll with salary accruals, leave tracking, and deduction calculations.
  • Livestock and farm-supply records with dashboard statistics.
  • Printable invoices and statements with mobile share and download support.
  • Approval-based access: new users stay pending until an administrator activates them.

System Architecture Flow

Frontend (Next.js App Router, shadcn/ui) -> Server actions and route handlers -> Authentication (Firebase session and custom claims) -> Database layer (Drizzle ORM, Zod validation) -> PostgreSQL -> Invoice generation and sharing

Engineering Challenges

  • Sharing invoice images on mobile browsers produced blank output, which was fixed with Blob-based image generation, careful object URL cleanup, iOS warm-up rendering, and reduced pixel scaling.
  • Moving from Firestore to PostgreSQL required strict schema control, server-side money handling, and transaction-pooler compatibility work.
  • A finance-heavy app needed tight access control, so authorization is centralized through Firebase custom claims and server-side session checks, with an approval step for new users.

Lessons Learned

  • Schema-first database design makes business rules easier to enforce across finance-heavy workflows.
  • Mobile export and share features need explicit handling for browser and OS restrictions.
  • Rebuilding a working system means planning the migration path, not just the new features.

Results

Rebuilt in 2026 from the 2025 Flask version (Flask and SQLite) into a Next.js, TypeScript, and PostgreSQL system, documented with system architecture, design, and phase documents.