2.0 KiB
2.0 KiB
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
users
GET /api/users— List allGET /api/users/:id— Get by IDPOST /api/users— CreatePUT /api/users/:id— UpdateDELETE /api/users/:id— Delete
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
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