3.5 KiB
3.5 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
foods
GET /api/foods— List allGET /api/foods/:id— Get by IDPOST /api/foods— CreatePUT /api/foods/:id— UpdateDELETE /api/foods/:id— Delete
customers
GET /api/customers— List allGET /api/customers/:id— Get by IDPOST /api/customers— CreatePUT /api/customers/:id— UpdateDELETE /api/customers/:id— Delete
meal_plans
GET /api/meal_plans— List allGET /api/meal_plans/:id— Get by IDPOST /api/meal_plans— CreatePUT /api/meal_plans/:id— UpdateDELETE /api/meal_plans/:id— Delete
nutrition
GET /api/nutrition— List allGET /api/nutrition/:id— Get by IDPOST /api/nutrition— CreatePUT /api/nutrition/:id— UpdateDELETE /api/nutrition/:id— Delete
shopping_lists
GET /api/shopping_lists— List allGET /api/shopping_lists/:id— Get by IDPOST /api/shopping_lists— CreatePUT /api/shopping_lists/:id— UpdateDELETE /api/shopping_lists/:id— Delete
templates
GET /api/templates— List allGET /api/templates/:id— Get by IDPOST /api/templates— CreatePUT /api/templates/:id— UpdateDELETE /api/templates/: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