Skip to content

fadliaditama/split-bill-backend

Repository files navigation

Split Bill Backend

Backend API untuk aplikasi split bill yang memungkinkan pengguna mengunggah struk belanja, melakukan OCR, dan membagi tagihan dengan AI.

Fitur Utama

  • πŸ” Authentication & Authorization - JWT-based auth dengan user management
  • πŸ“Έ Image Upload - Upload gambar struk ke Supabase Storage
  • πŸ” OCR Processing - Ekstraksi teks dari gambar menggunakan Tesseract.js
  • πŸ€– AI Data Extraction - Parsing data struk menggunakan Google Gemini AI
  • πŸ’° Bill Management - CRUD operations untuk tagihan
  • πŸ‘₯ Split Bill - Fitur untuk membagi tagihan antar pengguna
  • πŸ—„οΈ Database - PostgreSQL dengan TypeORM

Tech Stack

  • Framework: NestJS
  • Database: PostgreSQL
  • ORM: TypeORM
  • Storage: Supabase Storage
  • OCR: Tesseract.js
  • AI: Google Gemini API
  • Authentication: JWT
  • Deployment: Vercel

Prerequisites

  • Node.js 18+
  • PostgreSQL database
  • Supabase account
  • Google Gemini API key

Environment Variables

Buat file .env di root directory dengan konfigurasi berikut:

# Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/split_bill_db

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-here
JWT_EXPIRES_IN=7d

# Supabase Configuration
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_KEY=your-supabase-anon-key

# Gemini AI Configuration
GEMINI_API_KEY=your-gemini-api-key-here

# Application Configuration
PORT=3000
NODE_ENV=development

Setup Project

1. Install Dependencies

npm install

2. Database Setup

Pastikan PostgreSQL database sudah berjalan dan buat database baru:

CREATE DATABASE split_bill_db;

3. Supabase Setup

  1. Buat project baru di Supabase
  2. Buat bucket storage dengan nama receipt-images
  3. Set bucket policy untuk public access
  4. Copy URL dan anon key ke file .env

4. Gemini API Setup

  1. Dapatkan API key dari Google AI Studio
  2. Copy API key ke file .env

Running the Application

Development Mode

npm run start:dev

Production Mode

npm run build
npm run start:prod

API Endpoints

Authentication

  • POST /auth/register - Register user baru
  • POST /auth/login - Login user
  • GET /auth/profile - Get user profile

OCR & Bills

  • POST /ocr/upload - Upload dan proses struk
  • GET /ocr/bills - Get semua tagihan user
  • GET /ocr/bills/:id - Get detail tagihan
  • PUT /ocr/bills/:id/split - Update split details
  • DELETE /ocr/bills/:id - Hapus tagihan

Project Structure

src/
β”œβ”€β”€ auth/                 # Authentication module
β”‚   β”œβ”€β”€ dto/             # Data transfer objects
β”‚   β”œβ”€β”€ entities/        # User entity
β”‚   β”œβ”€β”€ auth.controller.ts
β”‚   β”œβ”€β”€ auth.service.ts
β”‚   └── auth.module.ts
β”œβ”€β”€ ocr/                 # OCR & Bill management module
β”‚   β”œβ”€β”€ entities/        # Bill entity
β”‚   β”œβ”€β”€ ocr.controller.ts
β”‚   β”œβ”€β”€ ocr.service.ts
β”‚   β”œβ”€β”€ ocr.module.ts
β”‚   └── tesseract-fix.ts # Tesseract wrapper
β”œβ”€β”€ app.controller.ts     # Main app controller
β”œβ”€β”€ app.service.ts        # Main app service
β”œβ”€β”€ app.module.ts         # Root module
└── main.ts              # Application entry point

Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

Deployment

Vercel

Project ini sudah dikonfigurasi untuk deployment di Vercel dengan file vercel.json.

Environment Variables di Production

Pastikan semua environment variables sudah diset di dashboard Vercel:

  • DATABASE_URL
  • JWT_SECRET
  • SUPABASE_URL
  • SUPABASE_KEY
  • GEMINI_API_KEY

Troubleshooting

OCR Issues

  • Pastikan Tesseract worker sudah ter-load dengan benar
  • Check log untuk error messages
  • Pastikan gambar yang diupload valid dan readable

Supabase Issues

  • Verify bucket receipt-images sudah dibuat
  • Check bucket policies untuk public access
  • Verify API keys sudah benar

Gemini API Issues

  • Check API key validity
  • Verify quota dan rate limits
  • Check network connectivity

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

License

This project is licensed under the MIT License.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors