phoenix

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 10 Imported by: 0

README ยถ

๐Ÿ”ฅ Phoenix

Live hot-reload runtime for Go applications with zero-downtime restarts.

Go Reference Go Report Card

Phoenix brings hot-reload to Go. Save your code, and Phoenix automatically rebuilds and restarts your applicationโ€”on Linux/macOS, it even transfers open TCP connections to the new process so clients never disconnect.

โœจ Features

  • ๐Ÿ”„ Instant Rebuilds โ€” File watcher detects changes and triggers builds automatically
  • ๐Ÿ”Œ Connection Handoff โ€” Open TCP connections transfer to new process (Linux/macOS)
  • ๐Ÿ’พ State Preservation โ€” Serialize sessions, caches, and counters across reloads
  • โšก Incremental Builds โ€” Source hashing skips rebuilds when nothing changed
  • ๐ŸŽจ Beautiful Output โ€” Powered by Aurora for stunning terminal UI
  • ๐Ÿ“ฆ SDK Integration โ€” Drop-in library for full hot-reload support in your apps
  • ๐ŸชŸ Cross-Platform โ€” Works on Windows, Linux, and macOS

๐Ÿš€ Quick Start

Installation
go install github.com/Summaw/GoPhoenix/cmd/phoenix@latest
Usage
phoenix ./cmd/myapp

That's it. Phoenix watches your files, rebuilds on save, and restarts your app.

With the SDK (Full Hot-Reload)

For connection handoff and state preservation, integrate the SDK:

package main

import (
    "net/http"
    "github.com/Summaw/GoPhoenix/pkg/sdk"
)

func main() {
    app := sdk.New(sdk.WithAddress(":8080"))

    mux := http.NewServeMux()
    mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("Hello from Phoenix! ๐Ÿ”ฅ"))
    })

    app.ListenAndServe(mux)
}

๐ŸŽฌ Demo

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•—   โ”‚
โ”‚   โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•   โ”‚
โ”‚   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ•”โ•    โ”‚
โ”‚   โ–ˆโ–ˆโ•”โ•โ•โ•โ• โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘   โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•—    โ”‚
โ”‚   โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ• โ–ˆโ–ˆโ•—   โ”‚
โ”‚   โ•šโ•โ•     โ•šโ•โ•  โ•šโ•โ• โ•šโ•โ•โ•โ•โ•โ• โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•โ•โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•   โ”‚
โ”‚                 Hot Reload Runtime for Go                  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
  12:34:56.789  โ— INFO   Starting Phoenix
                โ”œโ”€ target: ./cmd/server
                โ”œโ”€ watch: .
                โ””โ”€ binary: ./bin/app.exe
  12:34:56.812  โœ“ SUCCESS  Build successful
                โ”œโ”€ binary: ./bin/app.exe
                โ””โ”€ duration: 156ms
  12:34:56.834  โœ“ SUCCESS  Application started
                โ””โ”€ pid: 12345
  12:35:02.123  โ— INFO   Change detected
                โ””โ”€ file: ./handlers/api.go
  12:35:02.456  โœ“ SUCCESS  Build complete
                โ””โ”€ duration: 203ms
  12:35:02.478  โœ“ SUCCESS  Application restarted
                โ””โ”€ pid: 12346

๐Ÿ”ง How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Phoenix Daemon                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                              โ”‚
โ”‚   ๐Ÿ“ Watch Files  โ†’  ๐Ÿ”จ Rebuild  โ†’  ๐Ÿ”„ Handoff              โ”‚
โ”‚                                                              โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚   โ”‚  .go     โ”‚      โ”‚ go build โ”‚      โ”‚  New     โ”‚         โ”‚
โ”‚   โ”‚  files   โ”‚  โ”€โ”€โ–ถ โ”‚          โ”‚  โ”€โ”€โ–ถ โ”‚ Process  โ”‚         โ”‚
โ”‚   โ”‚  change  โ”‚      โ”‚          โ”‚      โ”‚          โ”‚         โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ”‚                                              โ”‚               โ”‚
โ”‚                           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚                           โ–ผ                                  โ”‚
โ”‚                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                          โ”‚
โ”‚                    โ”‚ Transfer:   โ”‚                          โ”‚
โ”‚                    โ”‚ โ€ข Listeners โ”‚                          โ”‚
โ”‚                    โ”‚ โ€ข State     โ”‚                          โ”‚
โ”‚                    โ”‚ โ€ข Sessions  โ”‚                          โ”‚
โ”‚                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

On Linux/macOS, Phoenix uses Unix socket file descriptor passing (SCM_RIGHTS) to transfer open TCP listeners between processesโ€”clients stay connected through the reload.

