# Refreshing πŸš€ A modern, production-ready full-stack boilerplate for building scalable web applications [δΈ­ζ–‡](./README_zh.md) [![License: Apache2.0](https://img.shields.io/badge/License-Apache2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Go Version](https://img.shields.io/badge/Go-1.25+-blue.svg)](https://golang.org/) [![Next.js](https://img.shields.io/badge/Next.js-16-black.svg)](https://nextjs.org/) [![React](https://img.shields.io/badge/React-19-blue.svg)](https://reactjs.org/) ## πŸ“– Introduction **Refreshing** 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](https://github.com/hibiken/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+](https://go.dev/doc)** β€” Primary language - **[Gin](https://github.com/gin-gonic/gin)** β€” HTTP web framework - **[GORM](https://github.com/go-gorm/gorm)** β€” ORM with PostgreSQL & ClickHouse support - **[Redis](https://github.com/redis/redis)** β€” Cache, session store, and task queue backend - **[Asynq](https://github.com/hibiken/asynq)** β€” Distributed task queue (Redis-backed) - **[Cobra + Viper](https://github.com/spf13/cobra)** β€” CLI entrypoint and configuration management - **[OpenTelemetry](https://opentelemetry.io)** β€” Distributed tracing and observability - **[Zap](https://github.com/uber-go/zap)** β€” Structured, high-performance logging - **[Swagger (Swaggo)](https://github.com/swaggo/swag)** β€” Auto-generated API documentation - **[AWS SDK v2](https://github.com/aws/aws-sdk-go-v2)** β€” S3-compatible file storage - **[Snowflake](https://github.com/bwmarrin/snowflake)** β€” Distributed ID generation ### Frontend - **[Next.js 16](https://github.com/vercel/next.js)** β€” React framework with App Router - **[React 19](https://github.com/facebook/react)** β€” UI library - **[TypeScript](https://github.com/microsoft/TypeScript)** β€” Type safety - **[Tailwind CSS 4](https://github.com/tailwindlabs/tailwindcss)** β€” Utility-first styling - **[Shadcn UI](https://github.com/shadcn-ui/ui)** β€” Accessible, composable component library - **[Lucide Icons](https://github.com/lucide-icons/lucide)** β€” Icon library ## πŸ“‹ Requirements - **Go** >= 1.25 - **Node.js** >= 18.0 - **PostgreSQL** >= 14 - **Redis** >= 6.0 - **pnpm** >= 8.0 (recommended) ## πŸš€ Quick Start ### 1. Clone the Repository ```bash git clone https://github.com/linux-do/credit.git refreshing cd refreshing ``` ### 2. Configure Environment ```bash 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 ```bash # 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 -p 5432 -U postgres refreshing # Database schema is auto-migrated on first startup ``` ### 4. Start the Backend ```bash # 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: > ```bash > go run main.go scheduler # Cron job scheduler > go run main.go worker # Asynq task worker > ``` ### 5. Start the Frontend ```bash 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 ```bash # 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 ```bash cd frontend # Development mode (Turbopack) pnpm dev # Production build pnpm build # Start production server pnpm start # Lint & format pnpm lint pnpm format ``` ## πŸ“ Project Structure ``` Refreshing/ β”œβ”€β”€ main.go # Entry point (delegates to internal/cmd) β”œβ”€β”€ config.example.yaml # Configuration template β”œβ”€β”€ Makefile # Common commands (swagger, tidy, license) β”œβ”€β”€ Dockerfile # Container image build β”œβ”€β”€ 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 ```bash # Backend tests go test ./... # Frontend lint cd frontend && pnpm lint ``` ## πŸš€ Deployment ### Docker ```bash # 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: ```bash cd frontend && pnpm build ``` 2. Compile the backend: ```bash go build -o refreshing main.go ``` 3. Configure `config.yaml` for production. 4. Start services: ```bash ./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: - [Contributing Guidelines](CONTRIBUTING.md) - [Code of Conduct](CODE_OF_CONDUCT.md) - [Contributor License Agreement](CLA.md) ### 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](LICENSE).