SocialApp — 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
contracts
GET /api/contracts— List allGET /api/contracts/:id— Get by IDPOST /api/contracts— CreatePUT /api/contracts/:id— UpdateDELETE /api/contracts/:id— Delete
approvals
GET /api/approvals— List allGET /api/approvals/:id— Get by IDPOST /api/approvals— CreatePUT /api/approvals/:id— UpdateDELETE /api/approvals/:id— Delete
customers
GET /api/customers— List allGET /api/customers/:id— Get by IDPOST /api/customers— CreatePUT /api/customers/:id— UpdateDELETE /api/customers/:id— Delete
reminders
GET /api/reminders— List allGET /api/reminders/:id— Get by IDPOST /api/reminders— CreatePUT /api/reminders/:id— UpdateDELETE /api/reminders/:id— Delete
articles
GET /api/articles— List allGET /api/articles/:id— Get by IDPOST /api/articles— CreatePUT /api/articles/:id— UpdateDELETE /api/articles/:id— Delete
tags
GET /api/tags— List allGET /api/tags/:id— Get by IDPOST /api/tags— CreatePUT /api/tags/:id— UpdateDELETE /api/tags/:id— Delete
comments
GET /api/comments— List allGET /api/comments/:id— Get by IDPOST /api/comments— CreatePUT /api/comments/:id— UpdateDELETE /api/comments/:id— Delete
media
GET /api/media— List allGET /api/media/:id— Get by IDPOST /api/media— CreatePUT /api/media/:id— UpdateDELETE /api/media/:id— Delete
System
GET /api/health— Health check