https://github.com/sumingcheng/gin-blog-template
Production-ready blog template — Go (Gin) + React + PostgreSQL + Redis. Dual-token auth, Swagger, Prometheus/Grafana, Docker one-click deploy.
https://github.com/sumingcheng/gin-blog-template
blog docker gin golang jwt postgresql prometheus react redis swagger template
Last synced: 2 months ago
JSON representation
Production-ready blog template — Go (Gin) + React + PostgreSQL + Redis. Dual-token auth, Swagger, Prometheus/Grafana, Docker one-click deploy.
- Host: GitHub
- URL: https://github.com/sumingcheng/gin-blog-template
- Owner: sumingcheng
- License: mit
- Created: 2024-06-23T13:53:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-26T16:01:26.000Z (2 months ago)
- Last Synced: 2026-04-26T17:27:20.889Z (2 months ago)
- Topics: blog, docker, gin, golang, jwt, postgresql, prometheus, react, redis, swagger, template
- Language: Go
- Homepage:
- Size: 596 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Gin Blog Template
A production-ready blog template built with Go + React.
Clean architecture, dual-token auth, one-command deploy.

---
## Tech Stack
| Layer | Technology |
|---|---|
| Backend | Go 1.25, Gin, GORM, PostgreSQL 16, Redis |
| Frontend | React 18, Vite, Chakra UI |
| Auth | JWT (golang-jwt/v5) + Refresh Token, bcrypt |
| Observability | Prometheus, Grafana, Logrus |
| Deploy | Docker, Docker Compose, multi-stage build |
## Project Structure
```
.
├── config/ # YAML configs (postgres, redis, jwt secret)
├── database/ # GORM models, DB/Redis connection, init.sql
├── handler/ # HTTP handlers (thin layer, delegates to service)
├── middleware/ # Auth, CORS, rate limit, request logger, metrics
├── model/ # Response structs, error codes, pagination
├── router/ # Route definitions
├── service/ # Business logic
├── util/ # JWT, bcrypt, config loader, logger, validator
├── web/ # React frontend (Vite)
├── deploy/ # Prometheus & Grafana configs
├── Dockerfile # Multi-stage build
├── docker-compose.yaml
└── main.go
```
## API
### Public
| Method | Endpoint | Description |
|---|---|---|
| POST | `/api/register` | Register |
| POST | `/api/login` | Login (returns JWT + sets refresh token cookie) |
| POST | `/api/logout` | Logout |
| GET | `/api/token` | Refresh auth token |
| GET | `/api/blog/list` | Blog list (pagination, search) |
| GET | `/api/blog/:bid` | Blog detail |
### Authenticated
| Method | Endpoint | Description |
|---|---|---|
| GET | `/api/user/profile` | Get profile |
| POST | `/api/user/password` | Change password |
| POST | `/api/blog/create` | Create blog |
| POST | `/api/blog/update` | Update blog |
| DELETE | `/api/blog/:bid` | Delete blog (soft delete) |
### Other
| Endpoint | Description |
|---|---|
| `/health` | Health check (DB + Redis) |
| `/metrics` | Prometheus metrics |
| `/swagger/*` | Swagger UI |
## Quick Start
### Prerequisites
- Docker & Docker Compose
### Run
```bash
git clone https://github.com/sumingcheng/gin-blog-template.git
cd gin-blog-template
# Build
make build
# Start all services
docker compose up -d
```
The app will be available at `http://localhost:5678`.
Default account: `admin` / `123456`
### Local Development
```bash
# Start PostgreSQL + Redis only
docker compose -f docker-compose-dev.yaml up -d postgres redis
# Update config/postgres.yaml and config/redis.yaml host to localhost
# Start backend
go run main.go
# Start frontend (in another terminal)
cd web && npm install && VITE_APP_ENV=development npm run dev
```
Frontend dev server runs at `http://localhost:5173`, proxying API requests to `:5678`.
## Auth Flow
```
Client Server Redis
| | |
|-- POST /login --------->| |
| |-- verify password |
| |-- generate JWT |
| |-- generate refresh token|
| |-- SET refresh:auth ---->|
|<-- JWT + cookie --------| |
| | |
|-- GET /api/* ---------->| |
| (auth_token header) |-- verify JWT |
|<-- response ------------| |
| | |
|-- GET /token ---------->| |
| (refresh cookie) |-- GET refresh token --->|
|<-- new auth_token ------|<-- auth token ----------|
```
## Monitoring
After startup, import the Grafana dashboard from `deploy/grafana/gin-blog.json`.
- Prometheus: `http://localhost:59090`
- Grafana: `http://localhost:53000` (admin / admin123456)
## License
[MIT](./LICENSE)