@gv-sh/specgen-app 0.4.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.4.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,247 +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
-
32
- ### Using NPM Scripts
33
-
34
- 1. **Setup**:
35
- ```bash
36
- npm run setup
37
- ```
38
- During setup, you'll be prompted to enter your OpenAI API key.
39
-
40
- 2. **Add OpenAI API Key** to `server/.env` if you skipped during setup
41
-
42
- 3. **Start Development**:
43
- ```bash
44
- npm run dev
45
- ```
46
37
 
47
- 4. **Start Production** (optimized build with API key validation):
48
- ```bash
49
- npm run production
50
- ```
38
+ # Or deploy with PM2 (recommended for servers)
39
+ npx @gv-sh/specgen-app deploy
40
+ ```
51
41
 
52
- ## Access URLs
42
+ ## 🌐 Access URLs
53
43
 
54
- - User Interface: http://localhost:3002
55
- - Admin Interface: http://localhost:3001
56
- - 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/*
57
51
 
58
- ## 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
59
56
 
60
- ### Option 1: Quick NPX Deployment to Remote Server
57
+ ## 🖥️ Server Deployment
61
58
 
62
- 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
63
60
 
64
- 1. **Save your SSH key** to a file (e.g., `key.pem`) and set permissions:
65
- ```bash
66
- chmod 400 key.pem
67
- ```
61
+ Perfect for EC2, DigitalOcean, or any Ubuntu server:
68
62
 
69
- 2. **SSH into your server**:
63
+ 1. **SSH into your server**:
70
64
  ```bash
71
65
  ssh -i "key.pem" ubuntu@your-server-ip
72
66
  ```
73
67
 
74
- 3. **Install Node.js 18 or higher**:
68
+ 2. **Install Node.js 20+** (required):
75
69
  ```bash
76
- 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 -
77
71
  sudo apt-get install -y nodejs
78
72
  ```
79
73
 
80
- 4. **Install and run SpecGen**:
74
+ 3. **Deploy SpecGen** (one command setup with cleanup):
81
75
  ```bash
82
- # Create and enter project directory
83
- mkdir specgen
84
- cd specgen
85
-
86
- # Run the setup
76
+ mkdir specgen && cd specgen
87
77
  npx @gv-sh/specgen-app setup
88
-
89
- # Start in production mode
90
- npx @gv-sh/specgen-app production
78
+ npx @gv-sh/specgen-app deploy
91
79
  ```
92
80
 
93
- 5. **Keep the service running with PM2** (recommended):
94
- ```bash
95
- sudo npm install -g pm2
96
- pm2 start "npx @gv-sh/specgen-app production" --name "specgen"
97
- pm2 startup
98
- pm2 save
99
- ```
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
100
85
 
101
- 6. **Access your application**:
102
- - User Interface: http://your-server-ip:3002
103
- - Admin Interface: http://your-server-ip:3001
104
- - API: http://your-server-ip:3000
86
+ ### Option 2: Manual Setup
105
87
 
106
- ### 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
+ ```
107
95
 
108
- #### Local Machine Deployment
96
+ ## 🛠️ Setup Features
109
97
 
110
- 1. **Install globally** (recommended for deployment):
111
- ```bash
112
- npm install -g @gv-sh/specgen-app
113
- ```
98
+ The setup script now includes **comprehensive cleanup**:
114
99
 
115
- 2. **Create a project directory**:
116
- ```bash
117
- mkdir specgen-project
118
- cd specgen-project
119
- ```
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
120
107
 
121
- 3. **Initialize and setup**:
122
- ```bash
123
- specgen-app setup
124
- ```
125
- During setup, you'll be prompted to enter your OpenAI API key.
108
+ ## 📋 Available Commands
126
109
 
