140 lines
3.5 KiB
Markdown
140 lines
3.5 KiB
Markdown
# MealPrep — Backend API
|
|
|
|
> 一款支持商品浏览、购物车、在线支付和物流追踪的电商应用。
|
|
|
|
## Tech Stack
|
|
|
|
- **Runtime**: Node.js
|
|
- **Framework**: Fastify 5
|
|
- **Language**: TypeScript
|
|
- **Database**: SQLite (better-sqlite3)
|
|
- **Auth**: JWT + bcrypt
|
|
|
|
## Getting Started
|
|
|
|
```bash
|
|
# 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` — Register
|
|
- `POST /api/auth/login` — Login
|
|
- `GET /api/auth/me` — Current user (auth required)
|
|
|
|
### Resources
|
|
#### users
|
|
- `GET /api/users` — List all
|
|
- `GET /api/users/:id` — Get by ID
|
|
- `POST /api/users` — Create
|
|
- `PUT /api/users/:id` — Update
|
|
- `DELETE /api/users/:id` — Delete
|
|
|
|
#### foods
|
|
- `GET /api/foods` — List all
|
|
- `GET /api/foods/:id` — Get by ID
|
|
- `POST /api/foods` — Create
|
|
- `PUT /api/foods/:id` — Update
|
|
- `DELETE /api/foods/:id` — Delete
|
|
|
|
#### customers
|
|
- `GET /api/customers` — List all
|
|
- `GET /api/customers/:id` — Get by ID
|
|
- `POST /api/customers` — Create
|
|
- `PUT /api/customers/:id` — Update
|
|
- `DELETE /api/customers/:id` — Delete
|
|
|
|
#### meal_plans
|
|
- `GET /api/meal_plans` — List all
|
|
- `GET /api/meal_plans/:id` — Get by ID
|
|
- `POST /api/meal_plans` — Create
|
|
- `PUT /api/meal_plans/:id` — Update
|
|
- `DELETE /api/meal_plans/:id` — Delete
|
|
|
|
#### nutrition
|
|
- `GET /api/nutrition` — List all
|
|
- `GET /api/nutrition/:id` — Get by ID
|
|
- `POST /api/nutrition` — Create
|
|
- `PUT /api/nutrition/:id` — Update
|
|
- `DELETE /api/nutrition/:id` — Delete
|
|
|
|
#### shopping_lists
|
|
- `GET /api/shopping_lists` — List all
|
|
- `GET /api/shopping_lists/:id` — Get by ID
|
|
- `POST /api/shopping_lists` — Create
|
|
- `PUT /api/shopping_lists/:id` — Update
|
|
- `DELETE /api/shopping_lists/:id` — Delete
|
|
|
|
#### templates
|
|
- `GET /api/templates` — List all
|
|
- `GET /api/templates/:id` — Get by ID
|
|
- `POST /api/templates` — Create
|
|
- `PUT /api/templates/:id` — Update
|
|
- `DELETE /api/templates/:id` — Delete
|
|
|
|
#### products
|
|
- `GET /api/products` — List all
|
|
- `GET /api/products/:id` — Get by ID
|
|
- `POST /api/products` — Create
|
|
- `PUT /api/products/:id` — Update
|
|
- `DELETE /api/products/:id` — Delete
|
|
|
|
#### orders
|
|
- `GET /api/orders` — List all
|
|
- `GET /api/orders/:id` — Get by ID
|
|
- `POST /api/orders` — Create
|
|
- `PUT /api/orders/:id` — Update
|
|
- `DELETE /api/orders/:id` — Delete
|
|
|
|
#### order_items
|
|
- `GET /api/order_items` — List all
|
|
- `GET /api/order_items/:id` — Get by ID
|
|
- `POST /api/order_items` — Create
|
|
- `PUT /api/order_items/:id` — Update
|
|
- `DELETE /api/order_items/:id` — Delete
|
|
|
|
#### logistics
|
|
- `GET /api/logistics` — List all
|
|
- `GET /api/logistics/:id` — Get by ID
|
|
- `POST /api/logistics` — Create
|
|
- `PUT /api/logistics/:id` — Update
|
|
- `DELETE /api/logistics/:id` — Delete
|
|
|
|
### System
|
|
- `GET /api/health` — Health check
|