@seip/blue-bird 0.7.5 → 0.8.0

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 (42) hide show
  1. package/.env_example +34 -36
  2. package/AGENTS.md +174 -241
  3. package/LICENSE +21 -21
  4. package/README.md +312 -343
  5. package/{index.js → backend/index.js} +22 -30
  6. package/backend/routes/api.js +57 -57
  7. package/core/app.js +338 -402
  8. package/core/auth.js +262 -256
  9. package/core/cache.js +174 -174
  10. package/core/cli/docker.js +488 -370
  11. package/core/cli/init.js +332 -238
  12. package/core/cli/route.js +42 -42
  13. package/core/config.js +52 -52
  14. package/core/database.js +263 -182
  15. package/core/debug.js +248 -248
  16. package/core/logger.js +115 -115
  17. package/core/middleware.js +27 -27
  18. package/core/router.js +144 -144
  19. package/core/swagger.js +40 -40
  20. package/core/upload.js +77 -77
  21. package/core/validate.js +380 -380
  22. package/docker/Dockerfile +16 -16
  23. package/docker/docker-compose.dev.yml +6 -0
  24. package/docker/docker-compose.mysql.yml +92 -0
  25. package/docker/docker-compose.none.yml +68 -0
  26. package/docker/docker-compose.postgres.yml +93 -0
  27. package/docker/nginx.conf +98 -106
  28. package/docker-compose.yml +92 -93
  29. package/frontend/about.html +98 -0
  30. package/frontend/css/app.css +0 -0
  31. package/frontend/favicon.ico +0 -0
  32. package/frontend/index.html +141 -0
  33. package/frontend/js/bundle.js +8 -0
  34. package/package.json +64 -72
  35. package/backend/logs/2026-07-14/info.log +0 -48
  36. package/frontend/astro.config.mjs +0 -35
  37. package/frontend/public/css/app.css +0 -319
  38. package/frontend/public/favicon.ico +0 -0
  39. package/frontend/src/http/api.js +0 -29
  40. package/frontend/src/layouts/Layout.astro +0 -20
  41. package/frontend/src/pages/about.astro +0 -54
  42. package/frontend/src/pages/index.astro +0 -110
