A Twitter/X clone backend API built with Node.js, Express, TypeScript, and MongoDB.
- Tính năng
- Tech Stack
- Yêu cầu hệ thống
- Cài đặt
- Cấu hình
- Chạy dự án
- Scripts
- API Documentation
- Cấu trúc dự án
- 🔐 Authentication & Authorization
- Đăng ký / Đăng nhập
- JWT tokens (Access & Refresh)
- Xác thực email
- Quên mật khẩu / Đặt lại mật khẩu
- 👤 User Management
- Xem và chỉnh sửa profile
- Upload avatar
- Follow / Unfollow users
- Xem danh sách followers/following
- 🐦 Tweets (Coming soon)
- Đăng tweet
- Like / Unlike
- Retweet
- Reply
- Hashtags
- Media upload
- Runtime: Bun v1.2.22+ (hoặc Node.js 18+)
- Framework: Express.js 5
- Language: TypeScript 5
- Database: MongoDB (Mongoose ODM)
- Validation: Zod
- Authentication: JWT + Bcrypt
- Code Quality: ESLint, Prettier
- Bun v1.2.22+ hoặc Node.js v18+
- MongoDB v6.0+
- Git
git clone https://github.com/ngxccc/x-clone
cd x-cloneSử dụng Bun (khuyến nghị):
bun installHoặc sử dụng npm:
npm install
npm install tsx # Hỗ trợ chạy các file .ts-
Cài đặt MongoDB: https://www.mongodb.com/try/download/community
-
Chạy MongoDB service:
mongod
- Tạo tài khoản tại: https://www.mongodb.com/cloud/atlas
- Tạo cluster mới (Free tier)
- Lấy connection string
Chi tiết: .env.example
# Bun
bun dev
# Npm
npm run dev:nodeServer sẽ chạy tại: http://localhost:4000
- Build TypeScript sang JavaScript:
bun run build- Chạy compiled code:
bun start# Bun
bun run db:index
#Npm
npm run db:index:node| Script | Mô tả |
|---|---|
bun dev |
Chạy dev server với hot reload |
npm run dev:node |
Giống như bun dev nhưng dành cho npm |
bun run build |
Build TypeScript sang JavaScript |
bun start |
Chạy production build |
bun run lint |
Kiểm tra code style với ESLint |
bun run lint:fix |
Tự động fix lỗi ESLint |
bun run prettier |
Kiểm tra format code |
bun run prettier:fix |
Tự động format code |
bun run db:index |
Đồng bộ database indexes |
npm run db:index:node |
Giống như bun run db:index nhưng dành cho npm |
Chi tiết API endpoints xem tại: docs/API.md
x-clone/
├── src/
│ ├── constants/ # Các hằng số
│ ├── controllers/ # Request handlers
│ ├── middlewares/ # Express middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # API routes
│ ├── services/ # Business logic
│ ├── utils/ # Utility functions
│ ├── type.d.ts # TypeScript type definitions
│ └── index.ts # Entry point
├── docs/ # Documentation
├── dist/ # Compiled JavaScript (sau khi build)
├── .env # Environment variables (không commit)
├── package.json # Dependencies
├── tsconfig.json # TypeScript config
└── eslint.config.ts # ESLint config- ✅ Passwords được hash với bcrypt
- ✅ JWT tokens cho authentication
- ✅ Input validation với Zod
- ✅ MongoDB injection protection
- ✅ CORS configuration
⚠️ Cần thêm: Rate limiting, Helmet.js
Contributions, issues và feature requests đều được chào đón!
MIT License
Dự án được xây dựng với ❤️ bởi Ngxc và Gemini, Copilot