azmaeenmahtab/Khujo-backend

GitHub: azmaeenmahtab/Khujo-backend

一个集成多阶段文档验证流水线的被盗手机举报与 IMEI 查询后端系统,通过 EXIF、ELA、Vision LLM 和 OCR 技术自动鉴别警方报案文件真伪。

Stars: 0 | Forks: 0

# 📵 KHUJO — 后端 一个为孟加拉国构建的、基于文件验证的盗窃手机举报与 IMEI 查询系统。用户可以通过上传警方 GD 副本来举报被盗手机,该报告将经过多阶段自动验证流水线,随后该手机的 IMEI 才会被录入被盗设备数据库。 ## 🔍 功能简介 - 接受包含**警方 GD 副本**、IMEI 号码、被盗地点以及可选的手机包装盒照片的盗窃报告 - 将 GD 文档通过**多阶段验证流水线**(EXIF → ELA → Vision LLM → OCR → IMEI 匹配 → 重复项检查)进行处理 - 将置信度较低的案例引导至**管理员审核队列** - 将验证通过的被盗 IMEI 录入数据库 - 提供**公开的 IMEI 查询 API**,以便买家在购买前检查二手手机 ## 🧰 技术栈 ### 核心后端 ![Node.js](https://img.shields.io/badge/Node.js-339933?style=for-the-badge&logo=node.js&logoColor=white) ![Express](https://img.shields.io/badge/Express.js-000000?style=for-the-badge&logo=express&logoColor=white) ![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?style=for-the-badge&logo=typescript&logoColor=white) ### 数据库 ![PostgreSQL](https://img.shields.io/badge/PostgreSQL-4169E1?style=for-the-badge&logo=postgresql&logoColor=white) ![Redis](https://img.shields.io/badge/Redis-DC382D?style=for-the-badge&logo=redis&logoColor=white) ### 文档验证流水线 ![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge&logo=python&logoColor=white) ![OpenCV](https://img.shields.io/badge/OpenCV-5C3EE8?style=for-the-badge&logo=opencv&logoColor=white) ![Pillow](https://img.shields.io/badge/Pillow-FFD43B?style=for-the-badge&logo=python&logoColor=black) ### AI / ML ![OpenAI](https://img.shields.io/badge/GPT--4o_Vision-412991?style=for-the-badge&logo=openai&logoColor=white) ![EasyOCR](https://img.shields.io/badge/EasyOCR-Bengali%20%2B%20English-blue?style=for-the-badge) ![HuggingFace](https://img.shields.io/badge/HuggingFace-FFD21E?style=for-the-badge&logo=huggingface&logoColor=black) ### 存储与基础设施 ![AWS S3](https://img.shields.io/badge/AWS_S3-FF9900?style=for-the-badge&logo=amazons3&logoColor=white) ![Docker](https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white) ## 🏗️ 验证流水线 每份盗窃报告在被批准之前,都需要经过 8 个顺序执行的阶段: ``` Report Submitted │ ▼ ┌─────────────────────────────────────────────┐ │ Stage 1 — EXIF Metadata Check │ │ GPS coords, timestamp, device model │ │ Tool: ExifRead (Python) │ └──────────────────────┬──────────────────────┘ │ pass ▼ ┌─────────────────────────────────────────────┐ │ Stage 2 — ELA Tamper Detection │ │ JPEG re-compression artifact analysis │ │ Tool: Pillow / OpenCV │ └──────────────────────┬──────────────────────┘ │ pass ▼ ┌─────────────────────────────────────────────┐ │ Stage 3 — Vision LLM Structure Check │ │ GD header, seal, station format validation │ │ Model: GPT-4o Vision / Claude │ └──────────────────────┬──────────────────────┘ │ pass ▼ ┌─────────────────────────────────────────────┐ │ Stage 4 — OCR Text Extraction │ │ Extract IMEI, GD number, date from doc │ │ Tool: EasyOCR (Bengali + English) │ └──────────────────────┬──────────────────────┘ │ ▼ ┌─────────────────────────────────────────────┐ │ Stage 5 — IMEI Match │ │ OCR-extracted IMEI == submitted IMEI │ └──────────────────────┬──────────────────────┘ │ match ▼ ┌─────────────────────────────────────────────┐ │ Stage 6 — Duplicate / Spam Check │ │ Same IMEI, GD number, or user fingerprint │ │ Tool: PostgreSQL query │ └──────────────────────┬──────────────────────┘ │ unique ▼ ┌─────────────────────────────────────────────┐ │ Stage 7 — Confidence Score Routing │ │ High confidence → auto approve │ │ Low confidence → admin review queue │ └──────────────────────┬──────────────────────┘ │ approved ▼ ┌─────────────────────────────────────────────┐ │ Stage 8 — Verified & Indexed │ │ IMEI stored in stolen device database │ │ User notified, public lookup enabled │ └─────────────────────────────────────────────┘ ``` ## 📡 API Endpoints ### 举报提交 ``` POST /api/v1/reports Content-Type: multipart/form-data Fields: gd_copy File (required) — scanned GD document image imei String (required) — 15-digit IMEI number theft_location String (required) — district / area phone_box File (optional) — photo of phone box ``` ### 举报状态 ``` GET /api/v1/reports/:reportId/status ``` ### 公开 IMEI 查询 ``` GET /api/v1/lookup?imei=<15-digit-imei> Response: { "imei": "358765000000000", "status": "stolen" | "clear", "reported_at": "2025-03-12T09:40:00Z", // only if stolen "theft_location": "Dhaka, Mirpur" // only if stolen } ``` ### 管理员审核队列 ``` GET /api/v1/admin/queue POST /api/v1/admin/queue/:reportId/approve POST /api/v1/admin/queue/:reportId/reject ``` ## 📁 项目结构 ``` mobilesentry-backend/ ├── src/ │ ├── routes/ │ │ ├── reports.ts # Submission and status endpoints │ │ ├── lookup.ts # Public IMEI lookup │ │ └── admin.ts # Admin review queue │ ├── pipeline/ │ │ ├── exifCheck.ts # Stage 1 — EXIF metadata │ │ ├── elaDetection.py # Stage 2 — ELA tamper detection │ │ ├── visionLLM.ts # Stage 3 — GPT-4o structure check │ │ ├── ocrExtract.py # Stage 4 — EasyOCR extraction │ │ ├── imeiMatch.ts # Stage 5 — IMEI comparison │ │ ├── duplicateCheck.ts # Stage 6 — Duplicate detection │ │ └── confidenceRouter.ts # Stage 7 — Routing logic │ ├── models/ │ │ ├── Report.ts │ │ └── StolenDevice.ts │ ├── services/ │ │ ├── storage.ts # S3 file uploads │ │ ├── notify.ts # User notifications │ │ └── queue.ts # Admin queue management │ ├── middleware/ │ │ ├── auth.ts │ │ └── upload.ts # Multer config │ └── app.ts ├── python/ │ ├── ela_detect.py │ └── ocr_extract.py ├── prisma/ │ └── schema.prisma ├── docker-compose.yml ├── Dockerfile └── .env.example ``` ## ⚙️ 环境变量 ``` # Server PORT=3000 NODE_ENV=development # Database DATABASE_URL=postgresql://user:password@localhost:5432/mobilesentry # Redis REDIS_URL=redis://localhost:6379 # AI / Vision OPENAI_API_KEY=your_openai_key # AWS S3 AWS_ACCESS_KEY_ID=your_key AWS_SECRET_ACCESS_KEY=your_secret AWS_S3_BUCKET=mobilesentry-uploads AWS_REGION=ap-south-1 # Admin ADMIN_SECRET=your_admin_secret ``` ## 🚀 快速开始 ### 前置条件 - Node.js v20+ - Python 3.10+ - PostgreSQL 15+ - Docker(可选,但推荐) ### 使用 Docker ``` git clone https://github.com/your-username/mobilesentry-backend.git cd mobilesentry-backend cp .env.example .env docker-compose up --build ``` ### 手动设置 ``` # 安装 Node 依赖 npm install # 安装 Python 依赖 pip install pillow easyocr exifread opencv-python # 运行数据库迁移 npx prisma migrate dev # 启动 Server npm run dev ``` ## 🛡️ 安全说明 - 所有 GD 文档上传均私密存储于 S3 中——绝不公开访问 - IMEI 查询仅返回最少量的数据(无用户信息,无 GD 详细信息),以保护举报人的隐私 - 所有公开 endpoint 均通过 Redis 进行速率限制 - 管理 endpoint 需要基于 token 的身份验证 ## 🗺️ 路线图 - [ ] 针对孟加拉国警方 GD 格式微调的分类器(HuggingFace ViT) - [ ] 用于报告状态更新的 SMS 通知 - [ ] 移动应用(优先支持 Android — React Native) - [ ] BTRC IMEI 数据库交叉引用集成 - [ ] 多语言支持(বাংলা 界面) ## 📄 许可证 MIT 许可证 — 详情请参阅 [LICENSE](./LICENSE)。
标签:MITM代理, PostgreSQL, 光学字符识别, 后端开发, 图像分析, 搜索引擎查询, 文档防伪, 测试用例, 视觉大模型, 请求拦截, 逆向工具, 防盗防欺诈