package/README.md CHANGED
@@ -1,343 +1,312 @@
1
- # Blue Bird Framework
2
-
3
- **High-Performance Express Framework — Built for Speed, Caching, and Visual Excellence**
4
-
5
- ![Blue Bird Logo](https://seip25.github.io/Blue-bird/blue-bird.png)
6
-
7
- [![npm version](https://img.shields.io/npm/v/@seip/blue-bird.svg)](https://www.npmjs.com/package/@seip/blue-bird)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
-
10
- ---
11
-
12
- ## Introduction
13
-
14
- Blue Bird is a powerful, opinionated framework built on Express for backend routing and APIs, integrated with Astro (v7.0) for high-performance frontend rendering. It features pre-configured data validation, security middlewares, GCM-encrypted JWT authentication, and CLI/Docker developer workflows out of the box.
15
-
16
- ---
17
-
18
- ## 🚀 Key Features / Características Clave
19
-
20
- - All-In-One: Pre-configured Express server with JSON, URL encoding, Cookies, and CORS.
21
- - Astro Frontend: Native integration with Astro (v7.0) for server-side rendering (SSR), static site generation (SSG), and middleware mode.
22
- - Premium Security: AES-256-GCM encrypted JWT cookie auth, secure route filters, and built-in Helmet configurator.
23
- - File Uploads: Easy Multer-based single/multiple file storage handling.
24
- - Docker & PM2 Devops: Pre-built Docker Compose/Dockerfile templates and CLI tools for zero-config dev and VPS production.
25
-
26
- ---
27
-
28
- ## 🛠️ Quick Start / Inicio Rápido
29
-
30
- ### 1. Installation / Instalación
31
-
32
- ```bash
33
- npm install @seip/blue-bird
34
- ```
35
-
36
- ### 2. Initialize Project / Inicializar
37
-
38
- ```bash
39
- npx blue-bird
40
- ```
41
-
42
- _This copies the base structure: `backend`, `frontend`, `docker`, `docker-compose.yml`, `AGENTS.md`, and `.env`._
43
-
44
- ### 3. Run Development Server / Modo Desarrollo
45
-
46
- ```bash
47
- npm run dev
48
- ```
49
-
50
- ---
51
-
52
- ## 📁 Project Structure / Estructura del Proyecto
53
-
54
- ```
55
- project/
56
- ├── backend/
57
- │ └── routes/ # Express route files
58
- │ └── api.js # REST API routes
59
- ├── frontend/
60
- ├── src/
61
- └── pages/ # Astro routes and pages (.astro)
62
- ├── index.astro
63
- │ │ └── about.astro
64
- │ ├── public/ # Static assets mapped to root of Astro build
65
- │ └── css/
66
- └── app.css # Css files
67
- │ └── astro.config.mjs # Astro configuration file
68
- ├── docker/
69
- │ └── Dockerfile # Optimized production build file
70
- ├── docker-compose.yml # Dev/Prod container configurations
71
- ├── index.js # App startup and initialization entrypoint
72
- ├── AGENTS.md # AI coding assistant guidebook
73
- └── .env # App configuration (git-ignored)
74
- ```
75
-
76
- ---
77
-
78
- ## 📖 Core Modules Documentation / Documentación de Módulos
79
-
80
- ### 1. Routing (`Router`)
81
-
82
- Do not use Express' native router. Always use Blue Bird's wrapper class:
83
-
84
- ```javascript
85
- import Router from "@seip/blue-bird/core/router.js";
86
-
87
- const routerApi = new Router("/api");
88
- routerApi.get("/users", (req, res) => {
89
- res.json({ users: [] });
90
- });
91
- export default routerApi;
92
- ```
93
-
94
- ---
95
-
96
- ### 2. Astro Node Middleware Integration
97
-
98
- Blue Bird supports Astro (v7.0) Node middleware mode. Astro handles frontend SSR, routing, static assets, and layouts, while Express handles API endpoints and server logic.
99
-
100
- To enable Astro integration:
101
-
102
- ```javascript
103
- import App from "@seip/blue-bird/core/app.js";
104
- import routerApi from "./backend/routes/api.js";
105
-
106
- const app = new App({
107
- routes: [routerApi],
108
- astro: true, // Enables Astro middleware mode
109
- });
110
-
111
- app.run();
112
- ```
113
-
114
- #### Advanced Config Options
115
-
116
- You can pass a configuration object instead of a boolean value:
117
-
118
- ```javascript
119
- const app = new App({
120
- astro: {
121
- server: true, // Mounts Astro SSR handler
122
- serverEntry: "./frontend/dist/server/entry.mjs", // Path to compiled Astro server entrypoint
123
- client: false, // Set to true to serve static files from client build
124
- clientDir: "./frontend/dist/client", // Path to Astro client static assets
125
- base: "/", // Mount base path
126
- },
127
- });
128
- ```
129
-
130
- ---
131
-
132
- ### 3. Data Validation (`Validator`)
133
-
134
- Validates request payloads using a JSON schema. Returns structured `400 Bad Request` payloads automatically on schema failures.
135
-
136
- ```javascript
137
- import Validator from "@seip/blue-bird/core/validate.js";
138
-
139
- const userSchema = {
140
- email: { required: true, email: true },
141
- password: { required: true, min: 8 },
142
- bio: { required: false },
143
- };
144
-
145
- const validateUser = new Validator(userSchema, "en");
146
-
147
- routerApi.post("/users", validateUser.middleware(), (req, res) => {
148
- res.json({ success: true });
149
- });
150
- ```
151
-
152
- ---
153
-
154
- ### 4. JWT Authentication (`Auth`)
155
-
156
- Secure user sessions using stateless AES-256-GCM encrypted JWTs stored in secure HTTP-Only cookies.
157
-
158
- #### Protecting Routes
159
-
160
- ```javascript
161
- import Auth from "@seip/blue-bird/core/auth.js";
162
-
163
- // Secure API endpoint (returns 401 on failure)
164
- router.get("/profile", Auth.protect(), (req, res) => {
165
- res.json({ user: req.user });
166
- });
167
-
168
- // Secure web page (redirects to /login on failure)
169
- router.get("/dashboard", Auth.protect({ redirect: "/login" }), (req, res) => {
170
- Template.render(res, "dashboard");
171
- });
172
- ```
173
-
174
- #### Authentication Sessions
175
-
176
- ```javascript
177
- router.post("/login", async (req, res) => {
178
- const user = { id: 1, name: "John Doe" };
179
- await Auth.login(res, user);
180
- res.json({ message: "Logged in successfully" });
181
- });
182
-
183
- router.post("/logout", async (req, res) => {
184
- await Auth.logout(res);
185
- res.json({ message: "Logged out" });
186
- });
187
- ```
188
-
189
- ---
190
-
191
- ### 5. Performance Cache Middleware (`Cache`)
192
-
193
- Applies caching at the route handler level. Automatically caches JSON payloads (`res.json`) and rendered outputs (`res.send`).
194
-
195
- ```javascript
196
- import Cache from "@seip/blue-bird/core/cache.js";
197
-
198
- // Cache endpoint for 60 seconds
199
- router.get("/stats", Cache.middleware(60), (req, res) => {
200
- res.json({ usersOnline: 42 });
201
- });
202
- ```
203
-
204
- Integrates with Redis if `REDIS_HOST` is defined in the environment. Falls back to an in-memory cache automatically if Redis is not configured or not running.
205
-
206
- ---
207
-
208
- ### 6. Security Headers (`Helmet`)
209
-
210
- Apply security headers per-router. Preserves the framework's custom powered-by header by default:
211
-
212
- ```javascript
213
- import App from "@seip/blue-bird/core/app.js";
214
-
215
- const webRouter = new Router("/web");
216
- webRouter.use(App.helmet());
217
- ```
218
-
219
- ---
220
-
221
- ### 7. Database wrapper (`Database`)
222
-
223
- MySQL database client connection pool configuration featuring automated retry loops, query formatting utilities, and Redis query caching.
224
-
225
- ```javascript
226
- import connection from "@seip/blue-bird/core/database.js";
227
-
228
- // Fetch single row from a SELECT query
229
- const user = await connection.query("SELECT * FROM users WHERE email = ?", ["test@example.com"], "return_row");
230
-
231
- // Fetch rows with 60 seconds Redis caching enabled
232
- const stats = await connection.query("SELECT COUNT(*) as count FROM access_logs", [], { cache: 60 });
233
-
234
- // INSERT queries return the last insert ID directly
235
- const newId = await connection.query("INSERT INTO users (name) VALUES (?)", ["John"]);
236
- ```
237
-
238
- ---
239
-
240
- ### 8. Nginx Proxy Caching
241
-
242
- Nginx reverse proxy is preconfigured with a page cache zone (`astro_cache`) that stores public page outputs (Astro SSR/SSG) for 10 seconds.
243
- - **Cache Bypass:** Requests with an `auth` cookie or `Authorization` header automatically bypass the cache to ensure dynamic page outputs.
244
- - **Disabling:** Caching can be turned off in `docker/nginx.conf` by commenting out the `proxy_cache` directives.
245
- - **Caching API routes:** If you want Nginx to cache GET endpoints from `/api/` directly (which is much faster than Node query/redis caching), add a matching location block inside `docker/nginx.conf` before the generic `/api/` block:
246
- ```nginx
247
- location /api/cached-stats {
248
- limit_req zone=bluebird_limit burst=20 nodelay;
249
- set $upstream_target http://app:3000;
250
- proxy_pass $upstream_target;
251
- proxy_http_version 1.1;
252
- proxy_set_header Connection "";
253
- proxy_set_header Host $host;
254
-
255
- proxy_cache astro_cache;
256
- proxy_cache_valid 200 10s;
257
- add_header X-Cache-Status $upstream_cache_status;
258
- }
259
- ```
260
-
261
- ---
262
-
263
- ## 🐳 Docker CLI Workflow
264
-
265
- Blue Bird comes with a built-in Docker CLI wrapper that handles both local development database bootstrapping and full-stack VPS production deployments.
266
-
267
- ### Commands Syntax:
268
-
269
- ```bash
270
- npx blue-bird docker <command> [options]
271
- ```
272
-
273
- ### Supported Actions:
274
-
275
- - **`npx blue-bird docker start`**: Boots the production stack (Node.js App + Nginx + MySQL + Redis).
276
- - **`npx blue-bird docker start mysql`**: Boots the MySQL container only (great for local HTTP development).
277
- - **`npx blue-bird docker start redis`**: Boots the Redis container only.
278
- - **`npx blue-bird docker start dbs`**: Boots both database containers (MySQL + Redis).
279
- - **`npx blue-bird docker stop`**: Stops all active containers.
280
- - **`npx blue-bird docker build [--no-cache]`**: Builds or updates the Node.js production image.
281
- - **`npx blue-bird docker ps`**: Lists running project containers and ports.
282
- - **`npx blue-bird docker logs [app|mysql]`**: Tails logs for the specified container.
283
- - **`npx blue-bird docker pm2 [args]`**: Runs PM2 commands inside the Node.js application container (e.g. `status`, `monit`, `reload all`).
284
- - **`npx blue-bird docker db`**: Connects into the container's interactive MySQL shell using credentials from `.env`.
285
- - **`npx blue-bird docker redis`**: Connects into the container's interactive Redis CLI terminal.
286
- - **`npx blue-bird docker prune`**: Safely clears orphaned volumes, dangling build caches, and images.
287
-
288
- ---
289
-
290
- ## 🚀 Production Deployment Options
291
-
292
- You can deploy Blue Bird applications to production using two main workflows:
293
-
294
- ### A. Docker Container Stack (Highly Recommended)
295
-
296
- Using the built-in Docker stack is the recommended deployment method because it sets up a complete, hardened production environment automatically:
297
- - **Nginx Reverse Proxy:** Captures traffic on port 3000 (or custom PORT), serves Astro client-side assets directly from the filesystem to offload the Node.js server, and proxies the rest to Express.
298
- - **PM2 Clustering:** Launches Node.js in cluster mode inside the container, utilizing all available CPU cores based on `PM2_INSTANCES` configuration (defaulting to 1).
299
- - **Security Mitigation:** Nginx blocks common malicious scanners (e.g. `/.env`, `/.git`, `/wp-admin`) instantly using a 444 status code and implements a `10r/s` request rate-limit.
300
- - **Services Stack:** MySQL and Redis are configured in the same bridge network automatically.
301
-
302
- To deploy via Docker:
303
- 1. Configure `.env` with production keys, `DEBUG=false` and your custom `TITLE`.
304
- 2. Build the production image:
305
- ```bash
306
- npx blue-bird docker build
307
- ```
308
- 3. Run the container cluster:
309
- ```bash
310
- npx blue-bird docker start prod
311
- ```
312
-
313
- ### B. Standard Standalone PM2 / Node.js Runtime
314
-
315
- If you choose to run outside of Docker, you must set up the reverse proxy and databases manually. To deploy in a standard Linux environment using PM2:
316
-
317
- 1. Install PM2 globally:
318
- ```bash
319
- npm install pm2 -g
320
- ```
321
- 2. Start the application under PM2:
322
- ```bash
323
- pm2 start index.js --name "bluebird-app" --node-args="--env-file=.env" -i max
324
- ```
325
- 3. Monitor status:
326
- ```bash
327
- pm2 status
328
- pm2 logs
329
- ```
330
-
331
- ---
332
-
333
- ## 📄 License / Licencia
334
-
335
- Distributed under the **MIT License**. See `LICENSE` for more information.
336
-
337
- Distribuido bajo la **Licencia MIT**. Mira `LICENSE` para más información.
338
-
339
- ---
340
-
341
- <div align="center">
342
- <p>Made with ❤️ by <strong>Seip25</strong></p>
343
- </div>
1
+ # Blue Bird Framework
2
+
3
+ **High-Performance Express Framework — Built for Speed, Caching, and Visual Excellence**
4
+
5
+ ![Blue Bird Logo](https://seip25.github.io/Blue-bird/blue-bird.png)
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@seip/blue-bird.svg)](https://www.npmjs.com/package/@seip/blue-bird)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ ---
11
+
12
+ ## Introduction
13
+
14
+ Blue Bird is a powerful, performance-first API framework built on Express. It features pre-configured data validation, security middlewares, GCM-encrypted JWT authentication, and CLI/Docker developer workflows out of the box, with static frontend assets handled directly by Nginx.
15
+
16
+ ---
17
+
18
+ ## 🚀 Key Features / Características Clave
19
+
20
+ - All-In-One: Pre-configured Express API server with JSON, URL encoding, Cookies, and CORS.
21
+ - Nginx Static Frontend: Lightning-fast static asset and extensionless HTML serving via Nginx, decoupled from Node.js.
22
+ - Premium Security: AES-256-GCM encrypted JWT cookie auth, secure route filters, and built-in Helmet configurator.
23
+ - File Uploads: Easy Multer-based single/multiple file storage handling.
24
+ - Docker & PM2 Devops: Pre-built Docker Compose/Dockerfile templates and CLI tools for zero-config dev and VPS production.
25
+
26
+ ---
27
+
28
+ ## 🛠️ Quick Start / Inicio Rápido
29
+
30
+ ### 1. Installation / Instalación
31
+
32
+ ```bash
33
+ npm install @seip/blue-bird
34
+ ```
35
+
36
+ ### 2. Initialize Project / Inicializar
37
+
38
+ ```bash
39
+ npx blue-bird
40
+ ```
41
+
42
+ When run, the interactive CLI prompts for your preferred infrastructure configuration:
43
+ - Database Selection: Choose between `none`, `mysql`, or `postgres`.
44
+ - Credentials: Set your database name, user, password, and port (`3306` or `5432`).
45
+
46
+ The CLI intelligently copies the appropriate Docker configuration (`docker/docker-compose.mysql.yml`, `docker/docker-compose.postgres.yml`, or `docker/docker-compose.none.yml`) to your project root as `docker-compose.yml`. It also writes the environment settings (`DB_TYPE`, `DATABASE_URL`) to `.env` and installs the required database packages (`mysql2` or `pg`) automatically.
47
+
48
+ ### 3. Run Development Server / Modo Desarrollo
49
+
50
+ ```bash
51
+ npm run dev
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 📁 Project Structure / Estructura del Proyecto
57
+
58
+ ```
59
+ project/
60
+ ├── backend/
61
+ │ └── routes/ # Express route files
62
+ └── api.js # REST API routes
63
+ ├── frontend/
64
+ │ ├── css/ # CSS files
65
+ ├── js/ # JavaScript files
66
+ │ └── index.html # Static HTML files
67
+ ├── docker/
68
+ │ └── Dockerfile # Optimized production build file
69
+ ├── docker-compose.yml # Dev/Prod container configurations
70
+ ├── index.js # App startup and initialization entrypoint
71
+ ├── AGENTS.md # AI coding assistant guidebook
72
+ └── .env # App configuration (git-ignored)
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 📖 Core Modules Documentation / Documentación de Módulos
78
+
79
+ ### 1. Routing (`Router`)
80
+
81
+ Do not use Express' native router. Always use Blue Bird's wrapper class:
82
+
83
+ ```javascript
84
+ import Router from "@seip/blue-bird/core/router.js";
85
+
86
+ const routerApi = new Router("/api");
87
+ routerApi.get("/users", (req, res) => {
88
+ res.json({ users: [] });
89
+ });
90
+ export default routerApi;
91
+ ```
92
+
93
+ ---
94
+
95
+
96
+
97
+ ### 3. Data Validation (`Validator`)
98
+
99
+ Validates request payloads using a JSON schema. Returns structured `400 Bad Request` payloads automatically on schema failures.
100
+
101
+ ```javascript
102
+ import Validator from "@seip/blue-bird/core/validate.js";
103
+
104
+ const userSchema = {
105
+ email: { required: true, email: true },
106
+ password: { required: true, min: 8 },
107
+ bio: { required: false },
108
+ };
109
+
110
+ const validateUser = new Validator(userSchema, "en");
111
+
112
+ routerApi.post("/users", validateUser.middleware(), (req, res) => {
113
+ res.json({ success: true });
114
+ });
115
+ ```
116
+
117
+ ---
118
+
119
+ ### 4. JWT Authentication (`Auth`)
120
+
121
+ Secure user sessions using stateless AES-256-GCM encrypted JWTs stored in secure HTTP-Only cookies.
122
+
123
+ #### Protecting Routes
124
+
125
+ ```javascript
126
+ import Auth from "@seip/blue-bird/core/auth.js";
127
+
128
+ // Secure API endpoint (returns 401 on failure)
129
+ router.get("/profile", Auth.protect(), (req, res) => {
130
+ res.json({ user: req.user });
131
+ });
132
+
133
+ // Secure web page (redirects to /login on failure)
134
+ router.get("/dashboard", Auth.protect({ redirect: "/login" }), (req, res) => {
135
+ Template.render(res, "dashboard");
136
+ });
137
+ ```
138
+
139
+ #### Authentication Sessions
140
+
141
+ ```javascript
142
+ router.post("/login", async (req, res) => {
143
+ const user = { id: 1, name: "John Doe" };
144
+ await Auth.login(res, user);
145
+ res.json({ message: "Logged in successfully" });
146
+ });
147
+
148
+ router.post("/logout", async (req, res) => {
149
+ await Auth.logout(res);
150
+ res.json({ message: "Logged out" });
151
+ });
152
+ ```
153
+
154
+ ---
155
+
156
+ ### 5. Performance Cache Middleware (`Cache`)
157
+
158
+ Applies caching at the route handler level. Automatically caches JSON payloads (`res.json`) and rendered outputs (`res.send`).
159
+
160
+ ```javascript
161
+ import Cache from "@seip/blue-bird/core/cache.js";
162
+
163
+ // Cache endpoint for 60 seconds
164
+ router.get("/stats", Cache.middleware(60), (req, res) => {
165
+ res.json({ usersOnline: 42 });
166
+ });
167
+ ```
168
+
169
+ Integrates with Redis if `REDIS_HOST` is defined in the environment. Falls back to an in-memory cache automatically if Redis is not configured or not running.
170
+
171
+ ---
172
+
173
+ ### 6. Security Headers (`Helmet`)
174
+
175
+ Apply security headers per-router. Preserves the framework's custom powered-by header by default:
176
+
177
+ ```javascript
178
+ import App from "@seip/blue-bird/core/app.js";
179
+
180
+ const webRouter = new Router("/web");
181
+ webRouter.use(App.helmet());
182
+ ```
183
+
184
+ ---
185
+
186
+ ### 7. Database wrapper (`Database`)
187
+
188
+ Blue Bird provides a unified, multi-database client wrapper (`core/database.js`) supporting **MySQL** and **PostgreSQL** with automated connection retry loops, query formatting utilities, and Redis query caching.
189
+
190
+ #### Driver Support
191
+ - **Native MySQL (`mysql2/promise`)**: High-performance connection pool for MySQL 8.0+.
192
+ - **Native PostgreSQL (`pg`)**: Connection pool for PostgreSQL 18+. When running standard queries with `connection.query(sql, params)`, the wrapper automatically converts `?` parameter placeholders into PostgreSQL `$1, $2, ...` syntax, allowing unified SQL query writing across both database engines.
193
+ - **No Database (`none`)**: If no database is configured, the wrapper is disabled gracefully without crashing the server.
194
+
195
+ #### Standalone & Remote Database Configuration
196
+ You can connect to any local or remote database instance (outside Docker, such as Supabase, Neon, AWS RDS, or local services) simply by defining the `DATABASE_URL` in your `.env` file:
197
+
198
+ ```env
199
+ DB_TYPE="postgres"
200
+ DATABASE_URL="postgresql://postgres:password@localhost:5432/blue_bird?schema=public"
201
+ # OR for MySQL:
202
+ # DATABASE_URL="mysql://root:password@localhost:3306/blue_bird"
203
+ ```
204
+
205
+ #### Usage Examples
206
+
207
+ ```javascript
208
+ import { Database, DB_TYPE } from "@seip/blue-bird/core/database.js";
209
+
210
+ // Instantiate the database connection pool with a connection limit (e.g., 20)
211
+ const connection = new Database(20);
212
+
213
+ // 1. Basic SELECT query returning single row (Works for both MySQL and PostgreSQL using ? placeholders)
214
+ const user = await connection.query("SELECT * FROM users WHERE email = ?", ["test@example.com"], "return_row");
215
+
216
+ // 2. Fetch rows with 60 seconds Redis caching enabled
217
+ const stats = await connection.query("SELECT COUNT(*) as count FROM access_logs", [], { cache: 60 });
218
+
219
+ // 3. INSERT query (returns insertId for MySQL, or inserted row ID / rowCount for PostgreSQL)
220
+ const newId = await connection.query("INSERT INTO users (name) VALUES (?)", ["John"]);
221
+ ```
222
+
223
+ ---
224
+
225
+ ### 8. Nginx Static Asset Caching
226
+
227
+ Nginx is configured to explicitly cache static assets (`.js`, `.css`, `.jpg`, `.png`, etc.) in the user's browser with the `Cache-Control` header (valid for 1 month). HTML and API endpoints (`/api/*`) are not cached by Nginx to ensure they serve dynamic and up-to-date content, relying instead on the Node.js application and Redis for data-layer caching.
228
+
229
+ ---
230
+
231
+ ## Docker CLI Workflow
232
+
233
+ Blue Bird comes with a built-in Docker CLI wrapper that handles both local development database bootstrapping and full-stack VPS production deployments across MySQL, PostgreSQL, or no-database architectures.
234
+
235
+ ### Commands Syntax:
236
+
237
+ ```bash
238
+ npx blue-bird docker <command> [options]
239
+ ```
240
+
241
+ ### Supported Actions:
242
+
243
+ - **`npx blue-bird docker dev`**: Boots the development stack (Node.js App with `npm run dev` + Nginx + Database + Redis).
244
+ - **`npx blue-bird docker start`**: Boots the production stack (Node.js App + Nginx + Database + Redis).
245
+ - **`npx blue-bird docker start db`** (or `postgres` / `mysql`): Boots the configured database container only (great for local development outside Docker).
246
+ - **`npx blue-bird docker start redis`**: Boots the Redis container only.
247
+ - **`npx blue-bird docker start dbs`**: Boots both database containers (configured DB + Redis).
248
+ - **`npx blue-bird docker stop`**: Stops all active project containers.
249
+ - **`npx blue-bird docker build [--no-cache]`**: Builds or updates the Node.js production image.
250
+ - **`npx blue-bird docker ps`**: Lists running project containers and ports.
251
+ - **`npx blue-bird docker logs [app|db|postgres|mysql]`**: Tails logs for the specified container.
252
+ - **`npx blue-bird docker pm2 [args]`**: Runs PM2 commands inside the Node.js application container (e.g. `status`, `monit`, `reload all`).
253
+ - **`npx blue-bird docker db`** (or `psql` / `mysql`): Connects into the container's interactive database shell (`psql` for PostgreSQL, `mysql` for MySQL) using credentials from `.env`.
254
+ - **`npx blue-bird docker redis`**: Connects into the container's interactive Redis CLI terminal.
255
+ - **`npx blue-bird docker prune`**: Safely clears orphaned volumes, dangling build caches, and images.
256
+
257
+ ---
258
+
259
+ ## 🚀 Production Deployment Options
260
+
261
+ You can deploy Blue Bird applications to production using two main workflows:
262
+
263
+ ### A. Docker Container Stack (Highly Recommended)
264
+
265
+ Using the built-in Docker stack is the recommended deployment method because it sets up a complete, hardened production environment automatically:
266
+ - **Nginx Reverse Proxy:** Captures traffic on port 3000 (or custom PORT), serves static assets and extensionless HTML directly from the filesystem to offload the Node.js server, and proxies API traffic to Express.
267
+ - **PM2 Clustering:** Launches Node.js in cluster mode inside the container, utilizing all available CPU cores based on `PM2_INSTANCES` configuration (defaulting to 1).
268
+ - **Security Mitigation:** Nginx blocks common malicious scanners (e.g. `/.env`, `/.git`, `/wp-admin`) instantly using a 444 status code and implements a `10r/s` request rate-limit.
269
+ - **Services Stack:** MySQL and Redis are configured in the same bridge network automatically.
270
+
271
+ To deploy via Docker:
272
+ 1. Configure `.env` with production keys, `DEBUG=false` and your custom `TITLE`.
273
+ 2. Build the production image:
274
+ ```bash
275
+ npx blue-bird docker build
276
+ ```
277
+ 3. Run the container cluster:
278
+ ```bash
279
+ npx blue-bird docker start prod
280
+ ```
281
+
282
+ ### B. Standard Standalone PM2 / Node.js Runtime
283
+
284
+ If you choose to run outside of Docker, you must set up the reverse proxy and databases manually. To deploy in a standard Linux environment using PM2:
285
+
286
+ 1. Install PM2 globally:
287
+ ```bash
288
+ npm install pm2 -g
289
+ ```
290
+ 2. Start the application under PM2:
291
+ ```bash
292
+ pm2 start index.js --name "bluebird-app" --node-args="--env-file=.env" -i max
293
+ ```
294
+ 3. Monitor status:
295
+ ```bash
296
+ pm2 status
297
+ pm2 logs
298
+ ```
299
+
300
+ ---
301
+
302
+ ## 📄 License / Licencia
303
+
304
+ Distributed under the **MIT License**. See `LICENSE` for more information.
305
+
306
+ Distribuido bajo la **Licencia MIT**. Mira `LICENSE` para más información.
307
+
308
+ ---
309
+
310
+ <div align="center">
311
+ <p>Made with ❤️ by <strong>Seip25</strong></p>
312
+ </div>