Skip to content

paper

Role: production Framework: Vite 8 + React 19 + TypeScript Backend: Cloudflare Pages Functions (D1 + R2) Deployment: Cloudflare Pages (paper.mcky.space) Stack: shadcn/ui, Tailwind v4, lucide-react, react-router v7

คำอธิบาย

ระบบจัดการเอกสารใบเสร็จ สำหรับจัดระเบียบและจัดการรูปภาพใบเสร็จ รองรับการอัปโหลดพร้อมบีบอัดรูปภาพ (WebP 2048px / 80%), จัดการหมวดหมู่, บันทึกโน้ต, ค้นหาแบบเต็มข้อความ, และ auth แบบรหัสผ่านเดียว

เทคโนโลยี

เลเยอร์เทคโนโลยี
FrontendVite 8, React 19, TypeScript 7, Tailwind 4
UIshadcn/ui (Radix primitives), lucide-react, framer-motion
Routingreact-router v7
Authรหัสผ่านเดียว (env var) + HMAC-SHA256 cookie
BackendCloudflare Pages Functions (Workers runtime)
DatabaseCloudflare D1 (receipts_db)
StorageCloudflare R2 (BUCKET)
Image ProcessingClient-side WebP via Canvas API

สถาปัตยกรรม

paper/
├── functions/                    # Cloudflare Pages Functions
│   └── api/
│       ├── _middleware.js        # Auth middleware (เช็ค HMAC cookie)
│       ├── auth/
│       │   ├── check.js          # GET /api/auth/check
│       │   ├── login.js          # POST /api/auth/login
│       │   └── logout.js         # POST /api/auth/logout
│       ├── categories.js         # GET/POST /api/categories
│       ├── categories/
│       │   └── [id].js           # PUT/DELETE /api/categories/:id
│       ├── file/
│       │   └── [id].js           # GET /api/file/:id (เสิร์ฟจาก R2)
│       ├── receipts.js           # GET /api/receipts
│       ├── receipts/
│       │   └── [id].js           # GET/PUT/DELETE /api/receipts/:id
│       └── upload.js             # POST /api/upload
├── src/
│   ├── App.tsx                   # Root: BrowserRouter, AuthProvider, routes
│   ├── main.tsx                  # จุดเริ่มต้น
│   ├── index.css                 # Tailwind + CSS variables theme
│   ├── components/
│   │   ├── bottom-nav.tsx        # Mobile bottom nav (ป้ายภาษาไทย)
│   │   ├── layout.tsx            # App shell (sidebar/bottom-nav + content)
│   │   ├── sidebar.tsx           # Desktop sidebar nav
│   │   ├── topbar.tsx            # Top bar (ปุ่มสลับ theme)
│   │   ├── theme-toggle.tsx      # สลับ dark/light
│   │   └── ui/                   # คอมโพเนนต์ shadcn/ui
│   ├── hooks/
│   │   ├── use-categories.ts     # hook ข้อมูลหมวดหมู่
│   │   └── use-receipts.ts       # hook ข้อมูลใบเสร็จ
│   ├── lib/
│   │   ├── api.ts                # API client
│   │   ├── auth-context.tsx      # Auth state provider
│   │   ├── theme-provider.tsx    # Theme context
│   │   ├── use-media-query.ts    # hook media query
│   │   └── utils.ts              # ฟังก์ชันช่วย (stripExtension, cn)
│   ├── pages/
│   │   ├── categories.tsx        # Category CRUD
│   │   ├── dashboard.tsx         # สถิติ + ใบเสร็จล่าสุด
│   │   ├── login.tsx             # เข้าสู่ระบบด้วยรหัสผ่าน
│   │   ├── receipt-detail.tsx    # preview + แก้ไขใบเสร็จ
│   │   ├── receipts.tsx          # รายการใบเสร็จ (มุมมอง table/card)
│   │   ├── settings.tsx          # Theme, สถิติการจัดเก็บ, logout
│   │   └── upload.tsx            # อัปโหลดพร้อมบีบอัด + ความคืบหน้า
│   ├── types/
│   │   └── index.ts              # interface ของ TypeScript
│   └── vite-env.d.ts             # Vite type declarations
├── schema.sql                    # นิยามตาราง D1
├── wrangler.toml                 # config Cloudflare Pages
├── vite.config.ts                # config Vite
└── package.json