127
- 4. **Start the application**:
128
- - Development mode: `specgen-app dev`
129
- - Production mode: `specgen-app production`
110
+ ### Core Commands
111
+ ```bash
112
+ # Setup with cleanup (one-time)
113
+ npx @gv-sh/specgen-app setup
130
114
 
131
- #### Remote Server Deployment
115
+ # Development mode (separate ports)
116
+ npx @gv-sh/specgen-app dev
132
117
 
133
- 1. **SSH into your server**:
134
- ```bash
135
- ssh -i "your-key.pem" username@your-server
136
- ```
118
+ # Production mode (direct run on port 8080)
119
+ npx @gv-sh/specgen-app production
137
120
 
138
- 2. **Install Node.js** (if not already installed):
139
- ```bash
140
- curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
141
- sudo apt-get install -y nodejs
142
- ```
121
+ # Production deployment with PM2 (recommended)
122
+ npx @gv-sh/specgen-app deploy
123
+ ```
143
124
 
144
- 3. **Create a project directory**:
145
- ```bash
146
- mkdir specgen
147
- cd specgen
148
- ```
125
+ ### Management Commands
126
+ ```bash
127
+ # Check deployment status
128
+ npx @gv-sh/specgen-app deploy:status
149
129
 
150
- 4. **Install SpecGen globally**:
151
- ```bash
152
- npm install -g @gv-sh/specgen-app
153
- ```
130
+ # Stop all services
131
+ npx @gv-sh/specgen-app deploy:stop
154
132
 
155
- 5. **Setup the application**:
156
- ```bash
157
- specgen-app setup
158
- ```
133
+ # Restart services
134
+ npx @gv-sh/specgen-app deploy:restart
135
+ ```
159
136
 
160
- 6. **Start in production mode**:
161
- ```bash
162
- specgen-app production
163
- ```
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
+ ```
164
144
 
165
- ### Option 3: Manual Deployment
145
+ ## 🔧 Configuration
166
146
 
167
- 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`:
168
149
 
169
- #### Build and Run Locally
170
- ```bash
171
- git clone https://github.com/gv-sh/specgen-app.git
172
- cd specgen-app
173
- npm run setup
174
- npm run build
175
- npm run production
150
+ ```env
151
+ OPENAI_API_KEY=your_openai_api_key_here
152
+ NODE_ENV=production
153
+ PORT=8080
176
154
  ```
177
155
 
178
- #### 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
179
163
 
180
- 1. Launch Ubuntu 22.04 instance with SSH access
181
- 2. Run deployment script:
164
+ If you prefer Docker:
182
165
 
183
166
  ```bash
184
- # On AWS instance
185
- wget https://github.com/gv-sh/specgen-app/raw/main/scripts/deploy.sh
186
- chmod +x deploy.sh
187
- 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
188
173
  ```
189
174
 
190
- ## Management Commands
175
+ ## 📊 Management with PM2
176
+
177
+ When deployed with `npm run deploy`, you get PM2 process management:
191
178
 
192
- When using NPX or global installation:
193
179
  ```bash
194
180
  # Check status
195
- npx @gv-sh/specgen-app deploy:status
196
- # or when installed globally
197
- specgen-app deploy:status
181
+ npx pm2 status
198
182
 
199
- # Stop services
200
- npx @gv-sh/specgen-app deploy:stop
201
- # or
202
- specgen-app deploy:stop
183
+ # View logs
184
+ npx pm2 logs specgen
203
185
 
204
- # Restart services
205
- npx @gv-sh/specgen-app deploy:restart
206
- # or
207
- specgen-app deploy:restart
186
+ # Restart
187
+ npx pm2 restart specgen
188
+
189
+ # Stop
190
+ npx pm2 stop specgen
208
191
 
209
- # Update to latest version
210
- npm update -g @gv-sh/specgen-app
192
+ # Monitor
193
+ npx pm2 monit
211
194
  ```
212
195
 
213
- When using the repository:
214
- ```bash
215
- # Stop services
216
- npm run deploy:stop
196
+ ## 🔍 Troubleshooting
217
197
 
