# 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

#### 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
