plh97/golang-vue-cms

avatarplhDigital nomad

Entrypoint Overview

This project is composed of several major modules, each with its own entrypoint and deployment/operation method:

Backend

  • Entrypoint: Managed via the project root Makefile (build, test, migration, server, Docker, etc.)
  • Cloud Deployment: AWS (see terraform/aws/ for infrastructure as code)

DevOps / Operations

  • Infrastructure as Code:
    • Terraform for provisioning cloud resources (AWS, Vultr, etc.)
    • Ansible for configuration management and server initialization

Frontend

  • Entrypoint: Deployed via Vercel (see web/ directory)
  • API Proxy: Vercel or local dev server proxies API requests to backend (see vercel.json and frontend config)

入口说明

本项目由多个主要模块组成,每个模块有独立的入口和运维方式:

后端

  • 入口: 通过项目根目录的 Makefile 统一管理(构建、测试、迁移、服务、Docker 等)
  • 云部署: AWS(见 terraform/aws/,基础设施即代码)

运维 / 基础设施

  • 基础设施即代码:
    • Terraform 用于云资源编排(AWS、Vultr 等)
    • Ansible 用于配置管理和服务器初始化

前端

  • 入口: 通过 Vercel 部署(见 web/ 目录)
  • 接口转发: Vercel 或本地开发服务器将 API 请求代理到后端(见 vercel.json 和前端配置)

Entrypoint Overview

This project is composed of several major modules, each with its own entrypoint and deployment/operation method:

Backend

  • Entrypoint: Managed via the project root Makefile (build, test, migration, server, Docker, etc.)
  • Cloud Deployment: AWS (see terraform/aws/ for infrastructure as code)

DevOps / Operations

  • Infrastructure as Code:
    • Terraform for provisioning cloud resources (AWS, Vultr, etc.)
    • Ansible for configuration management and server initialization

Frontend

  • Entrypoint: Deployed via Vercel (see web/ directory)
  • API Proxy: Vercel or local dev server proxies API requests to backend (see vercel.json and frontend config)

GoLang Vue CMS Project | GoLang Vue 内容管理系统

English | 中文


English

A full-stack Content Management System (CMS) built with Go (Gin, GORM, Casbin) for the backend and Vue 3 (Vite, TailwindCSS) for the frontend. Features robust RBAC (role-based access control), JWT authentication, and a modern, responsive UI. Project structure is inspired by nunu-go.

Note: All backend operations (build, test, migration, server start, etc.) should be run via the provided Makefile for consistency and reproducibility.

Features

  • 🔐 RBAC Authorization: Role-based access control with Casbin
  • 👤 User Management: Full CRUD with role assignment
  • 🔑 JWT Authentication: Secure token-based login
  • 📊 RESTful API: Clean API with Gin
  • 🎨 Modern UI: Vue3 + TailwindCSS
  • 🗄️ Database: MySQL + GORM

Tech Stack

Backend

  • Gin (HTTP framework)
  • GORM (ORM)
  • Casbin (RBAC)
  • JWT
  • Wire (DI)

Frontend

  • Vue 3
  • Vite
  • TailwindCSS
  • Composition API
  • Fetch API

Project Structure

.
├── api/         # API DTOs
├── cmd/         # Entrypoints (server, migration, task)
├── config/      # Config files (local.yml, prod.yml, model.conf)
├── internal/    # Main backend logic
│   ├── handler/     # HTTP handlers
│   ├── middleware/  # JWT, RBAC, CORS
│   ├── model/       # GORM models
│   ├── repository/  # Data access
│   ├── router/      # Routing
│   ├── service/     # Business logic
│   └── server/      # Server startup
├── pkg/         # Utilities (casbin, jwt, log, etc)
└── web/         # Frontend (Vue3 app)
    └── src/
        ├── api.ts
        ├── components/
        └── pages/

Getting Started

Prerequisites

  • Go 1.21+
  • Node.js 18+
  • MySQL 8.0+
  • pnpm

Backend Setup

  1. Clone repo
    git clone https://github.com/plh97/golang-tutorial.git
    cd golang-tutorial
  2. Install Go dependencies
    go mod download
  3. Configure database in config/local.yml
  4. Run migrations (via Makefile)
    make migration
  5. Start server (via Makefile)
    make server
    Server: http://localhost:8291

Frontend Setup

  1. Enter web directory
    cd web
  2. Install dependencies
    pnpm install
  3. Start dev server
    pnpm dev
    Frontend: http://localhost:8000

RBAC Architecture

Business Layer (MySQL):

  • Tables: users, roles, permissions, user_roles, role_permissions
  • Used for: UI, management, assignments

Access Layer (Casbin):

  • Table: casbin_rule
  • Format: p, role_key, api_path, method
  • Used for: Fast API permission checks

Flow:

