A full-stack web application for mobile bank receipt processing with OCR, review interface, database storage, Google Sheets export, and RAG-powered chatbot.
- OCR Processing: Extract text from Thai bank receipts using Tesseract OCR
- Template-Based OCR: Customizable zone-based OCR templates for different receipt formats
- Review Interface: View and edit OCR results with zone overlay visualization
- Batch Upload: Process multiple receipts at once with drag-and-drop
- Transaction Classification: Auto-classify transactions as income/expense
- Database Storage: Store receipts in PostgreSQL with full CRUD operations
- RAG Chatbot: Query receipt data using AI with semantic search (ChromaDB + Gemini)
- Analytics Dashboard: Visualize spending patterns and insights with interactive charts
- Export Options: Export to Google Sheets or Excel files
- User Authentication: JWT-based auth with login/register
- Admin Panel: User management and system oversight
- Income Tracking: Track and categorize income sources
- Salary Management: Manage salary records
- Auto-Cleanup: Automatically delete receipt images after confirmation
- React 18 + TypeScript
- Vite (build tool)
- React Router v6 (routing)
- Axios + React Query (data fetching)
- Tailwind CSS (styling)
- Recharts (data visualization)
- React Hook Form + Zod (forms & validation)
- Lucide React (icons)
- React Dropzone (file uploads)
- Python 3.10+ / FastAPI
- PostgreSQL (database)
- SQLAlchemy (ORM)
- Alembic (migrations)
- Tesseract OCR (OCR engine)
- ChromaDB (vector store for RAG)
- Google Generative AI SDK (Gemini)
- Groq (alternative LLM provider)
- Openpyxl (Excel export)
- JWT + Passlib (authentication)
- Python 3.10 or higher
- Node.js 18 or higher
- Docker and Docker Compose
- Google Cloud account (for Gemini API)
- Groq account (for alternative LLM)
cd ocr-bank2cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your API keys and configuration
# Start PostgreSQL
docker compose up -d
# Run database migrations
alembic upgrade head
# Create admin user (optional)
python change_admin.py
# Start the server
uvicorn app.main:app --reloadThe API will be available at http://localhost:8000
API Documentation:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
cd frontend
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# The default configuration should work for local development
# Start development server
npm run devThe application will be available at http://localhost:5173
# Database
DATABASE_URL=postgresql://ocr_bank_user:ocr_bank_password@localhost:5432/ocr_bank
# OCR
OCR_LANGUAGE=th # Thai language
OCR_DEVICE=cpu # or gpu if available
# LLM (Primary: Gemini)
GEMINI_API_KEY=your_gemini_api_key
LLM_PROVIDER=gemini
# LLM (Alternative: Groq)
GROQ_API_KEY=your_groq_api_key
# Vector Store
CHROMADB_PERSIST_DIRECTORY=./data/chromadb
# Google Sheets (optional)
GOOGLE_SHEETS_CREDENTIALS_PATH=./config/credentials.json
GOOGLE_SHEETS_SPREADSHEET_ID=your_spreadsheet_id
# File Storage
IMAGE_STORAGE_PATH=./images
MAX_UPLOAD_SIZE=10485760 # 10MB
# Authentication
SECRET_KEY=your_secret_key_here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
# Auto-cleanup
AUTO_DELETE_IMAGES=true # Delete images after confirmationVITE_API_BASE_URL=http://localhost:8000/apiocr-bank2/
├── backend/
│ ├── app/
│ │ ├── main.py # FastAPI application
│ │ ├── config.py # Configuration
│ │ ├── api/ # API routes
│ │ │ ├── auth.py # Authentication endpoints
│ │ │ ├── upload.py # Upload & OCR endpoints
│ │ │ ├── receipts.py # Receipt CRUD
│ │ │ ├── chat.py # RAG chatbot
│ │ │ ├── export.py # Export endpoints
│ │ │ ├── analytics.py # Analytics endpoints
│ │ │ ├── admin.py # Admin panel
│ │ │ ├── income.py # Income tracking
│ │ │ ├── salary.py # Salary management
│ │ │ ├── templates.py # OCR templates
│ │ │ ├── ocr_corrections.py # OCR corrections
│ │ │ ├── cleanup.py # Auto-cleanup
│ │ │ └── user_settings.py # User preferences
│ │ ├── models/ # Database models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── services/ # Business logic
│ │ │ ├── ocr_service.py # PaddleOCR wrapper
│ │ │ ├── template_ocr_service.py # Template-based OCR
│ │ │ ├── template_manager.py # Template management
│ │ │ ├── zone_extractor.py # Zone extraction
│ │ │ ├── rag_service.py # RAG implementation
│ │ │ ├── vector_store.py # Vector store operations
│ │ │ ├── vlm_service.py # Vision-language model
│ │ │ ├── gemini_vlm_service.py # Gemini VLM
│ │ │ ├── transaction_classifier.py # Transaction classification
│ │ │ ├── text_cleaning_service.py # Text cleaning
│ │ │ ├── auth_service.py # Authentication
│ │ │ └── excel_export_service.py # Excel export
│ │ └── database/ # Database configuration
│ ├── requirements.txt
│ ├── alembic.ini
│ └── docker-compose.yml
│
├── frontend/
│ ├── src/
│ │ ├── pages/ # Page components
│ │ │ ├── Login.tsx # Login page
│ │ │ ├── Register.tsx # Registration page
│ │ │ ├── Dashboard.tsx # Dashboard (layout)
│ │ │ ├── Upload.tsx # Upload page
│ │ │ ├── Review.tsx # Review page with zone overlay
│ │ │ ├── ReceiptsList.tsx # Receipt list with filters
│ │ │ ├── Chat.tsx # RAG chatbot
│ │ │ ├── Analytics.tsx # Analytics dashboard
│ │ │ ├── Export.tsx # Export page
│ │ │ ├── Settings.tsx # User settings
│ │ │ └── Admin.tsx # Admin panel
│ │ ├── components/ # Reusable components
│ │ │ ├── ProtectedRoute.tsx # Auth wrapper
│ │ │ ├── ZoneOverlay.tsx # Zone visualization
│ │ │ └── ErrorBoundary.tsx # Error handling
│ │ ├── services/ # API service layer
│ │ │ ├── api.ts # Base API client
│ │ │ ├── authService.ts # Auth API
│ │ │ ├── receiptService.ts # Receipt API
│ │ │ ├── analyticsService.ts # Analytics API
│ │ │ ├── exportService.ts # Export API
│ │ │ └── userService.ts # User API
│ │ ├── types/ # TypeScript types
│ │ └── utils/ # Utility functions
│ ├── package.json
│ └── vite.config.ts
│
└── README.md
POST /api/auth/register- Register new userPOST /api/auth/login- Login and get access tokenGET /api/auth/me- Get current user infoPUT /api/auth/me- Update current user
POST /api/upload/- Upload receipt images (batch)POST /api/upload/process-ocr/{id}- Re-process OCR for receiptPOST /api/upload/process-with-template- Process with templatePOST /api/upload/crop-and-process- Crop zone and process
GET /api/receipts/- List receipts (with filters and pagination)GET /api/receipts/{id}- Get receipt detailsPUT /api/receipts/{id}- Update receiptPOST /api/receipts/{id}/confirm- Mark as confirmedDELETE /api/receipts/{id}- Delete receiptGET /api/receipts/stats/overview- Get statistics
POST /api/templates/- Create templateGET /api/templates/- List templatesGET /api/templates/{id}- Get templatePUT /api/templates/{id}- Update templateDELETE /api/templates/{id}- Delete templatePOST /api/templates/{id}/apply- Apply template to image
POST /api/chat/query- Query receipt data with RAGPOST /api/chat/reset- Reset chat context
GET /api/analytics/overview- Get overview statisticsGET /api/analytics/spending-by-category- Spending by categoryGET /api/analytics/monthly-trends- Monthly spending trends
POST /api/export/excel- Export to ExcelPOST /api/export/google-sheets- Export to Google Sheets
GET /api/admin/users- List all usersPUT /api/admin/users/{id}/role- Update user roleDELETE /api/admin/users/{id}- Delete user
GET /api/income/- List income recordsPOST /api/income/- Create income recordGET /api/salary/- List salary recordsPOST /api/salary/- Create salary record
Backend:
cd backend
pytestFrontend:
cd frontend
npm run lintCreate a new migration:
cd backend
alembic revision --autogenerate -m "description"Apply migrations:
alembic upgrade headRollback migration:
alembic downgrade -1# Check if PostgreSQL container is running
docker compose ps
# Restart PostgreSQL
docker compose restart
# View logs
docker compose logs postgres# Make sure Tesseract OCR is installed on your system
# macOS: brew install tesseract
# Ubuntu: sudo apt install tesseract-ocr
# Windows: Download from https://github.com/UB-Mannheim/tesseract/wiki
# For Thai language support, install Thai language pack
# macOS: brew install tesseract-lang
# Ubuntu: sudo apt install tesseract-ocr-tha# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm installThis project is for educational purposes.
This is a student project. Feel free to fork and modify for your own use.