๐Ÿ“‹ CLI Options

phoenix [options] <package>

Options:
  -watch     Paths to watch (comma-separated)     default: "."
  -ext       File extensions to watch             default: ".go"
  -exclude   Paths to exclude                     default: "vendor,node_modules,.git"
  -bin       Output binary path                   default: "./bin/app"
  -drain     Graceful shutdown timeout            default: 30s
  -debug     Enable debug logging                 default: false

Examples:
  phoenix ./cmd/server
  phoenix -watch=./cmd,./internal ./cmd/api
  phoenix -ext=.go,.html -debug .

๐Ÿ’พ State Preservation

Keep data alive across reloads:

type MyCache struct {
    data map[string]string
    mu   sync.RWMutex
}

func (c *MyCache) Snapshot() ([]byte, error) {
    c.mu.RLock()
    defer c.mu.RUnlock()
    return json.Marshal(c.data)
}

func (c *MyCache) Restore(data []byte) error {
    c.mu.Lock()
    defer c.mu.Unlock()
    return json.Unmarshal(data, &c.data)
}

app := sdk.New(
    sdk.WithStateProvider("cache", myCache),
)

๐Ÿ†š Comparison

Feature Phoenix Air Fresh Realize
Hot reload โœ… โŒ โŒ โŒ
Zero downtime โœ… โŒ โŒ โŒ
Connection handoff โœ… โŒ โŒ โŒ
State preservation โœ… โŒ โŒ โŒ
SDK integration โœ… โŒ โŒ โŒ
Cross-platform โœ… โœ… โœ… โœ…
Beautiful UI โœ… โš ๏ธ โŒ โš ๏ธ

๐Ÿ“ Project Structure

phoenix/
โ”œโ”€โ”€ cmd/phoenix/          # CLI daemon
โ”œโ”€โ”€ pkg/sdk/              # Application SDK
โ”œโ”€โ”€ internal/
โ”‚   โ”œโ”€โ”€ watcher/          # File system monitoring
โ”‚   โ”œโ”€โ”€ compiler/         # Build orchestration
โ”‚   โ”œโ”€โ”€ handoff/          # Connection & state transfer
โ”‚   โ”œโ”€โ”€ process/          # Process lifecycle
โ”‚   โ””โ”€โ”€ state/            # State serialization
โ””โ”€โ”€ examples/basic/       # Demo application

โš ๏ธ Platform Notes

Platform Connection Handoff State Transfer
Linux โœ… Full support โœ…
macOS โœ… Full support โœ…
Windows โŒ Quick restart โœ…

On Windows, Phoenix performs a fast restart instead of true zero-downtime handoff (Unix sockets required for FD passing).

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.

๐Ÿ™ Credits

  • Terminal UI powered by Aurora
  • Inspired by Erlang's hot code loading

Like Phoenix? Give it a โญ to support the project!

Documentation ยถ

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

This section is empty.

Functions ยถ

This section is empty.

Types ยถ

type Option ยถ

type Option func(*Phoenix)

func WithAddress ยถ

func WithAddress(addr string) Option

func WithConfig ยถ

func WithConfig(cfg *config.Config) Option

func WithDrainTimeout ยถ

func WithDrainTimeout(d time.Duration) Option

func WithLogger ยถ

func WithLogger(log *aurora.Logger) Option

func WithStateProvider ยถ

func WithStateProvider(provider state.Provider) Option

func WithWatchPaths ยถ

func WithWatchPaths(paths ...string) Option

type Phoenix ยถ

type Phoenix struct {
	// contains filtered or unexported fields
}

func New ยถ

func New(opts ...Option) *Phoenix

func (*Phoenix) Context ยถ

func (p *Phoenix) Context() context.Context

func (*Phoenix) IsChild ยถ

func (p *Phoenix) IsChild() bool

func (*Phoenix) Listen ยถ

func (p *Phoenix) Listen(network, address string) (net.Listener, error)

func (*Phoenix) Listener ยถ

func (p *Phoenix) Listener() net.Listener

func (*Phoenix) Ready ยถ

func (p *Phoenix) Ready()

func (*Phoenix) RegisterState ยถ

func (p *Phoenix) RegisterState(name string, provider state.Provider)

func (*Phoenix) Run ยถ

func (p *Phoenix) Run(serve func(net.Listener) error) error

func (*Phoenix) Shutdown ยถ

func (p *Phoenix) Shutdown(ctx context.Context) error

Directories ยถ

Path Synopsis
cmd
phoenix command
examples
basic command
internal
ui
pkg
sdk

Jump to

Keyboard shortcuts

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