Dự án Knowledge Management System gồm frontend React/Vite và backend Node.js/Express, sử dụng MongoDB để lưu dữ liệu. Ứng dụng hỗ trợ quản lý tài liệu học tập, danh mục, bình luận, thông báo, tài khoản người dùng và khu vực quản trị dành cho giảng viên.
- Frontend: React, Vite, Tailwind CSS, React Router, Axios, Lucide React
- Backend: Node.js, Express, MongoDB, Mongoose, JWT, Multer, GridFS
- Xác thực: JWT lưu qua cookie HTTP-only
Knowledge-Management-System/
|-- client/ # Frontend React + Vite
| |-- public/ # Icon, favicon và tài nguyên tĩnh
| |-- src/
| | |-- api/ # Cấu hình HTTP client và API modules
| | |-- assets/ # Hình ảnh/tài nguyên dùng trong app
| | |-- components/ # Component dùng chung
| | |-- components/admin/ # Component riêng cho trang admin
| | |-- context/ # App context
| | |-- hooks/ # Custom hooks
| | |-- layouts/ # Layout chính
| | |-- pages/ # Trang người dùng
| | |-- pages/admin/ # Trang quản trị
| | |-- routes/ # Định nghĩa route frontend
| | `-- utils/ # Hàm tiện ích
| |-- index.html
| |-- package.json
| `-- vite.config.js
|
|-- Server/ # Backend Node.js + Express
| |-- config/ # Cấu hình env, database, CORS, upload
| |-- controllers/ # Xử lý logic request
| |-- middleware/ # Auth, phân quyền, error handler
| |-- models/ # Mongoose models
| |-- routes/ # API routes
| |-- scripts/ # Script hỗ trợ, ví dụ migrate uploads
| |-- utils/ # Hàm tiện ích backend
| |-- app.js # Tạo Express app và đăng ký middleware/routes
| |-- server.js # Kết nối DB và chạy server
| `-- package.json
|
`-- README.md
- Node.js và npm
- MongoDB local hoặc MongoDB Atlas
Tạo file .env trong thư mục Server/:
PORT=5000
MONGO_URI=mongodb://127.0.0.1:27017/knowledge-management-system
JWT_SECRET=your_jwt_secret
JWT_EXPIRES_IN=7d
FRONTEND_URL=http://localhost:5173
NODE_ENV=developmentNếu frontend cần trỏ tới backend khác mặc định, tạo file .env trong thư mục client/:
VITE_BACKEND_URL=http://localhost:5000Mở terminal thứ nhất để chạy backend:
cd Server
npm install
npm run devBackend mặc định chạy tại:
http://localhost:5000
Mở terminal thứ hai để chạy frontend:
cd client
npm install
npm run devFrontend mặc định chạy tại:
http://localhost:5173
Build frontend:
cd client
npm install
npm run buildChạy backend:
cd ../Server
npm install
npm run serverKhi thư mục client/dist tồn tại, backend sẽ tự phục vụ frontend build và các route không thuộc /api sẽ trả về ứng dụng React.
Backend đăng ký các route dưới prefix /api:
/api/auth
/api/materials
/api/comments
/api/categories
/api/notifications
/api/subjects
/api/users
Trong Server/:
npm run dev # Chạy backend bằng nodemon
npm run server # Chạy backend bằng node
npm run build:client # Build frontend từ backend
npm run migrate:uploads # Migrate file upload cũ sang GridFSTrong client/:
npm run dev # Chạy Vite dev server
npm run build # Build frontend
npm run preview # Preview bản build
npm run lint # Kiểm tra lint