PetCare — 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
pets
GET /api/pets— List allGET /api/pets/:id— Get by IDPOST /api/pets— CreatePUT /api/pets/:id— UpdateDELETE /api/pets/:id— Delete
schedules
GET /api/schedules— List allGET /api/schedules/:id— Get by IDPOST /api/schedules— CreatePUT /api/schedules/:id— UpdateDELETE /api/schedules/:id— Delete
records
GET /api/records— List allGET /api/records/:id— Get by IDPOST /api/records— CreatePUT /api/records/:id— UpdateDELETE /api/records/:id— Delete
albums
GET /api/albums— List allGET /api/albums/:id— Get by IDPOST /api/albums— CreatePUT /api/albums/:id— UpdateDELETE /api/albums/:id— Delete
hospitals
GET /api/hospitals— List allGET /api/hospitals/:id— Get by IDPOST /api/hospitals— CreatePUT /api/hospitals/:id— UpdateDELETE /api/hospitals/:id— Delete
items
GET /api/items— List allGET /api/items/:id— Get by IDPOST /api/items— CreatePUT /api/items/:id— UpdateDELETE /api/items/:id— Delete
daily-logs
GET /api/daily-logs— List allGET /api/daily-logs/:id— Get by IDPOST /api/daily-logs— CreatePUT /api/daily-logs/:id— UpdateDELETE /api/daily-logs/:id— Delete
System
GET /api/health— Health check