update readme
This commit is contained in:
173
README.md
173
README.md
@@ -1,53 +1,66 @@
|
||||
# 🐱 CatSave - Go + Next.js Monorepo
|
||||
# 🐱 NekoFlow - Go + Next.js Monorepo
|
||||
|
||||
Single binary application with Go backend + Next.js frontend.
|
||||
[](README.md)
|
||||
[](README.vi.md)
|
||||
|
||||
## 📦 Structure
|
||||
> **[Đọc bằng tiếng Việt](README.vi.md)**
|
||||
|
||||
Single binary application combining Go backend with Next.js frontend.
|
||||
|
||||
## 📦 Project Structure
|
||||
|
||||
```
|
||||
catsave/
|
||||
nekoflow/
|
||||
├── apps/
|
||||
│ ├── web/ # Next.js frontend (static export)
|
||||
│ └── server-go/ # Go backend + static file server
|
||||
│ ├── web/ # Next.js 14 (Frontend - Static Export)
|
||||
│ └── server-go/ # Go backend + Static file server
|
||||
├── scripts/ # Build scripts
|
||||
└── dist/ # Build output
|
||||
```
|
||||
|
||||
## 🚀 Development
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Prerequisites
|
||||
- Node.js 18+
|
||||
- Go 1.21+
|
||||
|
||||
### Installation
|
||||
|
||||
### Quick Start
|
||||
```bash
|
||||
# 1. Install dependencies
|
||||
npm install
|
||||
|
||||
# 2. Option A: Dev Next.js only
|
||||
# 2. Option A: Dev Next.js only (with hot reload)
|
||||
npm run dev:web # http://localhost:3000
|
||||
|
||||
# 3. Option B: Dev with Go
|
||||
# 3. Option B: Full stack with Go
|
||||
npm run build:dev # Build Next.js + sync to Go
|
||||
npm run dev:go # Run Go server
|
||||
npm run dev:go # Run Go server → http://localhost:8080
|
||||
```
|
||||
|
||||
### Workflow
|
||||
## 💻 Development
|
||||
|
||||
**Frontend Development (Next.js):**
|
||||
### Frontend Development (Next.js)
|
||||
```bash
|
||||
npm run dev:web # Hot reload on :3000
|
||||
npm run dev:web # Hot reload on port 3000
|
||||
```
|
||||
|
||||
**Full Stack Development (Next.js + Go):**
|
||||
### Full Stack Development (Next.js + Go)
|
||||
|
||||
**Terminal 1: Build & sync when you change Next.js code**
|
||||
```bash
|
||||
# Terminal 1: Build & sync on changes
|
||||
npm run build:dev
|
||||
```
|
||||
|
||||
# Terminal 2: Run Go server
|
||||
**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
|
||||
# Go server will auto-serve new files (no restart needed)
|
||||
```
|
||||
|
||||
## 🔨 Build
|
||||
@@ -62,38 +75,134 @@ npm run build:dev
|
||||
```bash
|
||||
npm run build
|
||||
# → Builds Next.js + Go binary
|
||||
# → Output: dist/catsave (single binary)
|
||||
# → Output: dist/nekoflow (single binary ~10-30MB)
|
||||
```
|
||||
|
||||
### Available Commands
|
||||
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `npm run dev:web` | Dev Next.js only (port 3000) |
|
||||
| `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 → Go static |
|
||||
| `npm run build:dev` | Build + sync (development) |
|
||||
| `npm run build` | Full production build |
|
||||
| `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 the binary
|
||||
./dist/catsave
|
||||
# Just copy and run the binary
|
||||
./dist/nekoflow
|
||||
|
||||
# Runs on http://localhost:8080
|
||||
# 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
|
||||
|
||||
- **Go**: API + serve static files (embedded)
|
||||
- **Next.js**: Static export (HTML/CSS/JS)
|
||||
- **Result**: One binary file (~10-30MB)
|
||||
### How It Works
|
||||
|
||||
## 📝 Tech Stack
|
||||
```
|
||||
┌─────────────────────────────────────┐
|
||||
│ Single Binary (nekoflow) │
|
||||
│ │
|
||||
│ ┌────────────┐ ┌──────────────┐ │
|
||||
│ │ Go Server │ │ Static Files │ │
|
||||
│ │ │ │ (Next.js) │ │
|
||||
│ │ - API │ │ - HTML │ │
|
||||
│ │ - Router │ │ - CSS │ │
|
||||
│ │ - Embedded │ │ - JS │ │
|
||||
│ └────────────┘ └──────────────┘ │
|
||||
└─────────────────────────────────────┘
|
||||
↓
|
||||
Single Port (8080)
|
||||
↓
|
||||
┌─────────────┐
|
||||
│ Browser │
|
||||
│ - UI │
|
||||
│ - API call │
|
||||
└─────────────┘
|
||||
```
|
||||
|
||||
- Go 1.21+
|
||||
- Next.js 14
|
||||
### 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**
|
||||
|
||||
Reference in New Issue
Block a user