Skip to content

RohitSharma50/voice-ration-ledger

Repository files navigation

๐Ÿ“’ Digital Khata โ€” Digital Ration Ledger

A voice-enabled digital ration ledger app for small shop owners to track customers and their ration entries, with phone OTP login via Twilio.


โœจ Features

  • ๐Ÿ“ฑ Phone OTP Login โ€” Secure login via Twilio SMS verification
  • ๐ŸŽ™๏ธ Voice Entry โ€” Add entries using voice commands in Hindi/English
    (e.g., "Ram Kumar 2 kg rice 60 rupees")
  • ๐Ÿ‘ฅ Customer Management โ€” Add, view, and manage customers
  • ๐Ÿ“‹ Ration Entries โ€” Track items, quantities, units, and prices per customer
  • ๐Ÿ” Search โ€” Quickly find customers by name
  • ๐Ÿ” Protected Routes โ€” Only authenticated users can access the app

๐Ÿ› ๏ธ Tech Stack

Layer Technology
Frontend React 18 + TypeScript + Vite
Styling Tailwind CSS + shadcn/ui
Backend Lovable Cloud (powered by Supabase)
Database PostgreSQL (via Lovable Cloud)
Edge Functions Deno (serverless, auto-deployed)
SMS Twilio API
State Management TanStack React Query

๐Ÿ“ฆ Prerequisites

Before you start, make sure you have:

  1. Node.js v18+ โ€” Download here or install via nvm
  2. npm (comes with Node.js) or bun (install bun)
  3. A Twilio Account โ€” Sign up free
    • Account SID (starts with AC...)
    • Auth Token
    • A Twilio phone number for sending SMS

๐Ÿš€ Step-by-Step Setup Guide

Step 1: Clone the Repository

git clone <YOUR_GIT_URL>
cd digital-khata

Step 2: Install Dependencies

npm install

Or if using bun:

bun install

Step 3: Environment Variables

The .env file is auto-configured by Lovable Cloud with these variables:

VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_PUBLISHABLE_KEY=your-anon-key
VITE_SUPABASE_PROJECT_ID=your-project-id

โš ๏ธ Do NOT commit .env to version control. It's already in .gitignore.

Step 4: Configure Twilio Secrets

In Lovable, go to Settings โ†’ Cloud โ†’ Secrets and add:

Secret Name Where to Find It
TWILIO_ACCOUNT_SID Twilio Console โ†’ Account SID
TWILIO_AUTH_TOKEN Twilio Console โ†’ Auth Token (click "Show")
TWILIO_PHONE_NUMBER Twilio Console โ†’ Phone Numbers โ†’ Your number (format: +1XXXXXXXXXX)

Step 5: Start the Development Server

npm run dev

The app will open at http://localhost:5173

Step 6: Test the App

  1. Open http://localhost:5173 in your browser
  2. Enter your phone number on the login screen
  3. You'll receive a 6-digit OTP via SMS
  4. Enter the OTP to log in
  5. Start adding customers and ration entries!

๐Ÿ“ Project Structure

digital-khata/
โ”œโ”€โ”€ public/                    # Static assets
โ”‚   โ”œโ”€โ”€ favicon.ico
โ”‚   โ””โ”€โ”€ robots.txt
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ components/            # Reusable UI components
โ”‚   โ”‚   โ”œโ”€โ”€ ui/                # shadcn/ui components
โ”‚   โ”‚   โ”œโ”€โ”€ AddCustomerDialog.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ AddEntryForm.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ CustomerCard.tsx
โ”‚   โ”‚   โ”œโ”€โ”€ GlobalVoiceEntry.tsx
โ”‚   โ”‚   โ””โ”€โ”€ NavLink.tsx
โ”‚   โ”œโ”€โ”€ contexts/
โ”‚   โ”‚   โ””โ”€โ”€ AuthContext.tsx     # Authentication state management
โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”‚   โ”œโ”€โ”€ useCustomers.ts    # Customer CRUD operations
โ”‚   โ”‚   โ”œโ”€โ”€ useRationEntries.ts # Entry CRUD operations
โ”‚   โ”‚   โ””โ”€โ”€ useVoiceInput.ts   # Browser speech recognition
โ”‚   โ”œโ”€โ”€ integrations/
โ”‚   โ”‚   โ””โ”€โ”€ supabase/
โ”‚   โ”‚       โ”œโ”€โ”€ client.ts      # Supabase client (auto-generated)
โ”‚   โ”‚       โ””โ”€โ”€ types.ts       # Database types (auto-generated)
โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”œโ”€โ”€ Index.tsx          # Home page (customer list)
โ”‚   โ”‚   โ”œโ”€โ”€ Login.tsx          # Phone OTP login page
โ”‚   โ”‚   โ”œโ”€โ”€ CustomerDetail.tsx # Individual customer view
โ”‚   โ”‚   โ””โ”€โ”€ NotFound.tsx       # 404 page
โ”‚   โ”œโ”€โ”€ App.tsx                # Root component with routing
โ”‚   โ”œโ”€โ”€ index.css              # Design tokens & global styles
โ”‚   โ””โ”€โ”€ main.tsx               # Entry point
โ”œโ”€โ”€ supabase/
โ”‚   โ”œโ”€โ”€ functions/
โ”‚   โ”‚   โ”œโ”€โ”€ send-otp/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ index.ts       # Edge function: send OTP via Twilio
โ”‚   โ”‚   โ””โ”€โ”€ verify-otp/
โ”‚   โ”‚       โ””โ”€โ”€ index.ts       # Edge function: verify OTP code
โ”‚   โ””โ”€โ”€ config.toml            # Supabase project config
โ”œโ”€โ”€ .env                       # Environment variables (auto-configured)
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tailwind.config.ts
โ”œโ”€โ”€ vite.config.ts
โ””โ”€โ”€ tsconfig.json

