create-luff-app 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/NOTES.md +190 -0
  2. package/README.md +189 -0
  3. package/package.json +2 -2
package/NOTES.md ADDED
@@ -0,0 +1,190 @@
1
+ # Luff Boilerplate
2
+
3
+ This repository contains a full-stack Next.js + Node.js Microservices architecture boilerplate, ready for local execution and seamless Kubernetes (K8s) deployment via ArgoCD.
4
+
5
+ Everything is containerized, fully configured for Google OAuth authentication, and automatically validated with CI/CD.
6
+
7
+ ---
8
+
9
+ ## 🚀 1. Initial Setup Required
10
+
11
+ Before running this project for the first time, you must configure your environment locally.
12
+
13
+ ### Prerequisites:
14
+
15
+ - **Node.js** (v20+)
16
+ - **Docker** and **Docker Desktop / Minikube**
17
+ - **kubectl** (connected to your local Kubernetes cluster)
18
+ - **ArgoCD** (must be installed on your local Kubernetes cluster)
19
+
20
+ ### Step 1: Install Dependencies & Setup Env Files
21
+
22
+ We have an automated setup script that installs NPM packages and copies the required `.env.example` files to `.env`.
23
+
24
+ ```bash
25
+ npm run setup
26
+ ```
27
+
28
+ Wait for `npm install` and Husky to finish.
29
+
30
+ ### Step 2: Configure Environment Variables
31
+
32
+ You MUST explicitly provide Google OAuth credentials and URLs for the frontend build and backend authentication to work. Check these three `.env` files and verify their values.
33
+
34
+ **1. `frontend/.env`**
35
+
36
+ ```env
37
+ NEXT_PUBLIC_API_URL=http://localhost:4000
38
+ NEXT_PUBLIC_GOOGLE_CLIENT_ID=your_client_id.apps.googleusercontent.com
39
+ ```
40
+
41
+ **2. `backend/auth/.env`**
42
+
43
+ ```env
44
+ PORT=4001
45
+ JWT_SECRET="your-jwt-secret-change-in-production"
46
+ GOOGLE_CLIENT_ID=your_client_id.apps.googleusercontent.com
47
+ GOOGLE_CLIENT_SECRET=your_client_secret
48
+ FRONTEND_URL=http://localhost:3000
49
+ NODE_ENV=development
50
+ ```
51
+
52
+ **3. `backend/posts/.env`**
53
+
54
+ ```env
55
+ PORT=4002
56
+ JWT_SECRET="your-jwt-secret-change-in-production"
57
+ NODE_ENV=development
58
+ ```
59
+
60
+ ### Step 3: Kubernetes Secrets
61
+
62
+ To deploy securely, pass your local backend secrets into Kubernetes so the pods can access them securely:
63
+
64
+ ```bash
65
+ # Create App Secrets
66
+ kubectl create secret generic app-secrets \
67
+ --from-literal=jwt-secret="your-jwt-secret-change-in-production"
68
+
69
+ # Create Auth Secrets
70
+ kubectl create secret generic auth-secrets \
71
+ --from-literal=google-client-id="your_google_client_id" \
72
+ --from-literal=google-client-secret="your_google_client_secret" \
73
+ --from-literal=frontend-url="http://localhost:3000" \
74
+ --from-literal=database-url="postgresql://postgres:postgres@auth-db-service:5432/auth_db"
75
+
76
+ # Create Posts Secrets
77
+ kubectl create secret generic posts-secrets \
78
+ --from-literal=database-url="postgresql://postgres:postgres@posts-db-service:5432/posts_db" \
79
+ --from-literal=jwt-secret="your-jwt-secret-change-in-production"
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 🌟 2. How To Run This For The First Time (Kubernetes)
85
+
86
+ We utilize ArgoCD as the GitOps agent. It constantly monitors your main branch's `k8s/` folder and applies the configuration locally.
87
+
88
+ ### Step 1: Tell ArgoCD to watch your directory
89
+
90
+ Apply the custom Application configuration directly:
91
+
92
+ ```bash
93
+ kubectl apply -f argocd/application.yaml
94
+ ```
95
+
96
+ ### Step 2: Build the Local Images (Automated)
97
+
98
+ Your Kubernetes `Deployment` manifests are configured to pull from `ghcr.io/luff-org/...` with an `IfNotPresent` pull policy. To run the images locally exactly as they are configured in your manifests, **we have created an automation script**.
99
+
100
+ This script pulls your `.env` Client ID, tags images according to your current commit SHA (what ArgoCD expects), and restarts the Kubernetes pods.
101
+
102
+ ```bash
103
+ ./scripts/deploy-local.sh
104
+ ```
105
+
106
+ ### Step 3: Port Forwarding
107
+
108
+ Because we are working locally, we must manually expose K8s services to `localhost`:
109
+
110
+ ```bash
111
+ # Terminal 1 - For the Frontend Application
112
+ kubectl port-forward svc/frontend-service 3000:3000
113
+
114
+ # Terminal 2 - For the API Gateway (Backend)
115
+ kubectl port-forward svc/api-gateway 4000:4000
116
+ ```
117
+
118
+ Visit `http://localhost:3000` — Your Google OAuth login will be functioning seamlessly.
119
+
120
+ ---
121
+
122
+ ## 🔄 3. What To Do Whenever You Run This Afterwards
123
+
124
+ When returning to development on a new day, you **DO NOT** need to repeat the secret configuration or ArgoCD setup. You just have to build any new changes and run your port-forwards.
125
+
126
+ 1. **Commit your code to Git**: Or ArgoCD will desync!
127
+ 2. **Run the Automation Script**: To push the newest changes directly to your local cluster:
128
+ ```bash
129
+ ./scripts/deploy-local.sh
130
+ ```
131
+ 3. **Start your tunnels**:
132
+ ```bash
133
+ kubectl port-forward svc/frontend-service 3000:3000
134
+ kubectl port-forward svc/api-gateway 4000:4000
135
+ ```
136
+
137
+ _(Alternatively, if you only want to develop quickly on your host machine WITHOUT Kubernetes, you can bypass Docker altogether by running `npm run dev` in the root folder!)_
138
+
139
+ ---
140
+
141
+ ## 🤖 4. Ensuring Automation Works (GitHub Actions CI/CD)
142
+
143
+ Whenever you push to `main` on GitHub, our unified pipeline (`.github/workflows/pipeline.yml`) runs automatically.
144
+
145
+ **To ensure this workflow succeeds on the cloud:**
146
+ You MUST add your `GOOGLE_CLIENT_ID` to GitHub Secrets. Failure to do so means the Cloud-built Docker image will have an empty Google Client ID baked into its statically-generated frontend!
147
+
148
+ **Go to GitHub**:
149
+
150
+ 1. Open Repository > `Settings`
151
+ 2. Navigate to `Secrets and variables` > `Actions`
152
+ 3. Click `New repository secret`
153
+ 4. **Name**: `GOOGLE_CLIENT_ID`
154
+ 5. **Secret**: `your_client_id.apps.googleusercontent.com`
155
+ 6. Click **Add secret**.
156
+
157
+ _(The frontend URL and other runtime variables are dynamically passed, but Next.js `NEXT_PUBLIC_` variables are physically built into the Docker image, so this is strictly required!)\_
158
+
159
+ ---
160
+
161
+ ## 🎨 5. Personalization & Customization (For New Users)
162
+
163
+ If you are cloning this boilerplate to start your own project, you need to update a few hardcoded values to point to your own GitHub Organization and Repository.
164
+
165
+ ### Step 1: Search and Replace
166
+
167
+ Search the entire repository for `luff-org` and replace it with your own **GitHub Username** or **Organization Name** (in lowercase).
168
+
169
+ - **Impacts**: K8s image paths, Docker tags, and CI/CD registry paths.
170
+
171
+ ### Step 2: Update ArgoCD Repo URL
172
+
173
+ Open `argocd/application.yaml` and update the `repoURL` to point to your new fork or repository:
174
+
175
+ ```yaml
176
+ repoURL: https://github.com/YOUR_ORG/YOUR_REPO.git
177
+ ```
178
+
179
+ ### Step 3: Update Production API URL
180
+
181
+ Open `.github/workflows/pipeline.yml` and update the `NEXT_PUBLIC_API_URL` under the `Build & Push` job to your actual production domain:
182
+
183
+ ```yaml
184
+ build-args: |
185
+ NEXT_PUBLIC_API_URL=https://api.your-actual-domain.com
186
+ ```
187
+
188
+ ### Step 4: Database Names & Secrets
189
+
190
+ If you change the service names or database names in the `k8s/` manifests, remember to update the corresponding `DATABASE_URL` strings in your **Kubernetes Secrets** (Step 1.3 above).
package/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # 💨 Luff Microservices Boilerplate
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/create-luff-app?color=blue&style=flat-square)](https://www.npmjs.com/package/create-luff-app)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.4-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
6
+
7
+ A **production-grade microservices monorepo** designed for speed, scalability, and developer experience. Built with Turborepo, Next.js, Express, Prisma, and PostgreSQL.
8
+
9
+ ---
10
+
11
+ ## 🚀 Quick Start with CLI
12
+
13
+ The fastest way to scaffold a new project using this boilerplate is with our official CLI:
14
+
15
+ ```bash
16
+ npx create-luff-app <your-app-name>
17
+ ```
18
+
19
+ > [!TIP]
20
+ > This command will clone the repository, install dependencies, and set up your project structure automatically.
21
+
22
+ ---
23
+
24
+ ## 📝 Operational Notes
25
+
26
+ For detailed troubleshooting on database connections, Kubernetes local setup, and Docker build fixes, see [NOTES.md](./NOTES.md).
27
+
28
+ ---
29
+
30
+ ## 🏗️ Architecture
31
+
32
+ ```text
33
+ ┌─────────────┐
34
+ │ API Gateway│ :4000
35
+ │ (Express) │
36
+ └──────┬──────┘
37
+
38
+ ┌────────────┼────────────┐
39
+ │ │
40
+ ┌─────┴─────┐ ┌──────┴─────┐
41
+ │ Auth │ │ Posts │
42
+ │ Service │ :4001 │ Service │ :4002
43
+ │ (Express) │ │ (Express) │
44
+ └─────┬─────┘ └──────┬─────┘
45
+ │ │
46
+ ┌─────┴─────┐ ┌──────┴─────┐
47
+ │ Auth DB │ │ Posts DB │
48
+ │ (Postgres)│ │ (Postgres) │
49
+ └───────────┘ └────────────┘
50
+
51
+ ┌─────────────────────────────┐
52
+ │ Frontend App │
53
+ │ (Next.js) │
54
+ │ :3000 │
55
+ └─────────────────────────────┘
56
+ ```
57
+
58
+ ---
59
+
60
+ ## 🛠️ Tech Stack
61
+
62
+ | Layer | Technology |
63
+ | :----------- | :------------------------------------------------ |
64
+ | **Frontend** | Next.js 14 (App Router), TailwindCSS, React Query |
65
+ | **Backend** | Node.js, Express, TypeScript |
66
+ | **Database** | PostgreSQL, Prisma ORM |
67
+ | **Auth** | Google OAuth (PostMessage flow), JWT |
68
+ | **Monorepo** | Turborepo, npm workspaces |
69
+ | **Infra** | Docker, Kubernetes (ArgoCD ready) |
70
+ | **Quality** | ESLint, Prettier, Husky, Commitlint |
71
+
72
+ ---
73
+
74
+ ## ⚡ Local Development Setup
75
+
76
+ Follow these steps to get your environment running from scratch.
77
+
78
+ ### 1. Prerequisites
79
+
80
+ Ensure you have the following installed:
81
+
82
+ - **Node.js**: `v20.x` or higher
83
+ - **Docker**: For running databases locally
84
+
85
+ ### 2. Installation
86
+
87
+ If you didn't use the CLI, clone and install manually:
88
+
89
+ ```bash
90
+ git clone https://github.com/Luff-Org/Luff-Boilerplate.git
91
+ cd Luff-Boilerplate
92
+ npm install
93
+ ```
94
+
95
+ ### 3. Environment & Databases
96
+
97
+ We provide a setup script to automate `.env` creation:
98
+
99
+ ```bash
100
+ # Automatically creates .env files from .env.example
101
+ npm run setup
102
+
103
+ # Spin up PostgreSQL instances via Docker
104
+ docker compose -f docker/docker-compose.yml up auth-db posts-db -d
105
+ ```
106
+
107
+ ### 4. Database Initialization
108
+
109
+ Generate Prisma clients and push schemas to your local databases:
110
+
111
+ ```bash
112
+ # Auth service
113
+ cd backend/auth && npm run db:push && npm run db:generate && cd ../..
114
+
115
+ # Posts service
116
+ cd backend/posts && npm run db:push && npm run db:generate && cd ../..
117
+ ```
118
+
119
+ ### 5. Start Developing
120
+
121
+ ```bash
122
+ npm run dev
123
+ ```
124
+
125
+ Your services will be available at:
126
+
127
+ - **Web Interface**: [http://localhost:3000](http://localhost:3000)
128
+ - **API Gateway**: [http://localhost:4000](http://localhost:4000)
129
+ - **Auth Service**: [http://localhost:4001](http://localhost:4001)
130
+ - **Posts Service**: [http://localhost:4002](http://localhost:4002)
131
+
132
+ ---
133
+
134
+ ## 📂 Project Structure
135
+
136
+ ```text
137
+ ├── frontend/ # Unified Next.js application
138
+ ├── backend/
139
+ │ ├── auth/ # Auth microservice (Google OAuth + JWT)
140
+ │ ├── posts/ # Posts microservice (CRUD)
141
+ │ └── api-gateway/ # Express Proxy & Rate Limiting
142
+ ├── shared/ # Shared internal packages (Types, Logger, Config)
143
+ ├── docker/ # Docker Compose configurations
144
+ ├── k8s/ # Kubernetes manifests
145
+ └── scripts/ # Automation & Setup scripts
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 🔐 Google OAuth Configuration
151
+
152
+ To enable authentication:
153
+
154
+ 1. Create OAuth credentials in [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
155
+ 2. Set authorized origin to `http://localhost:3000`.
156
+ 3. Update `GOOGLE_CLIENT_ID` in `backend/auth/.env` and `NEXT_PUBLIC_GOOGLE_CLIENT_ID` in `frontend/.env`.
157
+
158
+ ---
159
+
160
+ ## 🐳 Deployment
161
+
162
+ ### Docker Compose
163
+
164
+ ```bash
165
+ docker compose -f docker/docker-compose.yml up --build
166
+ ```
167
+
168
+ ### Kubernetes
169
+
170
+ ```bash
171
+ kubectl apply -f k8s/
172
+ ```
173
+
174
+ ---
175
+
176
+ ## 📜 Scripts
177
+
178
+ | Command | Description |
179
+ | :-------------- | :-------------------------------------- |
180
+ | `npm run dev` | Starts all services in development mode |
181
+ | `npm run build` | Builds all apps and packages |
182
+ | `npm run setup` | Initializes environment files |
183
+ | `npm run lint` | Runs linting across the monorepo |
184
+
185
+ ---
186
+
187
+ ## 📄 License
188
+
189
+ This project is licensed under the [MIT License](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-luff-app",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "CLI to scaffold the Luff Microservices Boilerplate",
5
5
  "bin": {
6
6
  "create-luff-app": "bin/cli.js"
@@ -16,4 +16,4 @@
16
16
  "url": "https://github.com/Luff-Org/Luff-Boilerplate"
17
17
  },
18
18
  "license": "MIT"
19
- }
19
+ }