A modern Express.js backend with TypeScript, Firebase, and comprehensive development tooling.
- Framework: Express.js + TypeScript (Strict Mode)
- Database: Firebase Admin SDK (Firestore + Realtime Database)
- Environment: dotenv + Zod validation
- Code Quality: ESLint, Prettier, EditorConfig
- Git Hooks: Husky + lint-staged
- Development: tsx (watch mode)
- Logging: Pino
- Security: Helmet + CORS
- CI/CD: GitHub Actions (Node 20 + pnpm)
- Node.js >= 20.0.0
- pnpm (recommended package manager)
- Firebase project with service account credentials
- Clone the repository:
git clone <your-repo-url>
cd XueEr-Backend
- Install dependencies:
pnpm install
- Set up environment variables:
cp .env.example .env
-
Configure your Firebase service account credentials in
.env
-
Initialize Git hooks:
pnpm prepare
Start the development server with hot reload:
pnpm dev
The server will start on http://localhost:3000
by default.
Run tests with Vitest:
pnpm test # Watch mode
pnpm test:run # Run once
pnpm test:coverage # With coverage
pnpm test:ui # UI interface
See TESTING.md for detailed testing guide.
Build the project:
pnpm build
Start the production server:
pnpm start
Run type checking:
pnpm typecheck
Run linting:
pnpm lint
pnpm lint:fix # Auto-fix issues
Run formatting:
pnpm format
pnpm format:check # Check formatting
- GET
/health
- Server health status
- GET
/api/test
- Test API and Firebase connection
Copy .env.example
to .env
and configure:
PORT
: Server port (default: 3000)NODE_ENV
: Environment (development/production/test)FIREBASE_*
: Firebase service account credentialsCORS_ORIGINS
: Allowed CORS origins
- Create a Firebase project
- Generate a service account key
- Download the JSON file
- Extract the credentials to your
.env
file
The project is configured with Firestore by default. Access it via:
import { firestore } from './config/firebase';
To enable Realtime Database, uncomment the relevant lines in:
src/config/firebase.ts
- Add database URL to
.env
pnpm dev
- Start development serverpnpm build
- Build for productionpnpm start
- Start production serverpnpm clean
- Clean build directorypnpm typecheck
- Run TypeScript checkspnpm lint
- Run ESLintpnpm lint:fix
- Fix ESLint issuespnpm format
- Format with Prettierpnpm format:check
- Check Prettier formattingpnpm check
- Run all quality checks (CI equivalent)pnpm setup:test
- Setup test environment with dummy credentials
- Helmet: Security headers
- CORS: Cross-origin resource sharing
- Environment Validation: Zod schema validation
- Request Logging: Structured logging with Pino
本專案使用 GitHub Actions 進行持續整合:
- ✅ TypeScript 類型檢查
- ✅ ESLint 代碼檢查
- ✅ Prettier 格式檢查
- ✅ 專案構建
- ⏸️ 測試 (暫時停用,需要環境變數配置)
- 🔧 手動觸發或配置 Firebase 環境變數後啟用
- 包含完整的 API 測試和覆蓋率報告
- 需要設置 GitHub Secrets 或使用測試用環境變數
-
使用測試環境變數 (推薦用於開發):
- 修改
.github/workflows/test.yml
- 取消註解
push
和pull_request
觸發器
- 修改
-
使用真實 Firebase 配置:
- 在 GitHub Repository Settings > Secrets 中設置:
FIREBASE_PROJECT_ID
FIREBASE_PRIVATE_KEY
FIREBASE_CLIENT_EMAIL
- 等其他必要變數
- 在 GitHub Repository Settings > Secrets 中設置:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The pre-commit hooks will automatically run linting and formatting checks.
This project is licensed under the ISC License. XueEr Backend Service