Wavelet

command module
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

wavelet

🚀 A modern, production-ready full-stack boilerplate for building scalable web applications

中文

Go Version Next.js React

📖 Introduction

wavelet is a generic, production-ready full-stack boilerplate built with Go (Gin + GORM) on the backend and Next.js (App Router + Shadcn UI) on the frontend. It ships with everything you need to bootstrap a modern SaaS, internal tool, or developer platform — without the boilerplate headaches.

The project was designed from the ground up to be framework-first and business-agnostic: plug in your own domain logic while reusing the battle-tested infrastructure that comes out of the box.

✨ Key Features
  • 🔐 Multi-auth System — Local password login/registration + pluggable OIDC/OAuth2 providers (supports multiple auth sources simultaneously)
  • 🗝️ Personal Access Tokens — API key management for programmatic access; supports Authorization: Bearer and X-Access-Token headers
  • 👤 User Management — Admin panel for listing, searching, filtering, enabling/disabling user accounts
  • ⚙️ Dynamic System Config — Key-value system configuration management with live reload, controllable from the admin UI
  • 📋 Async Task Queue — Background job processing with Asynq (Redis-backed), including a scheduling dashboard
  • 📁 S3 File Storage — Unified file upload/download via S3-compatible APIs with local disk cache
  • 📊 Observability — Structured logging (Zap) + distributed tracing (OpenTelemetry)
  • 🎨 Modern UI — Responsive, dark-mode-ready design system built with Tailwind CSS 4 and Shadcn UI
  • 📖 Built-in Documentation — Integrated docs portal with usage guides, API reference, privacy policy, and terms of service

🏗️ Architecture Overview

┌─────────────────┐    ┌─────────────────────────────┐    ┌─────────────────┐
│   Frontend      │    │          Backend             │    │   Database      │
│   (Next.js)     │◄──►│           (Go)               │◄──►│  (PostgreSQL)   │
│                 │    │                              │    │                 │
│ • React 19      │    │ • Gin HTTP Framework         │    │ • PostgreSQL    │
│ • TypeScript    │    │ • GORM ORM                   │    │ • Redis Cache   │
│ • Tailwind 4    │    │ • Multi-provider Auth        │    │                 │
│ • Shadcn UI     │    │ • AccessToken Middleware     │    │                 │
│                 │    │ • Asynq Task Queue           │    │                 │
│                 │    │ • OpenTelemetry Tracing      │    │                 │
│                 │    │ • Swagger API Docs           │    │                 │
└─────────────────┘    └─────────────────────────────┘    └─────────────────┘
                                      │
                           ┌──────────┴──────────┐
                           │   Multi-Process CLI  │
                           │  (Cobra + Viper)     │
                           │ • api      (HTTP)    │
                           │ • worker   (Queue)   │
                           │ • scheduler(Cron)    │
                           └─────────────────────┘

🛠️ Tech Stack

Backend
  • Go 1.25+ — Primary language
  • Gin — HTTP web framework
  • GORM — ORM with PostgreSQL & ClickHouse support
  • Redis — Cache, session store, and task queue backend
  • Asynq — Distributed task queue (Redis-backed)
  • Cobra + Viper — CLI entrypoint and configuration management
  • OpenTelemetry — Distributed tracing and observability
  • Zap — Structured, high-performance logging
  • Swagger (Swaggo) — Auto-generated API documentation
  • AWS SDK v2 — S3-compatible file storage
  • Snowflake — Distributed ID generation
Frontend

📋 Requirements

  • Go >= 1.25
  • Node.js >= 18.0
  • PostgreSQL >= 14
  • Redis >= 6.0
  • pnpm >= 8.0 (recommended)

🚀 Quick Start

1. Clone the Repository
git clone https://github.com/Rain-kl/Wavelet.git refreshing
cd refreshing
2. Configure Environment
cp config.example.yaml config.yaml

Edit config.yaml to configure your database and Redis. OIDC auth sources are configured at runtime in the admin settings page.

3. Initialize Database
# Start local dependencies (PostgreSQL + Redis)
docker compose up -d

# Optional: also start ClickHouse
docker compose --profile clickhouse up -d

# If you use an external PostgreSQL instance instead of Docker, create the database manually
createdb -h <host> -p 5432 -U postgres refreshing

# Database schema is auto-migrated on first startup
4. Start the Backend
# Install Go dependencies
go mod tidy

