Karaoke-SvelteKit là ứng dụng đặt phòng karaoke full-stack, kết hợp public storefront, member flows có xác thực, và admin back office trong cùng một SvelteKit app. UI routing nằm ở SvelteKit, còn booking, loyalty, analytics, email verification, phân quyền, và quản trị vận hành đi qua tRPC.
| Layer | Công nghệ |
|---|---|
| Frontend | SvelteKit, Svelte 5 |
| Styling | Tailwind CSS v4, DaisyUI |
| API boundary | tRPC |
| Validation | Zod |
| Authentication | Better Auth |
| Database | PostgreSQL |
| ORM | Drizzle ORM, Drizzle Kit |
| Resend | |
| Tooling | Vite, TypeScript |
| Testing infrastructure | Vitest, Playwright provider |
Luồng request chính là hooks.server.ts -> event.locals -> createContext -> SvelteKit loads hoặc tRPC procedures. Better Auth resolve session một lần ở hook, sau đó page loads và tRPC cùng dùng chung user và session.
Phần backend đi theo layering:
router -> controller -> service -> repository -> db
Các domain quan trọng như booking, loyalty, pricing, promotion, review, dashboard, branch, setting, và user đều bám theo flow này. Authorization được tập trung ở reusable procedures như publicProcedure, protectedProcedure, staffProcedure, managerProcedure, adminProcedure, và rateLimitedProcedure.
src/
routes/ SvelteKit pages, layouts, HTTP endpoints
lib/components/ Shared UI components
lib/stores/ Shared client stores
lib/trpc/ Browser tRPC client wrapper
lib/server/
routes/ tRPC routers
controllers/ Thin orchestration layer
services/ Business logic
repositories/ Drizzle-backed data access
db/schema/ Database schema and relations
trpc/ Context, auth guards, rate limiting
drizzle/ Generated migrations
docs/project-report/ Academic and technical report bundle
static/ Static assets
GET /api/export/bookings để export CSVCác điểm đã được code evidencing:
static/uploads, tức là deployment cần writable local disk nếu giữ nguyên thiết kế nàyỨng dụng hiện dùng các biến môi trường sau trong .env:
APP_DATABASE_URI="postgres://user:password@host:port/db-name"
APP_ORIGIN_URL=""
APP_BETTER_SECRET=""
RESEND_API_KEY=""
RESEND_FROM_EMAIL=""
RESEND_FROM_NAME="KaraSystem"
RESEND_REPLY_TO=""
APP_DATABASE_URI là bắt buộc ngay từ startup. Email-related variables là bắt buộc cho các flow gửi mail như verification và booking notification.
npm install
cp .env.example .env
Điền giá trị phù hợp vào .env, chuẩn bị PostgreSQL, sau đó chạy một trong các flow schema sau:
npm run db:push
# hoặc
npm run db:migrate
Nếu cần seed dữ liệu:
npm run db:seed
Khởi động development server:
npm run dev
npm run dev
npm run build
npm run preview
npm run check
npm run test
npm run db:push
npm run db:migrate
npm run db:generate
npm run db:seed
npm run db:studio
npm run auth:schema
Thư mục docs/project-report là bộ tài liệu học thuật và kỹ thuật đầy đủ cho dự án. Nên đọc theo thứ tự sau:
project_overview.mdarchitecture.mdbusiness_analysis.mdsystem_analysis_and_design.mddeveloper_guide.mdCác tài liệu còn lại trong bundle:
index.md: mục lục và phạm vi tài liệucomponents.md: breakdown frontend, backend, shared modulesinterfaces.md: internal boundaries và integration surfacesapi_documentation.md: tRPC procedures và HTTP endpointsdata_models.md: domain entitiesdatabase_design.md: physical schema designworkflows.md: technical execution flowsuser_workflows.md: end-user journeyssecurity_and_performance.md: security/performance reviewtesting_and_evaluation.md: test reality và evaluation guidancedeployment_and_operations.md: deployment assumptions và operational constraintsfeature_breakdown.md: feature-by-feature analysisdependencies.md: dependency rationalediagrams.md: catalog Mermaid diagramscodebase_info.md: repository inventoryreview_notes.md: gaps, inconsistencies, technical debtthesis_report_outline.md: gợi ý cấu trúc báo cáo tốt nghiệptrpc().SRS.md; ưu tiên code hiện tại và bundle trong docs/project-report.