2.3 KiB
2.3 KiB
MealPrep — Backend API
一款支持商品浏览、购物车、在线支付和物流追踪的电商应用。
Tech Stack
- Runtime: Node.js
- Framework: Fastify 5
- Language: TypeScript
- Database: SQLite (better-sqlite3)
- Auth: JWT + bcrypt
Getting Started
# Install dependencies
npm install
# Development (hot reload)
npm run dev
# Build
npm run build
# Production start
npm run start
# Run tests
npm test
Project Structure
src/
├── index.ts # Server entry point
├── db/
│ ├── schema.ts # SQLite schema
│ └── client.ts # Database client
├── routes/
│ ├── auth.ts # Auth routes (register/login/me)
│ └── *.ts # CRUD routes
├── services/
│ └── *.ts # Business logic
├── middleware/
│ └── auth.ts # JWT middleware
├── types/
│ └── index.ts # TypeScript types
└── __tests__/
└── *.test.ts # Tests
API Endpoints
Auth
POST /api/auth/register— RegisterPOST /api/auth/login— LoginGET /api/auth/me— Current user (auth required)
Resources
users
GET /api/users— List allGET /api/users/:id— Get by IDPOST /api/users— CreatePUT /api/users/:id— UpdateDELETE /api/users/:id— Delete
products
GET /api/products— List allGET /api/products/:id— Get by IDPOST /api/products— CreatePUT /api/products/:id— UpdateDELETE /api/products/:id— Delete
orders
GET /api/orders— List allGET /api/orders/:id— Get by IDPOST /api/orders— CreatePUT /api/orders/:id— UpdateDELETE /api/orders/:id— Delete
order_items
GET /api/order_items— List allGET /api/order_items/:id— Get by IDPOST /api/order_items— CreatePUT /api/order_items/:id— UpdateDELETE /api/order_items/:id— Delete
logistics
GET /api/logistics— List allGET /api/logistics/:id— Get by IDPOST /api/logistics— CreatePUT /api/logistics/:id— UpdateDELETE /api/logistics/:id— Delete
System
GET /api/health— Health check