Request → JWT Middleware → RBAC Middleware (Casbin) → Handler

Permission Update:

UI → Update role_permissions (GORM) → Sync casbin_rule (Casbin)

API Endpoints

Auth

  • POST /v1/login
  • GET /v1/profile

User

  • POST /v1/user/list
  • POST /v1/user
  • PUT /v1/user
  • DELETE /v1/user/:id

Role

  • GET /v1/role/list
  • POST /v1/role
  • PUT /v1/role
  • DELETE /v1/role/:id

Permission

  • GET /v1/permission/list

Default Credentials

Development

Makefile Usage

The project uses a Makefile as the main entrypoint for backend operations. Common targets:

  • make build # Build the backend binary
  • make test # Run backend tests with coverage
  • make migration # Run database migrations
  • make server # Start the backend server
  • make docker # Build and run the backend in Docker
  • make swag # Generate Swagger docs

Wire dependencies

cd cmd/server/wire
wire

Run tests

make test

Build

make build
# Frontend
cd web && pnpm build

License

MIT License


中文

基于 Go (Gin, GORM, Casbin) 后端和 Vue3 (Vite, TailwindCSS) 前端的全栈内容管理系统。支持 RBAC 权限、JWT 登录、现代响应式 UI。项目结构参考 nunu-go

注意: 所有后端操作(构建、测试、迁移、启动等)请通过项目根目录的 Makefile 执行,确保一致性和可复现性。

功能特性

  • 🔐 RBAC 权限控制:基于 Casbin 的角色访问控制
  • 👤 用户管理:完整的用户增删改查及角色分配
  • 🔑 JWT 认证:安全的令牌登录
  • 📊 RESTful API:Gin 框架
  • 🎨 现代 UI:Vue3 + TailwindCSS
  • 🗄️ 数据库:MySQL + GORM

技术栈

后端

  • Gin (HTTP 框架)
  • GORM (ORM)
  • Casbin (RBAC)
  • JWT
  • Wire (依赖注入)

前端

  • Vue 3
  • Vite
  • TailwindCSS
  • Composition API
  • Fetch API

项目结构

.
├── api/         # API 定义和 DTO
├── cmd/         # 启动入口(server, migration, task)
├── config/      # 配置文件(local.yml, prod.yml, model.conf)
├── internal/    # 后端主逻辑
│   ├── handler/     # HTTP 处理器
│   ├── middleware/  # JWT、RBAC、CORS
│   ├── model/       # GORM 模型
│   ├── repository/  # 数据访问
│   ├── router/      # 路由
│   ├── service/     # 业务逻辑
│   └── server/      # 启动
├── pkg/         # 工具包(casbin, jwt, log 等)
└── web/         # 前端(Vue3 应用)
    └── src/
        ├── api.ts
        ├── components/
        └── pages/

快速开始

环境要求

  • Go 1.21+
  • Node.js 18+
  • MySQL 8.0+
  • pnpm

后端设置

  1. 克隆仓库
    git clone https://github.com/plh97/golang-tutorial.git
    cd golang-tutorial
  2. 安装 Go 依赖
    go mod download
  3. 配置数据库 config/local.yml
  4. 运行迁移(通过 Makefile)
    make migration
  5. 启动服务(通过 Makefile)
    make server
    地址: http://localhost:8291

前端设置

  1. 进入 web 目录
    cd web
  2. 安装依赖
    pnpm install
  3. 启动开发服务器
    pnpm dev
    地址: http://localhost:8000

RBAC 架构

业务层(MySQL)

  • 表:users, roles, permissions, user_roles, role_permissions
  • 用于:UI、管理、分配

访问层(Casbin)

  • 表:casbin_rule
  • 格式:p, role_key, api_path, method
  • 用于:API 权限快速校验

流程:

请求 → JWT 中间件 → RBAC 中间件(Casbin)→ 处理器

权限更新:

UI → 更新 role_permissions(GORM)→ 同步 casbin_rule(Casbin)

API 接口

认证

  • POST /v1/login
  • GET /v1/profile

用户

  • POST /v1/user/list
  • POST /v1/user
  • PUT /v1/user
  • DELETE /v1/user/:id

角色

  • GET /v1/role/list
  • POST /v1/role
  • PUT /v1/role
  • DELETE /v1/role/:id

权限

  • GET /v1/permission/list

默认账号

开发

Makefile 用法

本项目后端操作统一通过 Makefile 入口。常用命令:

  • make build # 构建后端二进制
  • make test # 运行后端测试并生成覆盖率
  • make migration # 执行数据库迁移
  • make server # 启动后端服务
  • make docker # Docker 构建和运行
  • make swag # 生成 Swagger 文档

生成 Wire 依赖

cd cmd/server/wire
wire

运行测试

make test

构建

make build
# 前端
cd web && pnpm build

许可证

MIT License

undefined