119 lines
2.9 KiB
Markdown
119 lines
2.9 KiB
Markdown
# MyProject — 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
|
|
#### contracts
|
|
- `GET /api/contracts` — List all
|
|
- `GET /api/contracts/:id` — Get by ID
|
|
- `POST /api/contracts` — Create
|
|
- `PUT /api/contracts/:id` — Update
|
|
- `DELETE /api/contracts/:id` — Delete
|
|
|
|
#### approvals
|
|
- `GET /api/approvals` — List all
|
|
- `GET /api/approvals/:id` — Get by ID
|
|
- `POST /api/approvals` — Create
|
|
- `PUT /api/approvals/:id` — Update
|
|
- `DELETE /api/approvals/: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
|
|
|
|
#### reminders
|
|
- `GET /api/reminders` — List all
|
|
- `GET /api/reminders/:id` — Get by ID
|
|
- `POST /api/reminders` — Create
|
|
- `PUT /api/reminders/:id` — Update
|
|
- `DELETE /api/reminders/:id` — Delete
|
|
|
|
#### services
|
|
- `GET /api/services` — List all
|
|
- `GET /api/services/:id` — Get by ID
|
|
- `POST /api/services` — Create
|
|
- `PUT /api/services/:id` — Update
|
|
- `DELETE /api/services/:id` — Delete
|
|
|
|
#### appointments
|
|
- `GET /api/appointments` — List all
|
|
- `GET /api/appointments/:id` — Get by ID
|
|
- `POST /api/appointments` — Create
|
|
- `PUT /api/appointments/:id` — Update
|
|
- `DELETE /api/appointments/:id` — Delete
|
|
|
|
#### clients
|
|
- `GET /api/clients` — List all
|
|
- `GET /api/clients/:id` — Get by ID
|
|
- `POST /api/clients` — Create
|
|
- `PUT /api/clients/:id` — Update
|
|
- `DELETE /api/clients/:id` — Delete
|
|
|
|
#### stats
|
|
- `GET /api/stats` — List all
|
|
- `GET /api/stats/:id` — Get by ID
|
|
- `POST /api/stats` — Create
|
|
- `PUT /api/stats/:id` — Update
|
|
- `DELETE /api/stats/:id` — Delete
|
|
|
|
### System
|
|
- `GET /api/health` — Health check
|