# 🐱 NekoFlow - Go + Next.js Monorepo [![Language](https://img.shields.io/badge/Language-English-blue)](README.md) [![Language](https://img.shields.io/badge/Language-TiαΊΏng_Việt-red)](README.vi.md) > **[Đọc bαΊ±ng tiαΊΏng Việt](README.vi.md)** Single binary application combining Go backend with Next.js frontend. ## πŸ“¦ Project Structure ``` nekoflow/ β”œβ”€β”€ apps/ β”‚ β”œβ”€β”€ web/ # Next.js 14 (Frontend - Static Export) β”‚ └── server-go/ # Go backend + Static file server β”œβ”€β”€ scripts/ # Build scripts └── dist/ # Build output ``` ## πŸš€ Quick Start ### Prerequisites - Node.js 18+ - Go 1.21+ ### Installation ```bash # 1. Install dependencies npm install # 2. Option A: Dev Next.js only (with hot reload) npm run dev:web # http://localhost:3000 # 3. Option B: Full stack with Go npm run build:dev # Build Next.js + sync to Go npm run dev:go # Run Go server β†’ http://localhost:8080 ``` ## πŸ’» Development ### Frontend Development (Next.js) ```bash npm run dev:web # Hot reload on port 3000 ``` ### Full Stack Development (Next.js + Go) **Terminal 1: Build & sync when you change Next.js code** ```bash npm run build:dev ``` **Terminal 2: Run Go server** ```bash npm run dev:go # http://localhost:8080 ``` **After changing Next.js code:** ```bash npm run build:dev # Re-build and sync # Go server will auto-serve new files (no restart needed) ``` ## πŸ”¨ Build ### Development Build (Quick) ```bash npm run build:dev # β†’ Builds Next.js + syncs to Go static folder ``` ### Production Binary ```bash npm run build # β†’ Builds Next.js + Go binary # β†’ Output: dist/nekoflow (single binary ~10-30MB) ``` ### Available Commands | Command | Description | |---------|-------------| | `npm run dev:web` | Dev Next.js only (port 3000, hot reload) | | `npm run dev:go` | Run Go server (port 8080) | | `npm run build:web` | Build Next.js static export | | `npm run sync:static` | Copy Next.js build β†’ Go static folder | | `npm run build:dev` | Build + sync (for development) | | `npm run build` | Full production build (creates binary) | ## 🎯 Deploy ### Simple Deployment ```bash # Just copy and run the binary ./dist/nekoflow # Or specify port PORT=8080 ./dist/nekoflow ``` ### Deploy to Linux Server ```bash # 1. Build for Linux npm run build # 2. Upload scp dist/nekoflow-linux user@server:/opt/nekoflow # 3. Run on server ssh user@server chmod +x /opt/nekoflow ./nekoflow ``` ### Docker (Optional) ```dockerfile FROM scratch COPY dist/nekoflow /nekoflow ENTRYPOINT ["/nekoflow"] ``` ## πŸ—οΈ Architecture ### How It Works ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Single Binary (nekoflow) β”‚ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ Go Server β”‚ β”‚ Static Files β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ (Next.js) β”‚ β”‚ β”‚ β”‚ - API β”‚ β”‚ - HTML β”‚ β”‚ β”‚ β”‚ - Router β”‚ β”‚ - CSS β”‚ β”‚ β”‚ β”‚ - Embedded β”‚ β”‚ - JS β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ↓ Single Port (8080) ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Browser β”‚ β”‚ - UI β”‚ β”‚ - API call β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ### Tech Stack **Frontend:** - Next.js 14 (Static Export) - React 18 - TypeScript - Tailwind CSS **Backend:** - Go 1.21+ - gorilla/mux (Router) - embed (Static files) **Build:** - npm workspaces - Bash scripts - Go build ## ❓ FAQ ### Is this SSR (Server-Side Rendering)? **No.** This uses Next.js **Static Export** (SSG - Static Site Generation). - Next.js pre-renders pages to HTML at build time - Go only serves static files (HTML/CSS/JS) - React hydrates on the client-side - API calls happen client-side via `fetch()` ### Can I use getServerSideProps? **No.** Static Export doesn't support: - `getServerSideProps()` - `getServerData()` - ISR (Incremental Static Regeneration) Use `'use client'` with `useEffect()` and `fetch()` instead. ### Why Go + Next.js? - βœ… **Single binary** - Easy deployment - βœ… **No Node.js runtime** needed in production - βœ… **Performance** - Go is fast and lightweight - βœ… **Modern DX** - React + TypeScript + Tailwind - βœ… **Cross-platform** - Compile for Linux/Mac/Windows ### Binary size? Typically **10-30MB** depending on: - Go code size - Next.js bundle size - Static assets (images, fonts) ## πŸ“ License MIT ## 🀝 Contributing Contributions welcome! Feel free to open issues or PRs. --- **Built with ❀️ using Go + Next.js + TypeScript**