# Generate Swagger API documentation
make swagger

# Start the HTTP API server
go run main.go api

The backend also supports separate scheduler and worker processes for async task processing:

go run main.go scheduler   # Cron job scheduler
go run main.go worker      # Asynq task worker
5. Start the Frontend
cd frontend

# Install dependencies
pnpm install

# Start dev server (Turbopack)
pnpm dev
6. Access the Application
Service URL
Frontend http://localhost:3000
Swagger API Docs http://localhost:8000/swagger/index.html
Health Check http://localhost:8000/api/health

⚙️ Configuration

Key configuration options (see config.example.yaml for the full reference):

Option Description Example
app.addr Backend listen address :8000
database.host PostgreSQL host 127.0.0.1
database.database Database name refreshing
redis.host Redis host 127.0.0.1
storage.endpoint S3-compatible endpoint s3.amazonaws.com

🔧 Development Guide

Backend
# Run API server
go run main.go api

# Run task scheduler
go run main.go scheduler

# Run async worker
go run main.go worker

# Regenerate Swagger docs (required after controller changes)
make swagger

# Format & vet code
make tidy
Frontend
cd frontend

# Development mode (Turbopack)
pnpm dev

# Production build
pnpm build

# Start production server
pnpm start

# Lint & format
pnpm lint
pnpm format

📁 Project Structure

wavelet/
├── main.go                  # Entry point (delegates to internal/cmd)
├── config.example.yaml      # Configuration template
├── Makefile                 # Common commands (swagger, tidy, license, cross-build)
├── docker/                  # Docker image build files (integrated/frontend/backend)
├── docs/                    # Swagger auto-generated docs
├── frontend/                # Next.js frontend application
│   ├── app/                 # App Router pages
│   ├── components/          # React components (ui, common, layout)
│   ├── lib/services/        # API service layer
│   └── types/               # TypeScript type definitions
└── internal/                # Go backend (private)
    ├── cmd/                 # CLI commands (api, scheduler, worker)
    ├── apps/                # Business modules (oauth, user, admin, upload)
    ├── model/               # GORM entities and business methods
    ├── router/              # HTTP route registration
    ├── task/                # Async task definitions and workers
    ├── db/                  # Database and Redis initialization
    ├── storage/             # S3 file storage abstraction
    └── common/              # Shared utilities and response helpers

📚 API Documentation

Swagger API documentation is auto-generated and available once the backend is running:

http://localhost:8000/swagger/index.html

The built-in frontend docs portal at /docs includes:

  • Usage Guide — Step-by-step walkthrough for getting started
  • API Reference — Detailed interface documentation
  • Privacy Policy — Template privacy policy (customize as needed)
  • Terms of Service — Template terms of service

🧪 Testing

# Backend tests
go test ./...

# Frontend lint
cd frontend && pnpm lint

🚀 Deployment

Cross-platform Binary

Build static binaries for all 6 targets (Linux / macOS / Windows × amd64 / arm64) with a single command. The compiled frontend is embedded in every binary — no separate deployment needed.

Prerequisites: Docker with BuildKit enabled (Docker 23+ defaults to on).

# Build all 6 binaries → ./bin/
make cross-build

# Stamp a release version
make cross-build VERSION=v1.2.3

# Build only a specific OS (both architectures)
make cross-build GOOS=linux
make cross-build GOOS=darwin
make cross-build GOOS=windows

# Build only a specific architecture (all OSes)
make cross-build GOARCH=amd64
make cross-build GOARCH=arm64

# Combine filters — single binary
make cross-build GOOS=linux GOARCH=arm64
make cross-build GOOS=darwin GOARCH=amd64 VERSION=v1.2.3

Output files in ./bin/:

File Platform
wavelet_linux_amd64 Linux x86-64
wavelet_linux_arm64 Linux ARM64
wavelet_darwin_amd64 macOS Intel
wavelet_darwin_arm64 macOS Apple Silicon
wavelet_windows_amd64.exe Windows x86-64
wavelet_windows_arm64.exe Windows ARM64

The version string is accessible at runtime via wavelet --version.

Docker
# Build image
docker build -t refreshing .

# Run (pass your config as a volume mount)
docker run -d -p 8000:8000 \
  -v $(pwd)/config.yaml:/app/config.yaml \
  refreshing api
