create-luff-app 1.0.4 → 1.0.6

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 +216 -0
  2. package/README.md +118 -85
  3. package/package.json +2 -2
package/NOTES.md ADDED
@@ -0,0 +1,216 @@
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"
57
+ NODE_ENV=development
58
+ ```
59
+
60
+ **4. `backend/payment/.env`**
61
+
62
+ ```env
63
+ PORT=4003
64
+ RAZORPAY_KEY_ID=rzp_test_your_id
65
+ RAZORPAY_KEY_SECRET=your_secret_key
66
+ DATABASE_URL="postgresql://postgres:postgres@localhost:5435/payment_db"
67
+ JWT_SECRET="your-jwt-secret"
68
+ NODE_ENV=development
69
+ ```
70
+
71
+ ### Step 3: Kubernetes Secrets
72
+
73
+ ```bash
74
+ # App, Auth & Posts Secrets (...)
75
+
76
+ # Create Payment Secrets
77
+ kubectl create secret generic payment-secrets \
78
+ --from-literal=database-url="postgresql://postgres:postgres@payment-db-service:5432/payment_db" \
79
+ --from-literal=razorpay-key-id="your_key" \
80
+ --from-literal=razorpay-key-secret="your_secret" \
81
+ --from-literal=jwt-secret="your-jwt-secret"
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 🌟 2. How To Run Locally
87
+
88
+ We support two modes of development:
89
+
90
+ ### 1. Native Mode (Recommended)
91
+
92
+ This is the fastest loop. Run everything directly on your machine:
93
+
94
+ ```bash
95
+ npm run run-local
96
+ ```
97
+
98
+ This script handles:
99
+
100
+ - Stopping K8s port conflicts
101
+ - Starting local Docker DBs
102
+ - Running all services via `npm run dev`
103
+
104
+ ### 2. Kubernetes Mode (GitOps)
105
+
106
+ Follow this if you want to test the full K8s stack:
107
+
108
+ 1. **Build & Deploy**: `npm run run-k8s build`
109
+ 2. **Access Dashboard**: `npm run argo`
110
+ 3. **Connect Ports**: `npm run access`
111
+
112
+ We utilize ArgoCD as the GitOps agent. It constantly monitors your main branch's `k8s/` folder and applies the configuration locally.
113
+
114
+ ### Step 1: Tell ArgoCD to watch your directory
115
+
116
+ Apply the custom Application configuration directly:
117
+
118
+ ```bash
119
+ kubectl apply -f argocd/application.yaml
120
+ ```
121
+
122
+ ### Step 2: Build the Local Images (Automated)
123
+
124
+ 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**.
125
+
126
+ This script pulls your `.env` Client ID, tags images according to your current commit SHA (what ArgoCD expects), and restarts the Kubernetes pods.
127
+
128
+ ```bash
129
+ ./scripts/deploy-local.sh
130
+ ```
131
+
132
+ ### Step 3: Port Forwarding
133
+
134
+ Because we are working locally, we must manually expose K8s services to `localhost`:
135
+
136
+ ```bash
137
+ # Terminal 1 - For the Frontend Application
138
+ kubectl port-forward svc/frontend-service 3000:3000
139
+
140
+ # Terminal 2 - For the API Gateway (Backend)
141
+ kubectl port-forward svc/api-gateway 4000:4000
142
+ ```
143
+
144
+ Visit `http://localhost:3000` — Your Google OAuth login will be functioning seamlessly.
145
+
146
+ ---
147
+
148
+ ## 🔄 3. What To Do Whenever You Run This Afterwards
149
+
150
+ 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.
151
+
152
+ 1. **Commit your code to Git**: Or ArgoCD will desync!
153
+ 2. **Run the Automation Script**: To push the newest changes directly to your local cluster:
154
+ ```bash
155
+ ./scripts/deploy-local.sh
156
+ ```
157
+ 3. **Start your tunnels**:
158
+ ```bash
159
+ kubectl port-forward svc/frontend-service 3000:3000
160
+ kubectl port-forward svc/api-gateway 4000:4000
161
+ ```
162
+
163
+ _(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!)_
164
+
165
+ ---
166
+
167
+ ## 🤖 4. Ensuring Automation Works (GitHub Actions CI/CD)
168
+
169
+ Whenever you push to `main` on GitHub, our unified pipeline (`.github/workflows/pipeline.yml`) runs automatically.
170
+
171
+ **To ensure this workflow succeeds on the cloud:**
172
+ 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!
173
+
174
+ **Go to GitHub**:
175
+
176
+ 1. Open Repository > `Settings`
177
+ 2. Navigate to `Secrets and variables` > `Actions`
178
+ 3. Click `New repository secret`
179
+ 4. **Name**: `GOOGLE_CLIENT_ID`
180
+ 5. **Secret**: `your_client_id.apps.googleusercontent.com`
181
+ 6. Click **Add secret**.
182
+
183
+ _(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!)\_
184
+
185
+ ---
186
+
187
+ ## 🎨 5. Personalization & Customization (For New Users)
188
+
189
+ 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.
190
+
191
+ ### Step 1: Search and Replace
192
+
193
+ Search the entire repository for `luff-org` and replace it with your own **GitHub Username** or **Organization Name** (in lowercase).
194
+
195
+ - **Impacts**: K8s image paths, Docker tags, and CI/CD registry paths.
196
+
197
+ ### Step 2: Update ArgoCD Repo URL
198
+
199
+ Open `argocd/application.yaml` and update the `repoURL` to point to your new fork or repository:
200
+
201
+ ```yaml
202
+ repoURL: https://github.com/YOUR_ORG/YOUR_REPO.git
203
+ ```
204
+
205
+ ### Step 3: Update Production API URL
206
+
207
+ Open `.github/workflows/pipeline.yml` and update the `NEXT_PUBLIC_API_URL` under the `Build & Push` job to your actual production domain:
208
+
209
+ ```yaml
210
+ build-args: |
211
+ NEXT_PUBLIC_API_URL=https://api.your-actual-domain.com
212
+ ```
213
+
214
+ ### Step 4: Database Names & Secrets
215
+
216
+ 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 CHANGED
@@ -1,10 +1,35 @@
1
- # Microservices Boilerplate
1
+ # 💨 Luff Microservices Boilerplate
2
2
 
3
- A **production-grade microservices monorepo** built with Turborepo, TypeScript, Next.js, Express, Prisma, and PostgreSQL.
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/)
4
6
 
5
- ## Architecture
7
+ A **production-grade microservices monorepo** designed for speed, scalability, and developer experience. Built with Turborepo, Next.js, Express, Prisma, and PostgreSQL.
6
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>
7
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
8
33
  ┌─────────────┐
9
34
  │ API Gateway│ :4000
10
35
  │ (Express) │
@@ -30,127 +55,135 @@ A **production-grade microservices monorepo** built with Turborepo, TypeScript,
30
55
  └─────────────────────────────┘
31
56
  ```
32
57
 
33
- ## Tech Stack
34
-
35
- | Layer | Technology |
36
- | ------------ | -------------------------------------------- |
37
- | Frontend | Next.js 14, React, TailwindCSS, React Query |
38
- | API Client | Axios |
39
- | Backend | Node.js, Express, TypeScript |
40
- | Database | PostgreSQL, Prisma ORM |
41
- | Auth | Google OAuth (PostMessage flow), JWT |
42
- | Gateway | http-proxy-middleware, rate-limit |
43
- | Monorepo | Turborepo, npm workspaces |
44
- | Logging | Pino |
45
- | Config | Zod validation, dotenv |
46
- | Docker | Multi-stage builds |
47
- | Orchestrator | Kubernetes |
48
- | Code Quality | ESLint, Prettier, Husky, Commitlint |
49
-
50
- ## Quick Start
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:
51
88
 
52
89
  ```bash
53
- # 1. Clone and install
54
- git clone <repo-url>
90
+ git clone https://github.com/Luff-Org/Luff-Boilerplate.git
55
91
  cd Luff-Boilerplate
56
92
  npm install
93
+ ```
94
+
95
+ ### 3. Environment & Databases
57
96
 
58
- # 2. Copy environment files
59
- bash scripts/setup.sh
97
+ We provide a setup script to automate `.env` creation:
60
98
 
61
- # 3. Start databases (requires Docker)
99
+ ```bash
100
+ # Automatically creates .env files from .env.example
101
+ npm run setup
102
+
103
+ # Spin up PostgreSQL instances via Docker
62
104
  docker compose -f docker/docker-compose.yml up auth-db posts-db -d
105
+ ```
63
106
 
64
- # 4. Generate Prisma clients and push schemas
107
+ ### 4. Database Initialization
108
+
109
+ Generate Prisma clients and push schemas to your local databases:
110
+
111
+ ```bash
112
+ # Auth service
65
113
  cd backend/auth && npm run db:push && npm run db:generate && cd ../..
114
+
115
+ # Posts service
66
116
  cd backend/posts && npm run db:push && npm run db:generate && cd ../..