218
- # Restart services
219
- npm run deploy:restart
198
+ ### Common Issues
220
199
 
221
- # Update to latest
222
- 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
+ ```
223
205
 
224
- # Check status
225
- 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
+ ```
226
214
 
227
- # Create backup
228
- npm run deploy:backup
229
- ```
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
+ ```
230
227
 
231
- ## 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
+ ```
232
234
 
233
- The following commands are available when using `npx @gv-sh/specgen-app` or `specgen-app` (if installed globally):
235
+ ## 🚨 Breaking Changes from Previous Versions
234
236
 
235
- - `setup` - Set up the SpecGen application
236
- - `production` - Run the application in production mode
237
- - `dev` - Run the application in development mode
238
- - `deploy` - Deploy the application
239
- - `deploy:stop` - Stop the deployed application
240
- - `deploy:restart` - Restart the deployed application
241
- - `deploy:update` - Update the deployed application
242
- - `deploy:status` - Check the status of the deployed application
243
- - `deploy:backup` - Create a backup of the deployed application
244
- - `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
245
241
 
246
- ## Troubleshooting
242
+ ## 📚 API Documentation
247
243
 
248
- If you encounter issues:
244
+ Once deployed, access the interactive API documentation at:
245
+ - **Swagger UI**: http://your-server:8080/api-docs
249
246
 
250
- ```bash
251
- # Using npx
252
- npx @gv-sh/specgen-app troubleshoot
247
+ ## 🤝 Contributing
253
248
 
254
- # Using global installation
255
- 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
256
254
 
257
- # For repository installation
258
- npm run troubleshoot
259
- ```
255
+ ## 📄 License
260
256
 
261
- This will check your setup and identify common problems.
257
+ This project is licensed under the ISC License.
262
258
 
263
- ## Environment Variables
259
+ ## 🆘 Support
264
260
 
265
- 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/bin/cli.js CHANGED
@@ -38,9 +38,15 @@ switch (command) {
38
38
  case 'setup':
39
39
  runScript('setup');
40
40
  break;
41
+ case 'setup-low-memory':
42
+ runScript('setup-low-memory');
43
+ break;
41
44
  case 'production':
42
45
  runScript('production');
43
46
  break;
47
+ case 'production-low-memory':
48
+ runScript('production-low-memory');
49
+ break;
44
50
  case 'dev':
45
51
  runScript('dev');
46
52
  break;
@@ -69,7 +75,9 @@ switch (command) {
69
75
  console.log('Usage: specgen-app <command>');
70
76
  console.log('\nAvailable commands:');
71
77
  console.log(' setup - Set up the SpecGen application');
78
+ console.log(' setup-low-memory - Set up the SpecGen application with memory optimizations');
72
79
  console.log(' production - Run the application in production mode');
80
+ console.log(' production-low-memory - Run the application in production mode with memory optimizations');
73
81
  console.log(' dev - Run the application in development mode');
74
82
  console.log(' deploy - Deploy the application');
75
83
  console.log(' deploy:stop - Stop the deployed application');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gv-sh/specgen-app",
3
- "version": "0.4.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": {
@@ -16,10 +16,7 @@
16
16
  "deploy": "chmod +x scripts/deploy.sh && ./scripts/deploy.sh",
17
17
  "deploy:stop": "chmod +x scripts/stop.sh && ./scripts/stop.sh",
18
18
  "deploy:restart": "chmod +x scripts/restart.sh && ./scripts/restart.sh",
19
- "deploy:update": "chmod +x scripts/update.sh && ./scripts/update.sh",
20
19
  "deploy:status": "chmod +x scripts/status.sh && ./scripts/status.sh",
21
- "deploy:backup": "chmod +x scripts/backup.sh && ./scripts/backup.sh",
22
- "troubleshoot": "chmod +x scripts/troubleshoot.sh && ./scripts/troubleshoot.sh",
23
20
  "postinstall": "chmod +x bin/cli.js"
24
21
  },
25
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"