Production
  1. Build the frontend:

    cd frontend && pnpm build
    
  2. Compile the backend:

    go build -o refreshing main.go
    
  3. Configure config.yaml for production.

  4. Start services:

    ./refreshing api        # HTTP API
    ./refreshing scheduler  # Cron scheduler (optional)
    ./refreshing worker     # Task worker (optional)
    

🤝 Contributing

We welcome contributions! Please read the following before submitting code:

Workflow
  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/your-feature)
  3. Commit your changes (git commit -am 'Add your feature')
  4. Push to the branch (git push origin feature/your-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the Apache 2.0 License.

Documentation

Overview

Package main 是 Wavelet 平台的程序入口

Directories

Path Synopsis
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
internal
apps/admin
Package admin 提供管理后台功能
Package admin 提供管理后台功能
apps/admin/auth_source
Package auth_source 提供认证源管理功能
Package auth_source 提供认证源管理功能
apps/admin/cache
Package cache provides HTTP handlers for managing disk cache.
Package cache provides HTTP handlers for managing disk cache.
apps/admin/db_manage
Package db_manage provides router handlers for managing database tables, overview information, and executing custom SQL queries.
Package db_manage provides router handlers for managing database tables, overview information, and executing custom SQL queries.
apps/admin/logs
Package logs 提供日志查询与分析功能
Package logs 提供日志查询与分析功能
apps/admin/push
Package push defines push notification HTTP routes, background tasks, and events.
Package push defines push notification HTTP routes, background tasks, and events.
apps/admin/push/custom_events
Package custom_events defines custom push notification events.
Package custom_events defines custom push notification events.
apps/admin/status
Package status 提供系统状态查询接口
Package status 提供系统状态查询接口
apps/admin/system_config
Package system_config 提供系统配置管理功能
Package system_config 提供系统配置管理功能
apps/admin/task
Package task 提供任务管理接口
Package task 提供任务管理接口
apps/admin/template
Package template 提供模板管理功能
Package template 提供模板管理功能
apps/admin/updater
Package updater manages GitHub Release checks and in-place application upgrades.
Package updater manages GitHub Release checks and in-place application upgrades.
apps/admin/user
Package user 提供用户管理功能
Package user 提供用户管理功能
apps/cap
Package cap 提供人机验证中间件
Package cap 提供人机验证中间件
apps/config
Package config 提供公开配置查询接口
Package config 提供公开配置查询接口
apps/custom
Package custom provides custom business handlers
Package custom provides custom business handlers
apps/health
Package health 提供健康检查端点
Package health 提供健康检查端点
apps/oauth
Package oauth 提供 OAuth/OIDC 认证与会话管理
Package oauth 提供 OAuth/OIDC 认证与会话管理
apps/risk_control
Package risk_control 提供风险控制中间件
Package risk_control 提供风险控制中间件
apps/upload
Package upload 提供文件上传与下载功能
Package upload 提供文件上传与下载功能
apps/upload/cache
Package cache provides in-process upload access-control caches.
Package cache provides in-process upload access-control caches.
apps/upload/filesrv
Package filesrv serves uploaded files with access control and image compression.
Package filesrv serves uploaded files with access control and image compression.
apps/upload/handler
Package handler provides upload HTTP API handlers.
Package handler provides upload HTTP API handlers.
apps/upload/ingest
Package ingest provides the programmatic upload domain service for Wavelet.
Package ingest provides the programmatic upload domain service for Wavelet.
apps/upload/shared
Package shared holds upload error and configuration constants shared across subpackages.
Package shared holds upload error and configuration constants shared across subpackages.
apps/upload/stats
Package stats maintains incremental upload statistics and aggregations.
Package stats maintains incremental upload statistics and aggregations.
apps/upload/storage
Package storage provides upload storage backend operations and migration state.
Package storage provides upload storage backend operations and migration state.
apps/upload/task
Package task provides upload-related async background task handlers.
Package task provides upload-related async background task handlers.
apps/upload/util
Package util provides upload media helpers and image utilities.
Package util provides upload media helpers and image utilities.
apps/user
Package user 提供用户认证与帐户管理功能
Package user 提供用户认证与帐户管理功能
bootstrap
Package bootstrap wires cross-module integrations and process-level subsystem initialization.
Package bootstrap wires cross-module integrations and process-level subsystem initialization.
buildinfo
Package buildinfo exposes metadata injected by the release workflow.
Package buildinfo exposes metadata injected by the release workflow.
cmd
Package cmd 提供 CLI 命令入口
Package cmd 提供 CLI 命令入口
common
Package common 提供跨模块共享的常量、错误定义和通用工具函数。
Package common 提供跨模块共享的常量、错误定义和通用工具函数。
common/response
Package response provides shared HTTP API response structures.
Package response provides shared HTTP API response structures.
config
Package config 负责应用配置的加载、解析与环境变量覆盖。
Package config 负责应用配置的加载、解析与环境变量覆盖。
db
Package db 提供数据库连接与基础设施
Package db 提供数据库连接与基础设施
db/batchwriter
Package batchwriter provides a reusable buffered batch writer for high-throughput append-only sinks such as ClickHouse.
Package batchwriter provides a reusable buffered batch writer for high-throughput append-only sinks such as ClickHouse.
db/idgen
Package idgen 提供分布式 ID 生成器
Package idgen 提供分布式 ID 生成器
db/migrator
Package migrator 提供数据库迁移功能
Package migrator 提供数据库迁移功能
diskcache
Package diskcache wraps the generic pkg/cache/disk to provide database configuration integration.
Package diskcache wraps the generic pkg/cache/disk to provide database configuration integration.
lifecycle
Package lifecycle manages global application and business component shutdown hooks.
Package lifecycle manages global application and business component shutdown hooks.
listener
Package listener provides domain event dispatch for cross-module integration.
Package listener provides domain event dispatch for cross-module integration.
model
Package model 定义数据模型与 GORM 实体
Package model 定义数据模型与 GORM 实体
model/analytics
Package analytics defines ClickHouse analytics domain models.
Package analytics defines ClickHouse analytics domain models.
repository
Package repository provides data access with caching and persistence boundaries.
Package repository provides data access with caching and persistence boundaries.
repository/analytics
Package analytics provides ClickHouse data access for analytics tables.
Package analytics provides ClickHouse data access for analytics tables.
router
Package router 提供 HTTP 路由注册与服务启动
Package router 提供 HTTP 路由注册与服务启动
router/root
Package root registers custom business routes and frontend serving.
Package root registers custom business routes and frontend serving.
router/v1
Package v1 contains router registrations for API V1
Package v1 contains router registrations for API V1
storage
Package storage provides dynamically configured file storage backends.
Package storage provides dynamically configured file storage backends.
task
Package task 定义异步任务类型与调度常量
Package task 定义异步任务类型与调度常量
task/handlers
Package handlers 注册异步任务处理器
Package handlers 注册异步任务处理器
task/scheduler
Package scheduler 提供定时任务调度功能
Package scheduler 提供定时任务调度功能
task/worker
Package worker 提供 Asynq 任务处理服务器与中间件
Package worker 提供 Asynq 任务处理服务器与中间件
testhelper
Package testhelper 提供测试辅助工具
Package testhelper 提供测试辅助工具
util
Package util provides framework-agnostic helper types and HTTP utilities.
Package util provides framework-agnostic helper types and HTTP utilities.
pkg
cache/disk
Package disk implements a platform-level disk-backed cache with size limit, TTL, and LRU eviction.
Package disk implements a platform-level disk-backed cache with size limit, TTL, and LRU eviction.
cache/ram
Package ram provides a thin wrapper around Otter v2 for process-local caching.
Package ram provides a thin wrapper around Otter v2 for process-local caching.
cap
Package cap 提供人机验证(CAPTCHA)功能
Package cap 提供人机验证(CAPTCHA)功能
httppool
Package httppool manages shared, optimized HTTP transports to reuse TCP connections.
Package httppool manages shared, optimized HTTP transports to reuse TCP connections.
logger
Package logger 提供结构化日志封装
Package logger 提供结构化日志封装
mail
Package mail 提供 SMTP 邮件发送功能。
Package mail 提供 SMTP 邮件发送功能。
push
Package push 提供解耦的、无外部业务依赖 of 通知推送底层实现
Package push 提供解耦的、无外部业务依赖 of 通知推送底层实现
trace
Package trace 提供 OpenTelemetry 链路追踪封装工具
Package trace 提供 OpenTelemetry 链路追踪封装工具
util
Package util provides generic utility functions.
Package util provides generic utility functions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL