@gv-sh/specgen-app 0.5.0 → 0.5.1

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.
package/README.md CHANGED
@@ -1,14 +1,21 @@
1
1
  # SpecGen App - Complete Platform
2
2
 
3
- [![Version](https://img.shields.io/badge/version-0.5.0-blue.svg)](https://github.com/gv-sh/specgen-app)
3
+ [![Version](https://img.shields.io/badge/version-0.5.1-blue.svg)](https://github.com/gv-sh/specgen-app)
4
4
 
5
- A unified deployment package for the SpecGen speculative fiction generator platform.
5
+ A unified deployment package for the SpecGen speculative fiction generator platform. **Now optimized for low-memory servers and unified on port 8080!**
6
+
7
+ ## 🚀 What's New
8
+
9
+ - **Single Port Deployment**: Everything runs on port 8080 with clean URL paths
10
+ - **Low Memory Default**: Optimized for small servers and EC2 instances
11
+ - **Automatic Cleanup**: Smart setup that cleans existing installations
12
+ - **Unified Interface**: All services accessible through one port
6
13
 
7
14
  ## Components
8
15
 
9
- - **Server**: Node.js API with OpenAI integration
10
- - **Admin**: React admin interface for content management
11
- - **User**: React user interface for story generation
16
+ - **Server**: Node.js API with OpenAI integration (Port 8080)
17
+ - **Admin**: React admin interface at `/admin`
18
+ - **User**: React user interface at `/app` (also default at `/`)
12
19
 
13
20
  ## Quick Start
14
21
 
@@ -19,274 +26,238 @@ A unified deployment package for the SpecGen speculative fiction generator platf
19
26
  mkdir specgen-project
20
27
  cd specgen-project
21
28
 
22
- # Run setup directly with npx
29
+ # Run setup (automatically includes low-memory optimizations and cleanup)
23
30
  npx @gv-sh/specgen-app setup
24
31
 
25
- # Start in development mode
32
+ # Start in development mode (traditional separate ports)
26
33
  npx @gv-sh/specgen-app dev
27
34
 
28
- # Or start in production mode
35
+ # Or start in production mode (unified port 8080)
29
36
  npx @gv-sh/specgen-app production
30
- ```
31
37
 
32
- ### Low Memory Mode for Small Servers
33
-
34
- If you're deploying on a small EC2 instance or any server with limited RAM:
35
-
36
- ```bash
37
- # First, add swap space to prevent out-of-memory errors
38
- sudo fallocate -l 2G /swapfile
39
- sudo chmod 600 /swapfile
40
- sudo mkswap /swapfile
41
- sudo swapon /swapfile
42
- echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
43
-
44
- # Then use the low-memory versions of the commands
45
- npx @gv-sh/specgen-app setup-low-memory
46
- npx @gv-sh/specgen-app production-low-memory
38
+ # Or deploy with PM2 (recommended for servers)
39
+ npx @gv-sh/specgen-app deploy
47
40
  ```
48
41
 
49
- ### Using NPM Scripts
50
-
51
- 1. **Setup**:
52
- ```bash
53
- npm run setup
54
- ```
55
- During setup, you'll be prompted to enter your OpenAI API key.
56
-
57
- 2. **Add OpenAI API Key** to `server/.env` if you skipped during setup
58
-
59
- 3. **Start Development**:
60
- ```bash
61
- npm run dev
62
- ```
63
-
64
- 4. **Start Production** (optimized build with API key validation):
65
- ```bash
66
- npm run production
67
- ```
68
-
69
- ## Access URLs
42
+ ## 🌐 Access URLs
70
43
 
71
- - User Interface: http://localhost:3002
72
- - Admin Interface: http://localhost:3001
73
- - API: http://localhost:3000
44
+ ### Production Mode (Port 8080 - Unified)
45
+ - **Main Application**: http://localhost:8080/
46
+ - **User Interface**: http://localhost:8080/app
47
+ - **Admin Panel**: http://localhost:8080/admin
48
+ - **API Documentation**: http://localhost:8080/api-docs
49
+ - **Health Check**: http://localhost:8080/api/health
50
+ - **API Endpoints**: http://localhost:8080/api/*
74
51
 
75
- ## Deployment Options
52
+ ### Development Mode (Separate Ports)
53
+ - **User Interface**: http://localhost:3002
54
+ - **Admin Interface**: http://localhost:3001
55
+ - **API Server**: http://localhost:8080
76
56
 
77
- ### Option 1: Quick NPX Deployment to Remote Server
57
+ ## 🖥️ Server Deployment
78
58
 
79
- If you have SSH access to a server (like an EC2 instance), this is the fastest way to deploy:
59
+ ### Option 1: Quick AWS/VPS Deployment
80
60
 
81
- 1. **Save your SSH key** to a file (e.g., `key.pem`) and set permissions:
82
- ```bash
83
- chmod 400 key.pem
84
- ```
61
+ Perfect for EC2, DigitalOcean, or any Ubuntu server:
85
62
 
86
- 2. **SSH into your server**:
63
+ 1. **SSH into your server**:
87
64
  ```bash
88
65
  ssh -i "key.pem" ubuntu@your-server-ip
89
66
  ```
90
67
 
91
- 3. **Install Node.js 18 or higher**:
68
+ 2. **Install Node.js 20+** (required):
92
69
  ```bash
93
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
70
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
94
71
  sudo apt-get install -y nodejs
95
72
  ```
96
73
 
97
- 4. **Install and run SpecGen**:
74
+ 3. **Deploy SpecGen** (one command setup with cleanup):
98
75
  ```bash
99
- # Add swap space to prevent out-of-memory errors
100
- sudo fallocate -l 2G /swapfile
101
- sudo chmod 600 /swapfile
102
- sudo mkswap /swapfile
103
- sudo swapon /swapfile
104
- echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
105
-
106
- # Create and enter project directory
107
- mkdir specgen
108
- cd specgen
109
-
110
- # Run the setup with low memory optimization
111
- npx @gv-sh/specgen-app setup-low-memory
112
-
113
- # Start in production mode with low memory optimization
114
- npx @gv-sh/specgen-app production-low-memory
76
+ mkdir specgen && cd specgen
77
+ npx @gv-sh/specgen-app setup
78
+ npx @gv-sh/specgen-app deploy
115
79
  ```
116
80
 
117
- 5. **Keep the service running with PM2** (recommended):
118
- ```bash
119
- sudo npm install -g pm2
120
- # Use the low-memory production mode with PM2
121
- pm2 start "npx @gv-sh/specgen-app production-low-memory" --name "specgen"
122
- pm2 startup
123
- pm2 save
124
- ```
81
+ 4. **Access your application**:
82
+ - **Main**: http://your-server-ip:8080/
83
+ - **User App**: http://your-server-ip:8080/app
84
+ - **Admin Panel**: http://your-server-ip:8080/admin
125
85
 
126
- 6. **Access your application**:
127
- - User Interface: http://your-server-ip:3002
128
- - Admin Interface: http://your-server-ip:3001
129
- - API: http://your-server-ip:3000
86
+ ### Option 2: Manual Setup
130
87
 
131
- ### Option 2: Global NPM Package Deployment
88
+ ```bash
89
+ # Clone and setup manually
90
+ git clone https://github.com/gv-sh/specgen-app.git
91
+ cd specgen-app
92
+ npm run setup
93
+ npm run deploy
94
+ ```
132
95
 
133
- #### Local Machine Deployment
96
+ ## 🛠️ Setup Features
134
97
 
135
- 1. **Install globally** (recommended for deployment):
136
- ```bash
137
- npm install -g @gv-sh/specgen-app
138
- ```
98
+ The setup script now includes **comprehensive cleanup**:
139
99
 
140
- 2. **Create a project directory**:
141
- ```bash
142
- mkdir specgen-project
143
- cd specgen-project
144
- ```
100
+ - **PM2 Process Cleanup**: Stops and removes existing PM2 processes
101
+ - ✅ **Port Liberation**: Frees up ports 8080, 3000, 3001, 3002
102
+ - ✅ **Nginx Cleanup**: Removes conflicting nginx configurations
103
+ - ✅ **Docker Cleanup**: Removes any existing SpecGen containers
104
+ - ✅ **Service Cleanup**: Removes systemd services
105
+ - ✅ **File Cleanup**: Removes old installations and log files
106
+ - ✅ **Low Memory Optimization**: Optimized for servers with limited RAM
145
107
 
146
- 3. **Initialize and setup**:
147
- ```bash
148
- specgen-app setup
149
- ```
150
- During setup, you'll be prompted to enter your OpenAI API key.
108
+ ## 📋 Available Commands
151
109
 
152
- 4. **Start the application**:
153
- - Development mode: `specgen-app dev`
154
- - Production mode: `specgen-app production`
110
+ ### Core Commands
111
+ ```bash
112
+ # Setup with cleanup (one-time)
113
+ npx @gv-sh/specgen-app setup
155
114
 
156
- #### Remote Server Deployment
115
+ # Development mode (separate ports)
116
+ npx @gv-sh/specgen-app dev
157
117
 
158
- 1. **SSH into your server**:
159
- ```bash
160
- ssh -i "your-key.pem" username@your-server
161
- ```
118
+ # Production mode (direct run on port 8080)
119
+ npx @gv-sh/specgen-app production
162
120
 
163
- 2. **Install Node.js** (if not already installed):
164
- ```bash
165
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
166
- sudo apt-get install -y nodejs
167
- ```
121
+ # Production deployment with PM2 (recommended)
122
+ npx @gv-sh/specgen-app deploy
123
+ ```
168
124
 
169
- 3. **Create a project directory**:
170
- ```bash
171
- mkdir specgen
172
- cd specgen
173
- ```
125
+ ### Management Commands
126
+ ```bash
127
+ # Check deployment status
128
+ npx @gv-sh/specgen-app deploy:status
174
129
 
175
- 4. **Install SpecGen globally**:
176
- ```bash
177
- npm install -g @gv-sh/specgen-app
178
- ```
130
+ # Stop all services
131
+ npx @gv-sh/specgen-app deploy:stop
179
132
 
180
- 5. **Setup the application**:
181
- ```bash
182
- specgen-app setup
183
- ```
133
+ # Restart services
134
+ npx @gv-sh/specgen-app deploy:restart
135
+ ```
184
136
 
185
- 6. **Start in production mode**:
186
- ```bash
187
- specgen-app production
188
- ```
137
+ ### Using NPM Scripts (if you cloned the repo)
138
+ ```bash
139
+ npm run setup # Setup with cleanup
140
+ npm run dev # Development mode
141
+ npm run production # Production mode
142
+ npm run deploy # Deploy with PM2
143
+ ```
189
144
 
190
- ### Option 3: Manual Deployment
145
+ ## 🔧 Configuration
191
146
 
192
- Alternatively, you can deploy manually using the repository:
147
+ ### OpenAI API Key
148
+ You'll be prompted for your OpenAI API key during setup. If you skip it, add it later to `server/.env`:
193
149
 
194
- #### Build and Run Locally
195
- ```bash
196
- git clone https://github.com/gv-sh/specgen-app.git
197
- cd specgen-app
198
- npm run setup
199
- npm run build
200
- npm run production
150
+ ```env
151
+ OPENAI_API_KEY=your_openai_api_key_here
152
+ NODE_ENV=production
153
+ PORT=8080
201
154
  ```
202
155
 
203
- #### AWS Deployment Script
156
+ ### Environment Files
157
+ The setup automatically creates optimized environment files:
158
+ - `server/.env` - Server configuration (port 8080)
159
+ - `admin/.env.development` - Admin dev settings
160
+ - `user/.env.development` - User dev settings
161
+
162
+ ## 🐳 Docker Alternative
204
163
 
205
- 1. Launch Ubuntu 22.04 instance with SSH access
206
- 2. Run deployment script:
164
+ If you prefer Docker:
207
165
 
208
166
  ```bash
209
- # On AWS instance
210
- wget https://github.com/gv-sh/specgen-app/raw/main/scripts/deploy.sh
211
- chmod +x deploy.sh
212
- sudo ./deploy.sh
167
+ # Quick Docker setup
168
+ docker run -d \
169
+ --name specgen \
170
+ -p 8080:8080 \
171
+ -e OPENAI_API_KEY=your_key_here \
172
+ gvsh/specgen-app:latest
213
173
  ```
214
174
 
215
- ## Management Commands
175
+ ## 📊 Management with PM2
176
+
177
+ When deployed with `npm run deploy`, you get PM2 process management:
216
178
 
217
- When using NPX or global installation:
218
179
  ```bash
219
180
  # Check status
220
- npx @gv-sh/specgen-app deploy:status
221
- # or when installed globally
222
- specgen-app deploy:status
181
+ npx pm2 status
223
182
 
224
- # Stop services
225
- npx @gv-sh/specgen-app deploy:stop
226
- # or
227
- specgen-app deploy:stop
183
+ # View logs
184
+ npx pm2 logs specgen
228
185
 
229
- # Restart services
230
- npx @gv-sh/specgen-app deploy:restart
231
- # or
232
- specgen-app deploy:restart
186
+ # Restart
187
+ npx pm2 restart specgen
188
+
189
+ # Stop
190
+ npx pm2 stop specgen
233
191
 
234
- # Update to latest version
235
- npm update -g @gv-sh/specgen-app
192
+ # Monitor
193
+ npx pm2 monit
236
194
  ```
237
195
 
238
- When using the repository:
239
- ```bash
240
- # Stop services
241
- npm run deploy:stop
196
+ ## 🔍 Troubleshooting
242
197
 
243
- # Restart services
244
- npm run deploy:restart
198
+ ### Common Issues
245
199
 
246
- # Update to latest
247
- npm run deploy:update
200
+ 1. **Port 8080 Already in Use**:
201
+ ```bash
202
+ # The setup script handles this automatically, but if needed:
203
+ sudo lsof -ti:8080 | xargs kill -9
204
+ ```
248
205
 
249
- # Check status
250
- npm run deploy:status
206
+ 2. **Out of Memory on Small Servers**:
207
+ ```bash
208
+ # Add swap space (setup script suggests this)
209
+ sudo fallocate -l 2G /swapfile
210
+ sudo chmod 600 /swapfile
211
+ sudo mkswap /swapfile
212
+ sudo swapon /swapfile
213
+ ```
251
214
 
252
- # Create backup
253
- npm run deploy:backup
254
- ```
215
+ 3. **Node.js Version Issues**:
216
+ ```bash
217
+ # Ensure Node.js 20+ is installed
218
+ node --version # Should be v20+
219
+ ```
220
+
221
+ 4. **SQLite3 Binding Errors**:
222
+ ```bash
223
+ # The setup script includes engine-strict=false
224
+ # If issues persist, run setup again - it includes full cleanup
225
+ npx @gv-sh/specgen-app setup
226
+ ```
255
227
 
256
- ## Available Commands
228
+ ### Health Check
229
+ Test if your deployment is working:
230
+ ```bash
231
+ curl http://localhost:8080/api/health
232
+ # Should return: {"status":"ok","port":8080}
233
+ ```
257
234
 
258
- The following commands are available when using `npx @gv-sh/specgen-app` or `specgen-app` (if installed globally):
235
+ ## 🚨 Breaking Changes from Previous Versions
259
236
 
260
- - `setup` - Set up the SpecGen application
261
- - `setup-low-memory` - Set up the SpecGen application with memory optimizations
262
- - `production` - Run the application in production mode
263
- - `production-low-memory` - Run the application in production mode with memory optimizations
264
- - `dev` - Run the application in development mode
265
- - `deploy` - Deploy the application
266
- - `deploy:stop` - Stop the deployed application
267
- - `deploy:restart` - Restart the deployed application
268
- - `deploy:update` - Update the deployed application
269
- - `deploy:status` - Check the status of the deployed application
270
- - `deploy:backup` - Create a backup of the deployed application
271
- - `troubleshoot` - Run troubleshooting checks
237
+ - **Port Change**: Default port changed from 3000 → 8080
238
+ - **URL Structure**: Admin at `/admin`, User at `/app`
239
+ - **Simplified Scripts**: Single `setup` and `production` commands
240
+ - **Automatic Cleanup**: Setup now cleans existing installations
272
241
 
273
- ## Troubleshooting
242
+ ## 📚 API Documentation
274
243
 
275
- If you encounter issues:
244
+ Once deployed, access the interactive API documentation at:
245
+ - **Swagger UI**: http://your-server:8080/api-docs
276
246
 
277
- ```bash
278
- # Using npx
279
- npx @gv-sh/specgen-app troubleshoot
247
+ ## 🤝 Contributing
280
248
 
281
- # Using global installation
282
- specgen-app troubleshoot
249
+ 1. Fork the repository
250
+ 2. Create your feature branch
251
+ 3. Commit your changes
252
+ 4. Push to the branch
253
+ 5. Create a Pull Request
283
254
 
284
- # For repository installation
285
- npm run troubleshoot
286
- ```
255
+ ## 📄 License
287
256
 
288
- This will check your setup and identify common problems.
257
+ This project is licensed under the ISC License.
289
258
 
290
- ## Environment Variables
259
+ ## 🆘 Support
291
260
 
292
- The setup script creates necessary environment files automatically. You only need to add your OpenAI API key during setup or later to `server/.env`.
261
+ - **Issues**: [GitHub Issues](https://github.com/gv-sh/specgen-app/issues)
262
+ - **Documentation**: Check `/api-docs` when running
263
+ - **Health Check**: Visit `/api/health` to verify installation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gv-sh/specgen-app",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Complete SpecGen application with server, admin, and user interfaces",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -8,20 +8,15 @@
8
8
  },
9
9
  "scripts": {
10
10
  "setup": "chmod +x scripts/setup.sh && ./scripts/setup.sh",
11
- "setup-low-memory": "chmod +x scripts/setup-low-memory.sh && ./scripts/setup-low-memory.sh",
12
11
  "dev": "chmod +x scripts/dev.sh && ./scripts/dev.sh",
13
12
  "build": "cd admin && npm run build && cd ../user && npm run build",
14
13
  "start": "cd server && npm start",
15
14
  "production": "chmod +x scripts/production.sh && ./scripts/production.sh",
16
- "production-low-memory": "chmod +x scripts/production-low-memory.sh && ./scripts/production-low-memory.sh",
17
15
  "make-executable": "chmod +x scripts/make-executable.sh && ./scripts/make-executable.sh",
18
16
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
19
17
  "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
20
18
  "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
21
- "deploy:update": "chmod +x scripts/update.sh && ./scripts/update.sh",
22
19
  "deploy:status": "chmod +x scripts/status.sh && ./scripts/status.sh",
23
- "deploy:backup": "chmod +x scripts/backup.sh && ./scripts/backup.sh",
24
- "troubleshoot": "chmod +x scripts/troubleshoot.sh && ./scripts/troubleshoot.sh",
25
20
  "postinstall": "chmod +x bin/cli.js"
26
21
  },
27
22
  "dependencies": {
@@ -0,0 +1,104 @@
1
+ #!/bin/bash
2
+
3
+ # SpecGen Deploy Script - Port 8080 Production Deployment
4
+ set -e
5
+
6
+ echo "🚀 Deploying SpecGen to production on port 8080..."
7
+
8
+ # Function to check if port is available
9
+ check_port() {
10
+ local port=$1
11
+ if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
12
+ return 1 # Port in use
13
+ else
14
+ return 0 # Port available
15
+ fi
16
+ }
17
+
18
+ # Stop existing PM2 processes
19
+ echo "Stopping existing PM2 processes..."
20
+ npx pm2 stop all 2>/dev/null || true
21
+ npx pm2 delete all 2>/dev/null || true
22
+
23
+ # Kill any processes on port 8080
24
+ echo "Freeing port 8080..."
25
+ if ! check_port 8080; then
26
+ echo "Port 8080 is in use. Attempting to free it..."
27
+ lsof -ti:8080 | xargs kill -9 2>/dev/null || true
28
+ sleep 2
29
+ fi
30
+
31
+ # Run the production setup
32
+ echo "Running production setup..."
33
+ npm run production-low-memory &
34
+ SETUP_PID=$!
35
+
36
+ # Wait for setup to complete or timeout
37
+ TIMEOUT=60
38
+ COUNT=0
39
+ while [ $COUNT -lt $TIMEOUT ]; do
40
+ if ! kill -0 $SETUP_PID 2>/dev/null; then
41
+ echo "Production setup completed"
42
+ break
43
+ fi
44
+ sleep 1
45
+ COUNT=$((COUNT + 1))
46
+ done
47
+
48
+ # Kill setup process if it's still running
49
+ if kill -0 $SETUP_PID 2>/dev/null; then
50
+ echo "Setup taking too long, continuing with PM2 deployment..."
51
+ kill $SETUP_PID 2>/dev/null || true
52
+ fi
53
+
54
+ # Wait a moment for cleanup
55
+ sleep 2
56
+
57
+ # Create PM2 ecosystem configuration
58
+ echo "Creating PM2 ecosystem configuration..."
59
+ cat > ecosystem.config.js << 'EOF'
60
+ module.exports = {
61
+ apps: [{
62
+ name: 'specgen',
63
+ script: './server/index.js',
64
+ cwd: process.cwd(),
65
+ env: {
66
+ NODE_ENV: 'production',
67
+ PORT: 8080
68
+ },
69
+ instances: 1,
70
+ exec_mode: 'fork',
71
+ max_memory_restart: '500M',
72
+ error_file: './logs/err.log',
73
+ out_file: './logs/out.log',
74
+ log_file: './logs/combined.log',
75
+ time: true,
76
+ watch: false,
77
+ ignore_watch: ['node_modules', 'logs', '*.log']
78
+ }]
79
+ }
80
+ EOF
81
+
82
+ # Create logs directory
83
+ mkdir -p logs
84
+
85
+ # Start with PM2
86
+ echo "Starting SpecGen with PM2 on port 8080..."
87
+ NODE_ENV=production PORT=8080 npx pm2 start ecosystem.config.js
88
+
89
+ # Wait for startup
90
+ sleep 5
91
+
92
+ echo ""
93
+ echo "✅ SpecGen deployment completed!"
94
+ echo ""
95
+ echo "🌐 Access your application at:"
96
+ echo " - Main page: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):8080/"
97
+ echo " - User app: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):8080/app"
98
+ echo " - Admin panel: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):8080/admin"
99
+ echo " - API docs: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):8080/api-docs"
100
+ echo " - Health check: http://$(curl -s ifconfig.me 2>/dev/null || echo 'your-server'):8080/api/health"
101
+ echo ""
102
+ echo "📊 Check status with: npx pm2 status"
103
+ echo "📝 View logs with: npx pm2 logs specgen"
104
+ echo "🔄 Restart with: npx pm2 restart specgen"