SPA พร้อม Cloudflare Pages Functions เป็น backend เส้นทาง API ทั้งหมดใต้ /api/* ถูกป้องกันโดย _middleware.js ยกเว้น /api/auth/* Auth ใช้ HttpOnly cookie ที่เซ็นด้วย HMAC

จุดเริ่มต้น (Entry Points)

ไฟล์หน้าที่
src/main.tsxApp bootstrap
src/App.tsxRoot component, routing, auth guard
src/lib/auth-context.tsxAuth state management
src/lib/api.tsAPI client (fetch helper)
functions/api/_middleware.jsAuth middleware สำหรับเส้นทาง /api/* ทั้งหมด

การจัดการสถานะ

React state ผ่าน hooks (useReceipts, useCategories) Theme ผ่าน React context Auth ผ่าน AuthProvider context

การตัดสินใจหลัก

  • auth แบบรหัสผ่านเดียว (ไม่มีลงทะเบียนผู้ใช้) สำหรับใช้ส่วนตัว
  • บีบอัดรูปภาพฝั่ง client เป็น WebP ก่อนอัปโหลด (ลดการใช้พื้นที่)
  • HttpOnly cookie ที่เซ็นด้วย HMAC สำหรับรักษาสถานะ session
  • bottom nav บนมือถือ, sidebar บนเดสก์ท็อป

Development

คำสั่งการทำงาน
npm run devเริ่ม dev server
npm run buildProduction build ไปยัง ./public
npm run previewPreview build ผลลัพธ์
npx wrangler pages deploy --project-name receipts-dms ./publicDeploy ไป Cloudflare Pages
npx wrangler pages dev --port 8788 ./publicรัน Pages Functions แบบท้องถิ่น (ถ้า wrangler support)
npx wrangler d1 execute receipts-db --local --file=schema.sqlประยุกต์ schema แบบท้องถิ่น
npx wrangler d1 execute receipts-db --file=schema.sqlประยุกต์ schema บน Cloudflare
npx wrangler pages secret put AUTH_PASSWORD --project-name receipts-dmsตั้งรหัสผ่าน auth
npx wrangler pages secret put AUTH_SECRET --project-name receipts-dmsตั้ง HMAC secret สำหรับ auth

ตัวแปรสภาพแวดล้อม (Secrets)

ตัวแปรหน้าที่
AUTH_PASSWORDรหัสผ่านเดียวสำหรับเข้าสู่ระบบ
AUTH_SECRETคีย์ HMAC สำหรับเซ็น/ตรวจสอบ auth token

Dependencies

Runtime

แพ็กเกจเวอร์ชันหน้าที่
react^19.2.7UI framework
react-dom^19.2.7DOM renderer
react-router^7.18.1Client routing
@radix-ui/react-dialog^1.1.19Modal dialogs
@radix-ui/react-dropdown-menu^2.1.20Dropdown menus
@radix-ui/react-label^2.1.11Form labels
@radix-ui/react-progress^1.1.12Upload progress bar
@radix-ui/react-select^2.3.3Category select
@radix-ui/react-separator^1.1.11Visual separators
@radix-ui/react-slot^1.3.0Slot/as-child pattern
@radix-ui/react-tooltip^1.2.12Tooltips
class-variance-authority^0.7.1shadcn/ui utility
clsx^2.1.1Class name merging
cookie^1.1.1Cookie parsing
framer-motion^12.42.2Animation library
lucide-react^1.24.0Icons
sonner^2.0.7Toast notifications
tailwind-merge^3.6.0Tailwind class merging

Dev

แพ็กเกจเวอร์ชันหน้าที่
vite^8.0.0Build tool
@vitejs/plugin-react^5.0.0React plugin for Vite
typescript^7.0.2Type checking
tailwindcss^4.3.1CSS framework
@tailwindcss/vite^4.3.1Tailwind Vite plugin
@types/react^19.2.17React types
@types/react-dom^19.2.3React DOM types

Cloudflare

บริการBindingหน้าที่
D1receipts_dbฐานข้อมูล SQL (receipts, categories)
R2BUCKETการเก็บไฟล์ (รูปภาพใบเสร็จ)

ภายนอก

บริการหน้าที่
Cloudflare PagesHosting + Functions runtime
paper.mcky.spaceCustom domain

ที่เกี่ยวข้อง

ประเภทลิงก์
Statusstatus.md

หลักฐาน

  • package.json
  • wrangler.toml
  • vite.config.ts
  • schema.sql
  • src/lib/auth-context.tsx

Open Knowledge Framework