๐Ÿ—„๏ธ Database Schema

customers table

Column Type Default Description
id uuid auto Primary key
name text โ€” Customer name
phone text null Phone number (optional)
created_at timestamptz now() Creation timestamp
updated_at timestamptz now() Last update timestamp

ration_entries table

Column Type Default Description
id uuid auto Primary key
customer_id uuid โ€” FK โ†’ customers.id
item_name text โ€” Item name (e.g., "rice")
quantity numeric 1 Amount
unit text "kg" Unit (kg, g, litre, ml, piece, packet)
price numeric 0 Price in โ‚น
created_at timestamptz now() Entry timestamp

otp_codes table

Column Type Default Description
id uuid auto Primary key
phone text โ€” Phone number
code text โ€” 6-digit OTP
expires_at timestamptz โ€” Expires 5 min after creation
verified boolean false Whether verified
created_at timestamptz now() Creation timestamp

โšก Edge Functions

Function Method Description
send-otp POST Generates 6-digit OTP, stores in DB, sends via Twilio SMS
verify-otp POST Validates OTP against DB, marks as verified

Request examples:

# Send OTP
curl -X POST https://your-project.supabase.co/functions/v1/send-otp \
  -H "Content-Type: application/json" \
  -d '{"phone": "+919876543210"}'

# Verify OTP
curl -X POST https://your-project.supabase.co/functions/v1/verify-otp \
  -H "Content-Type: application/json" \
  -d '{"phone": "+919876543210", "code": "123456"}'

๐ŸŒ How to Publish / Deploy

Option 1: Lovable (Easiest โ€” Recommended)

  1. Open the project in Lovable
  2. Click Publish button (top-right corner)
  3. Click Update to deploy
  4. Your app is live at https://yourapp.lovable.app
  5. (Optional) Connect a custom domain:
    Go to Settings โ†’ Domains โ†’ Connect Domain

๐Ÿ’ก Backend (edge functions, database) deploys automatically. Frontend requires clicking "Update".

Option 2: Vercel

  1. Push your code to GitHub
  2. Go to vercel.com โ†’ Import your repo
  3. Set build command: npm run build
  4. Set output directory: dist
  5. Add environment variables (VITE_SUPABASE_URL, VITE_SUPABASE_PUBLISHABLE_KEY)
  6. Click Deploy

Option 3: Netlify

  1. Push your code to GitHub
  2. Go to netlify.com โ†’ Import from Git
  3. Build command: npm run build
  4. Publish directory: dist
  5. Add environment variables in Site Settings โ†’ Environment
  6. Deploy

Option 4: Manual Static Hosting

# Build for production
npm run build

# The 'dist/' folder contains your production-ready app
# Upload it to any static hosting (AWS S3, Cloudflare Pages, etc.)

๐ŸŽ™๏ธ Voice Commands Guide

The app supports Hindi and English voice commands. Format:

[Customer Name] [Quantity] [Unit] [Item] [Price] rupees

Examples:

  • "Ram Kumar 2 kg rice 60 rupees"
  • "เคฐเคฎเฅ‡เคถ เค•เฅเคฎเคพเคฐ 5 เค•เคฟเคฒเฅ‹ เค†เคŸเคพ 200 เคฐเฅเคชเคฏเฅ‡"
  • "Sita 1 litre oil 150 rupees"

Supported units: kg, g, litre, ml, piece, packet
Supported Hindi units: เค•เคฟเคฒเฅ‹, เค—เฅเคฐเคพเคฎ, เคฒเฅ€เคŸเคฐ, เคชเฅ€เคธ, เคชเฅˆเค•เฅ‡เคŸ


๐Ÿ”ง Available Scripts

Command Description
npm run dev Start development server
npm run build Build for production
npm run preview Preview production build locally
npm run lint Run ESLint
npm run test Run tests
npm run test:watch Run tests in watch mode

๐Ÿ› Troubleshooting

Issue Solution
OTP not received Check Twilio credentials in Cloud Secrets. Ensure phone number format is +91XXXXXXXXXX
"Failed to send SMS" Verify Twilio Account SID and Auth Token are correct
Login succeeds but no redirect Clear browser cache and try again
Voice not working Allow microphone permission in browser. Works best in Chrome
Customers not loading Check that the database tables exist and RLS policies are set

๐Ÿ“„ License

MIT

About

digital-khata book

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors