Một ứng dụng full-stack hoàn chỉnh để quản lý ghi chú với tích hợp GitHub Pull Request. Bao gồm backend API viết bằng Golang và frontend React application.
# Khởi động full-stack application
make up
# Dừng tất cả services
make down
# Build lại toàn bộ
make build
# Rebuild hoàn toàn (down->build->up)
make rebuild
# Xem tất cả lệnh
make help📋 Xem hướng dẫn chi tiết: QUICKSTART.md
- Đăng ký user với email và password
- Đăng nhập và nhận JWT token
- Mật khẩu được hash bằng bcrypt
- Middleware bảo vệ các API cần đăng nhập
- Lưu trữ GitHub username và token của user
- Sử dụng token để gọi GitHub API
- Kiểm tra và yêu cầu cấu hình GitHub token khi cần
- Tạo, đọc, cập nhật, xóa ghi chú
- Liên kết ghi chú với GitHub Pull Request
- Tự động fetch thông tin PR từ GitHub API
- Lưu cache thông tin PR để tránh gọi API nhiều lần
- Tìm kiếm ghi chú theo tiêu đề, nội dung, PR number, PR state
- Phân trang kết quả
- Framework: Golang với Gin framework
- Database: PostgreSQL
- ORM: GORM
- Authentication: JWT
- Password Hashing: bcrypt
- Framework: React 18
- Routing: React Router DOM
- HTTP Client: Axios
- UI Framework: Bootstrap 5
- Icons: Font Awesome
- Notifications: React Toastify
- Containerization: Docker & Docker Compose
- Build Tool: Create React App
├── cmd/
│ └── main.go # Entry point của ứng dụng
├── internal/
│ ├── config/
│ │ └── config.go # Cấu hình ứng dụng
│ ├── database/
│ │ └── database.go # Kết nối database
│ ├── handlers/
│ │ ├── auth.go # Handlers cho authentication
│ │ ├── user.go # Handlers cho user management
│ │ └── note.go # Handlers cho note management
│ ├── middleware/
│ │ └── auth.go # Authentication middleware
│ ├── models/
│ │ └── models.go # Database models
│ ├── services/
│ │ └── github.go # GitHub API integration
│ └── utils/
│ ├── auth.go # Authentication utilities
│ └── response.go # Response utilities
├── frontend/ # React frontend application
│ ├── public/
│ ├── src/
│ │ ├── components/ # Reusable UI components
│ │ ├── contexts/ # React Context providers
│ │ ├── pages/ # Page components
│ │ ├── services/ # API service functions
│ │ └── styles/ # Global styles
│ ├── package.json
│ └── README.md
├── migrations/
├── docker-compose.yml
├── Dockerfile
├── go.mod
└── README.md
│ ├── models/
│ │ └── models.go # Database models và DTOs
│ ├── services/
│ │ └── github.go # GitHub API service
│ └── utils/
│ ├── auth.go # Authentication utilities
│ └── response.go # Response utilities
├── migrations/ # Database migrations (nếu cần)
├── .env # Environment variables
├── docker-compose.yml # Docker compose configuration
├── Dockerfile # Docker configuration
├── go.mod # Go module dependencies
├── go.sum # Go module checksums
├── init.sql # Database initialization
└── README.md # Documentation
- Docker và Docker Compose
- Node.js 16+ và npm (cho frontend)
- Go 1.23+ (nếu chạy backend local)
- PostgreSQL (nếu chạy local)
- Clone repository:
git clone <repository-url>
cd githubBE- Tạo file .env cho backend (đã có sẵn, có thể chỉnh sửa nếu cần):
cp .env.example .env- Chạy toàn bộ ứng dụng (backend + frontend + database):
docker-compose -f docker-compose.fullstack.yml up -d- Kiểm tra trạng thái:
docker-compose -f docker-compose.fullstack.yml ps- Ứng dụng sẽ chạy tại:
- Frontend: http://localhost:3000 (tích hợp đầy đủ với backend)
- Backend API: http://localhost:8080
- Setup và chạy backend:
docker-compose up -d- Setup frontend:
cd frontend
chmod +x setup.sh
./setup.sh- Chạy frontend:
npm start- Ứng dụng sẽ chạy tại:
- Backend API: http://localhost:8080
- Frontend: http://localhost:3000
- Chạy backend với Docker:
docker-compose up -d- Kiểm tra logs:
docker-compose logs -f backend- Cài đặt dependencies:
go mod tidy- Chạy PostgreSQL:
docker run --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=github_notes -p 5432:5432 -d postgres:15-alpine- Chạy backend:
go run cmd/main.go- Navigate to frontend directory:
cd frontend- Cài đặt dependencies:
npm install- Chạy development server:
npm start- Truy cập http://localhost:3000
- Đăng ký tài khoản mới hoặc đăng nhập
- Cập nhật GitHub profile (username và token) trong Profile settings
- Tạo, quản lý và tìm kiếm notes
- Liên kết notes với GitHub Pull Requests
Để sử dụng tính năng tích hợp GitHub PR:
- Vào GitHub Settings > Developer settings > Personal access tokens
- Tạo token mới với permissions:
public_repo- Truy cập repositories publicread:user- Đọc thông tin user profile
- Copy token và lưu vào Profile settings trong ứng dụng
http://localhost:8080/api
POST /api/auth/register
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}GET /api/user/profile
Authorization: Bearer <jwt_token>PUT /api/user/profile
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"github_username": "yourusername",
"github_token": "ghp_your_github_token"
}POST /api/notes
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"title": "My Note",
"content": "Note content here",
"github_pr_number": 123,
"repo_owner": "owner",
"repo_name": "repository"
}GET /api/notes?page=1&limit=10&search=keyword&pr_number=123&pr_state=open
Authorization: Bearer <jwt_token>GET /api/notes/:id
Authorization: Bearer <jwt_token>PUT /api/notes/:id
Authorization: Bearer <jwt_token>
Content-Type: application/json
{
"title": "Updated Note",
"content": "Updated content"
}DELETE /api/notes/:id
Authorization: Bearer <jwt_token>curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password123"
}'curl -X PUT http://localhost:8080/api/user/profile \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"github_username": "yourusername",
"github_token": "ghp_your_github_token"
}'curl -X POST http://localhost:8080/api/notes \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \
-d '{
"title": "Fix bug in authentication",
"content": "This note describes the bug fix in PR #123",
"github_pr_number": 123,
"repo_owner": "facebook",
"repo_name": "react"
}'curl -X GET "http://localhost:8080/api/notes?page=1&limit=10" \
-H "Authorization: Bearer YOUR_JWT_TOKEN"id(UUID, Primary Key)email(String, Unique)password_hash(String)github_username(String, Optional)github_token(String, Optional)created_at(Timestamp)updated_at(Timestamp)
id(UUID, Primary Key)user_id(UUID, Foreign Key)title(String, Max 255)content(Text)github_pr_number(Integer, Optional)repo_owner(String, Optional)repo_name(String, Optional)created_at(Timestamp)updated_at(Timestamp)
id(UUID, Primary Key)number(Integer)repo_owner(String)repo_name(String)title(String)body(Text)author(String)state(String)url(String)created_at(Timestamp)updated_at(Timestamp)
note_id(UUID)pr_id(UUID)
# Database Configuration
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=postgres
DB_NAME=github_notes
DB_SSL_MODE=disable
# JWT Configuration
JWT_SECRET=your_super_secret_jwt_key_here
# Server Configuration
PORT=8080- Mật khẩu được hash bằng bcrypt
- JWT token để authentication
- Prepared statements với GORM để tránh SQL injection
- GitHub token không được trả về trong API response
- CORS middleware được cấu hình
# Nếu sử dụng migrate tool
migrate create -ext sql -dir migrations -seq migration_namego test ./...docker build -t github-notes-backend .- Kiểm tra PostgreSQL đã chạy
- Kiểm tra thông tin kết nối trong .env
- Kiểm tra network trong Docker Compose
- Kiểm tra GitHub token có quyền truy cập repository
- Kiểm tra repository và PR number có tồn tại
- Kiểm tra rate limit của GitHub API
- Kiểm tra JWT_SECRET trong .env
- Kiểm tra token đã expired chưa
- Kiểm tra format của Authorization header
- Fork repository
- Tạo feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License.