Docker Compose setup để chạy OCR Service độc lập với PostgreSQL và RabbitMQ.
- QR Code Scanning: Hỗ trợ quét mã QR trên hóa đơn điện tử Việt Nam (theo chuẩn Tổng cục Thuế)
- OCR Text Recognition: Nhận diện văn bản từ ảnh hóa đơn (Tiếng Anh + Tiếng Việt)
- QR-First Approach: Ưu tiên quét QR (độ chính xác ~98%), fallback sang OCR nếu không tìm thấy
- Automatic Expense Creation: Tự động tạo khoản chi sau khi quét thành công
- RabbitMQ Integration: Xử lý bất đồng bộ với message queue
Định dạng hỗ trợ: Hóa đơn điện tử Việt Nam (pipe-separated format)
Dữ liệu trích xuất từ QR:
- Số hóa đơn (Invoice Number)
- Tên người bán (Seller Name)
- Mã số thuế (Tax Code)
- Tổng tiền thanh toán (Total Payment)
- Ngày hóa đơn (Invoice Date)
- Mã tra cứu (Lookup Code)
Ví dụ định dạng QR:
01GTKT0/001|AA/19E|0000123|09/01/2026|0123456789|CÔNG TY ABC|9876543210|KHÁCH HÀNG XYZ|1000000|100000|1100000|ABC123XYZ
# 1. Tạo .env file
cp .env.example .env
# 2. Start services (Docker sẽ tự động npm install)
docker-compose up -d --build
# 3. Run Prisma migration
docker-compose exec ocr-service npx prisma generate
docker-compose exec ocr-service npx prisma db push
# 4. Verify
# - OCR Service: http://localhost:3007
# - RabbitMQ UI: http://localhost:15672 (fepa/fepa123)# 1. Install dependencies
npm install
# 2. Tạo .env file
cp .env.example .env
# 3. Start service locally
npm run start:dev💡 Lưu ý: Chỉ cần
npm installkhi chạy local. Docker tự động cài đặt dependencies!
| Service | Port | Description |
|---|---|---|
| ocr-service | 3007 | OCR microservice with QR scanning |
| postgres | 5432 | PostgreSQL database |
| rabbitmq | 5672, 15672 | RabbitMQ message broker |
- Uncomment
command: npm run start:devindocker-compose.yml - Restart:
docker-compose restart ocr-service
# All services
docker-compose logs -f
# OCR service only
docker-compose logs -f ocr-service-
Start API Gateway separately:
cd ../api-gateway docker-compose up -d -
Test via API Gateway:
# Get JWT token first POST http://localhost:3000/api/v1/auth/login # Create OCR job POST http://localhost:3000/api/v1/ocr/scan Authorization: Bearer YOUR_TOKEN { "fileUrl": "https://example.com/receipt.jpg" }
OCR service listens on RabbitMQ ocr_queue. You can send messages directly:
// Using amqplib
const message = {
pattern: 'ocr.scan',
data: {
fileUrl: 'https://example.com/receipt.jpg',
userId: 'user-uuid'
}
};# Via Docker
docker-compose exec postgres psql -U fepa -d fepa_ocr
# List tables
\dt
# View OcrJob table
SELECT * FROM "OcrJob";docker-compose exec ocr-service npx prisma studiodocker-compose up -ddocker-compose downdocker-compose up -d --builddocker-compose down -vdocker-compose logs -f ocr-servicedocker-compose exec ocr-service shProblem: P1000: Authentication failed
Solution:
- Ensure PostgreSQL is running:
docker-compose ps postgres - Check DATABASE_URL in
.env - Recreate database:
docker-compose down -v docker-compose up -d postgres # Wait 10 seconds docker-compose up -d ocr-service
Problem: Cannot connect to RabbitMQ
Solution:
- Check RabbitMQ is healthy:
docker-compose ps rabbitmq - View logs:
docker-compose logs rabbitmq - Restart:
docker-compose restart rabbitmq
Problem: Tables not created
Solution:
docker-compose exec ocr-service npx prisma db push --force-resetServices communicate via fepa-network. To connect with other services:
# In other service's docker-compose.yml
networks:
fepa-network:
external: trueThen start this service first to create the network.
postgres_data: PostgreSQL data persistencerabbitmq_data: RabbitMQ data persistence
docker run --rm -v ocr-service_postgres_data:/data -v $(pwd):/backup alpine tar czf /backup/postgres-backup.tar.gz -C /data .docker run --rm -v ocr-service_postgres_data:/data -v $(pwd):/backup alpine tar xzf /backup/postgres-backup.tar.gz -C /data-
Change credentials in
docker-compose.yml:environment: - POSTGRES_PASSWORD=your_secure_password - RABBITMQ_DEFAULT_PASS=your_secure_password
-
Update
.env:DATABASE_URL="postgresql://fepa:your_secure_password@postgres:5432/fepa_ocr" RABBITMQ_URL=amqp://fepa:your_secure_password@rabbitmq:5672
-
Don't expose ports publicly (remove port mappings or use firewall)