117
+ ```
67
118
 
68
- # 5. Start all services
119
+ ### 5. Start Developing
120
+
121
+ ```bash
69
122
  npm run dev
70
123
  ```
71
124
 
72
- This starts:
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)
73
131
 
74
- | Service | URL |
75
- | -------------- | ---------------------- |
76
- | API Gateway | http://localhost:4000 |
77
- | Auth Service | http://localhost:4001 |
78
- | Posts Service | http://localhost:4002 |
79
- | Web Frontend | http://localhost:3000 |
132
+ ---
80
133
 
81
- ## Project Structure
134
+ ## 📂 Project Structure
82
135
 
83
136
  ```text
84
- ├── frontend/ # Unified Next.js application (Auth + Posts)
137
+ ├── frontend/ # Unified Next.js application
85
138
  ├── backend/
86
- │ ├── auth/ # Auth microservice (Google OAuth postmessage, JWT)
139
+ │ ├── auth/ # Auth microservice (Google OAuth + JWT)
87
140
  │ ├── posts/ # Posts microservice (CRUD)
88
- │ └── api-gateway/ # API Gateway (Express proxy, rate-limit)
89
- ├── shared/
90
- ├── types/ # Shared TypeScript types
91
- ├── logger/ # Shared Pino logger setup
92
- │ ├── config/ # Zod env validation schema
93
- │ └── eslint-config/ # Default ESLint rules
94
- ├── docker/ # Docker Compose Definitions
95
- ├── k8s/ # Kubernetes Manifests
96
- └── scripts/ # CI/CD and Local Setup Scripts
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
97
146
  ```
98
147
 
99
- ## API Endpoints
148
+ ---
100
149
 
101
- ### Auth Service (Proxied via Gateway `:4000`)
150
+ ## 🔐 Google OAuth Configuration
102
151
 
103
- | Method | Endpoint | Auth | Description |
104
- | ------ | -------------- | ---- | ----------------------------- |
105
- | POST | /auth/login | No | Google OAuth postmessage login|
106
- | GET | /auth/me | Yes | Get current user profile |
107
- | POST | /auth/logout | Yes | Logout (clear session) |
152
+ To enable authentication:
108
153
 
109
- ### Posts Service (Proxied via Gateway `:4000`)
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`.
110
157
 
111
- | Method | Endpoint | Auth | Description |
112
- | ------ | -------------- | ---- | -------------------- |
113
- | GET | /posts | No | List all posts |
114
- | GET | /posts/:id | No | Get post by ID |
115
- | POST | /posts | Yes | Create a post |
116
- | DELETE | /posts/:id | Yes | Delete a post |
158
+ ---
117
159
 
118
- ## Docker
160
+ ## 🐳 Deployment
119
161
 
120
- ### Run with Docker Compose
162
+ ### Docker Compose
121
163
 
122
164
  ```bash
123
165
  docker compose -f docker/docker-compose.yml up --build
124
166
  ```
125
167
 
126
- ### Build individual images
168
+ ### Kubernetes
127
169
 
128
170
  ```bash
129
- docker build -f backend/auth/Dockerfile -t auth-service .
130
- docker build -f backend/posts/Dockerfile -t posts-service .
131
- docker build -f backend/api-gateway/Dockerfile -t api-gateway .
132
- docker build -f frontend/Dockerfile -t frontend-app .
171
+ kubectl apply -f k8s/
133
172
  ```
134
173
 
135
- ## Kubernetes
136
-
137
- ```bash
138
- # Apply all manifests
139
- kubectl apply -f k8s/
174
+ ---
140
175
 
141
- # Note: You must manually deploy secrets in your cluster:
142
- # - auth-secrets (database-url, jwt-secret, google auth credentials)
143
- # - posts-secrets (database-url, jwt-secret)
144
- ```
176
+ ## 📜 Scripts
145
177
 
146
- ## Scripts
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 |
147
184
 
148
- ```bash
149
- npm run dev # Start all services (Turborepo)
150
- npm run build # Build all TypeScript packages & apps
151
- npm run lint # Lint across the monorepo
152
- ```
185
+ ---
153
186
 
154
- ## License
187
+ ## 📄 License
155
188
 
156
- MIT
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.4",
3
+ "version": "1.0.6",
4
4
  "description": "CLI to scaffold the Luff Microservices Boilerplate",
5
5
  "bin": {
6
6
  "create-luff-app": "bin/cli.js"
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "https://github.com/Luff-Org/Luff-Boilerplate"
16
+ "url": "git+https://github.com/Luff-Org/Luff-Boilerplate.git"
17
17
  },
18
18
  "license": "MIT"
19
19
  }