@seip/blue-bird 0.4.4 → 0.4.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.
- package/.env_example +26 -25
- package/AGENTS.md +199 -199
- package/LICENSE +21 -0
- package/README.md +79 -79
- package/backend/index.js +13 -13
- package/backend/routes/api.js +31 -31
- package/backend/routes/frontend.js +41 -41
- package/backend/routes/seo.js +39 -39
- package/core/app.js +328 -325
- package/core/auth.js +114 -83
- package/core/cache.js +44 -44
- package/core/cli/component.js +42 -42
- package/core/cli/init.js +119 -118
- package/core/cli/react.js +435 -435
- package/core/cli/route.js +42 -42
- package/core/cli/scaffolding-auth.js +1037 -0
- package/core/config.js +48 -47
- package/core/debug.js +248 -248
- package/core/logger.js +100 -100
- package/core/middleware.js +27 -27
- package/core/router.js +333 -333
- package/core/seo.js +95 -100
- package/core/swagger.js +40 -25
- package/core/template.js +472 -462
- package/core/upload.js +76 -76
- package/core/validate.js +380 -380
- package/frontend/index.html +26 -26
- package/frontend/landing.html +69 -69
- package/frontend/resources/css/tailwind.css +17 -17
- package/frontend/resources/js/App.jsx +70 -70
- package/frontend/resources/js/Main.jsx +18 -18
- package/frontend/resources/js/blue-bird/components/Button.jsx +67 -67
- package/frontend/resources/js/blue-bird/components/Card.jsx +18 -18
- package/frontend/resources/js/blue-bird/components/DataTable.jsx +126 -126
- package/frontend/resources/js/blue-bird/components/Input.jsx +21 -21
- package/frontend/resources/js/blue-bird/components/Label.jsx +12 -12
- package/frontend/resources/js/blue-bird/components/LanguageButton.jsx +23 -23
- package/frontend/resources/js/blue-bird/components/Link.jsx +15 -15
- package/frontend/resources/js/blue-bird/components/Modal.jsx +27 -27
- package/frontend/resources/js/blue-bird/components/Skeleton.jsx +44 -44
- package/frontend/resources/js/blue-bird/components/Translate.jsx +12 -12
- package/frontend/resources/js/blue-bird/components/Typography.jsx +69 -69
- package/frontend/resources/js/blue-bird/contexts/LanguageContext.jsx +41 -41
- package/frontend/resources/js/blue-bird/contexts/SPAContext.jsx +239 -237
- package/frontend/resources/js/blue-bird/contexts/SnackbarContext.jsx +38 -38
- package/frontend/resources/js/blue-bird/contexts/ThemeContext.jsx +49 -49
- package/frontend/resources/js/blue-bird/locales/en.json +47 -47
- package/frontend/resources/js/blue-bird/locales/es.json +47 -47
- package/frontend/resources/js/components/Header.jsx +55 -55
- package/frontend/resources/js/pages/About.jsx +31 -31
- package/frontend/resources/js/pages/Home.jsx +82 -82
- package/package.json +57 -57
- package/vite.config.js +22 -22
package/.env_example
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
DEBUG=true
|
|
2
|
-
DESCRIPTION_META="Example description meta"
|
|
3
|
-
KEYWORDS_META="Example keywords meta"
|
|
4
|
-
TITLE_META="Blue Bird"
|
|
5
|
-
AUTHOR_META="Blue Bird"
|
|
6
|
-
DESCRIPTION="Description project"
|
|
7
|
-
TITLE="Blue Bird"
|
|
8
|
-
VERSION="1.0.0"
|
|
9
|
-
LANGMETA="en"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
#
|
|
17
|
-
#
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
#
|
|
1
|
+
DEBUG=true
|
|
2
|
+
DESCRIPTION_META="Example description meta"
|
|
3
|
+
KEYWORDS_META="Example keywords meta"
|
|
4
|
+
TITLE_META="Blue Bird"
|
|
5
|
+
AUTHOR_META="Blue Bird"
|
|
6
|
+
DESCRIPTION="Description project"
|
|
7
|
+
TITLE="Blue Bird"
|
|
8
|
+
VERSION="1.0.0"
|
|
9
|
+
LANGMETA="en"
|
|
10
|
+
APP_URL="http://localhost"
|
|
11
|
+
HOST="localhost"
|
|
12
|
+
PORT=3000
|
|
13
|
+
STATIC_PATH="frontend/public"
|
|
14
|
+
JWT_SECRET="JWT_SECRET"
|
|
15
|
+
|
|
16
|
+
# Database Configuration
|
|
17
|
+
# SQLite (Default)
|
|
18
|
+
#Remove this line if you are not going to use sqlite
|
|
19
|
+
DATABASE_URL="file:./dev.db"
|
|
20
|
+
|
|
21
|
+
# MySQL
|
|
22
|
+
#Remove this line if you are not going to use Mysql
|
|
23
|
+
#DATABASE_URL="mysql://root:@localhost:3306/blue_bird"
|
|
24
|
+
|
|
25
|
+
# PostgreSQL
|
|
26
|
+
#Remove this line if you are not going to use PostgreSQL
|
|
26
27
|
# DATABASE_URL="postgresql://root:@localhost:5432/blue_bird?schema=public"
|
package/AGENTS.md
CHANGED
|
@@ -1,199 +1,199 @@
|
|
|
1
|
-
# Blue Bird Framework - AI Agent Guide
|
|
2
|
-
|
|
3
|
-
This document serves as the primary manual for any AI Agent interacting with the codebase. It details the architecture of Blue Bird, its internal modules, and how features should be written or modified.
|
|
4
|
-
|
|
5
|
-
## 1. Core Architecture
|
|
6
|
-
|
|
7
|
-
Blue Bird is a full-stack framework built on **Express (Backend)** and **React + Vite (Frontend)**. It is designed to save developers from repetitive configuration, packing validation, security, authentication (JWT), and multi-language support (i18n) out of the box.
|
|
8
|
-
|
|
9
|
-
- **Backend (`backend/`)**: Initializes the server using `App` from `core/app.js` and invokes routing from `backend/routes/`.
|
|
10
|
-
- **Frontend (`frontend/`)**: A React SPA handled by Vite. Default components and assets live in `frontend/resources/js/`.
|
|
11
|
-
- **Core (`core/`)**: The framework core. Contains wrapper classes such as `Router`, `Validator`, `Template`, `Auth`, `Cache`, etc. **DO NOT MODIFY** the core unless explicitly requested, as it could break other apps.
|
|
12
|
-
|
|
13
|
-
## 2. Routing (Router)
|
|
14
|
-
|
|
15
|
-
Do not use Express' native router (`express.Router()`). Always use Blue Bird's `Router` wrapper.
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
import Router from "@seip/blue-bird/core/router.js";
|
|
19
|
-
|
|
20
|
-
const routerApi = new Router("/api");
|
|
21
|
-
|
|
22
|
-
routerApi.get("/users", (req, res) => {
|
|
23
|
-
res.json({ users: [] });
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export default routerApi;
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
**For the Frontend (React Rendering / SEO):**
|
|
30
|
-
Blue Bird injects the SPA using its `Template` class.
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
import Template from "@seip/blue-bird/core/template.js";
|
|
34
|
-
|
|
35
|
-
// Render the entire App (SPA fallback)
|
|
36
|
-
router.get("*", (req, res) => {
|
|
37
|
-
return Template.renderReact(res, "App", { title: "App Title" });
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// SEO Routing (Meta tag SSR before React mounts)
|
|
41
|
-
// Automatically registers /sitemap.xml, /robots.txt, and language-prefixed routes
|
|
42
|
-
|
|
43
|
-
// Option A: Simple meta (no i18n)
|
|
44
|
-
router.seo([
|
|
45
|
-
{
|
|
46
|
-
path: "/",
|
|
47
|
-
component: "Home",
|
|
48
|
-
meta: { titleMeta: "Home", descriptionMeta: "Welcome" },
|
|
49
|
-
props: { id: 1 }
|
|
50
|
-
}
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
// Option B: Multilingual with external seoData file (recommended)
|
|
54
|
-
import seoData from "./seo.js";
|
|
55
|
-
router.seo([
|
|
56
|
-
{ path: "/", component: "Home", seoKey: "home", props: { id: 1 } },
|
|
57
|
-
{ path: "/about", component: "About", seoKey: "about" }
|
|
58
|
-
], { languages: ["en", "es"], defaultLanguage: "en", seoData });
|
|
59
|
-
// Generates: /, /en, /es, /about, /en/about, /es/about
|
|
60
|
-
|
|
61
|
-
// Option C: Multilingual inline meta
|
|
62
|
-
router.seo([
|
|
63
|
-
{
|
|
64
|
-
path: "/",
|
|
65
|
-
component: "Home",
|
|
66
|
-
meta: {
|
|
67
|
-
en: { titleMeta: "Home", descriptionMeta: "Welcome" },
|
|
68
|
-
es: { titleMeta: "Inicio", descriptionMeta: "Bienvenido" }
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
], { languages: ["en", "es"], defaultLanguage: "en" });
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Advanced SEO Features:**
|
|
75
|
-
- **SPA Navigation:** When `?source=frontend` is detected, `renderReact` returns JSON `{meta, props, component, lang}` instead of HTML.
|
|
76
|
-
- **Automatic Sitemap:** Dynamic `sitemap.xml` with all language-prefixed routes.
|
|
77
|
-
- **Robots.txt:** Auto-served pointing to the generated sitemap.
|
|
78
|
-
- **Caching:** SEO templates are cached in memory for high performance.
|
|
79
|
-
- **External SEO Data:** Use a `seo.js` file (like PHP's `seo.php`) for centralized multilingual meta management.
|
|
80
|
-
|
|
81
|
-
**Static & Hybrid Rendering (renderHtml):**
|
|
82
|
-
For ultra-fast pages (Landing, Privacy, Terms) that don't initially need React, use `Template.renderHtml`. It fallbacks to `.env` SEO values automatically.
|
|
83
|
-
|
|
84
|
-
```javascript
|
|
85
|
-
router.get("/", (req, res) => {
|
|
86
|
-
// Uses frontend/landing.html as base
|
|
87
|
-
return Template.renderHtml(res, "landing", { withAssets: false });
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
**Strategy: Controlled Collision**
|
|
92
|
-
You can use the same path for a static server page and a React route.
|
|
93
|
-
1. **Initial Load:** Express serves a static, cached HTML (instant LCP).
|
|
94
|
-
2. **Post-Mount:** React Router takes over. Navigation to `/` can then show a different component (like Login) without a full reload.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
## 3. Data Validation (Validator)
|
|
99
|
-
|
|
100
|
-
Incoming request data must be validated using `core/validate.js`, which automatically returns HTTP 400 multilingual JSON responses on error.
|
|
101
|
-
|
|
102
|
-
```javascript
|
|
103
|
-
import Validator from "@seip/blue-bird/core/validate.js";
|
|
104
|
-
|
|
105
|
-
const userSchema = {
|
|
106
|
-
email: { required: true, email: true },
|
|
107
|
-
password: { required: true, min: 8 },
|
|
108
|
-
bio: { required: false }, // *XSS mitigation is applied to all strings by default!
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// If you need raw HTML without sanitization, disable XSS explicitly.
|
|
112
|
-
const postSchema = {
|
|
113
|
-
contentHtml: { required: true, xss: false },
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const validateUser = new Validator(userSchema, "en");
|
|
117
|
-
|
|
118
|
-
routerApi.post("/users", validateUser.middleware(), (req, res) => {
|
|
119
|
-
// Reaching here means data is safe and valid
|
|
120
|
-
res.json({ success: true });
|
|
121
|
-
});
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
## 4. Authentication (Auth)
|
|
125
|
-
|
|
126
|
-
The system includes built-in JWT handling. The framework assumes tokens are passed via Cookies or the `Authorization` header.
|
|
127
|
-
|
|
128
|
-
```javascript
|
|
129
|
-
import Auth from "@seip/blue-bird/core/auth.js";
|
|
130
|
-
|
|
131
|
-
// Protect an API route (returns 401 if failed):
|
|
132
|
-
router.get("/profile", Auth.protect(), (req, res) => {
|
|
133
|
-
// The user payload is attached to req.user
|
|
134
|
-
res.json({ user: req.user });
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Protect a React route (redirects to login):
|
|
138
|
-
router.get("/dashboard", Auth.protect({ redirect: "/login" }), (req, res) => { ... });
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## 5. Performance Coaching (Cache)
|
|
142
|
-
|
|
143
|
-
If a route involves heavy processing or repetitive DB queries, utilize the in-memory `Cache` middleware.
|
|
144
|
-
|
|
145
|
-
```javascript
|
|
146
|
-
import Cache from "@seip/blue-bird/core/cache.js";
|
|
147
|
-
|
|
148
|
-
// Cache this response for 60 seconds
|
|
149
|
-
router.get("/stats", Cache.middleware(60), (req, res) => {
|
|
150
|
-
// Only executed once every 60s
|
|
151
|
-
res.json({ ok: true });
|
|
152
|
-
});
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
## 6. Security (Helmet)
|
|
156
|
-
|
|
157
|
-
Helmet is **not applied globally** by default. Apply it per-router where needed:
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
import App from "@seip/blue-bird/core/app.js";
|
|
161
|
-
|
|
162
|
-
// Apply helmet to a specific router
|
|
163
|
-
const webRouter = new Router("/web");
|
|
164
|
-
webRouter.use(App.helmet()); // Full helmet with defaults
|
|
165
|
-
webRouter.use(App.helmet({ contentSecurityPolicy: false })); // Custom options
|
|
166
|
-
|
|
167
|
-
// Or enable globally in App constructor (not recommended)
|
|
168
|
-
new App({ helmet: true });
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
## 7. SPA Navigation (SPAProvider)
|
|
172
|
-
|
|
173
|
-
The framework includes an `SPAProvider` that bridges React Router navigation with backend SEO data.
|
|
174
|
-
On every client-side `<Link>` navigation, it fetches meta/props from the backend and updates `document.title` + meta tags.
|
|
175
|
-
|
|
176
|
-
```javascript
|
|
177
|
-
// In App.jsx — already configured by default
|
|
178
|
-
import { SPAProvider } from './blue-bird/contexts/SPAContext.jsx';
|
|
179
|
-
|
|
180
|
-
<SPAProvider languages={["en", "es"]} defaultLanguage="en">
|
|
181
|
-
<Routes>...</Routes>
|
|
182
|
-
</SPAProvider>
|
|
183
|
-
|
|
184
|
-
// In components — use navigateToLang for language switching
|
|
185
|
-
import { useSPA } from './blue-bird/contexts/SPAContext.jsx';
|
|
186
|
-
const { navigateToLang, pageProps, pageMeta } = useSPA();
|
|
187
|
-
navigateToLang("es"); // Navigates to /es/current-path and updates meta
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
## 8. AI Development Guidelines
|
|
191
|
-
|
|
192
|
-
1. **Frontend**: Components must be Functional React components, leveraging Tailwind CSS. Avoid inline styles. Reuse components from `blue-bird/components/` (e.g., Card, Button, Input) if available.
|
|
193
|
-
2. **JSON Responses**: API endpoints should return standardized responses formatted as `{ message: "..." }` or `{ data: ... }`.
|
|
194
|
-
3. **i18n**: Check the `useLanguage` hook provided in React for multi-language components; avoid hardcoding display strings when localization is active.
|
|
195
|
-
4. **Magic Imports**: Stick to pure relative imports or well-configured aliases (imports natively resolve from `@seip/blue-bird/...` or relative directories like `../../`).
|
|
196
|
-
5. **SPA Navigation**: Use `<Link>` from `react-router-dom` for internal navigation. The `SPAProvider` automatically fetches and updates meta tags.
|
|
197
|
-
6. **Language Routes**: When using multilingual SEO, routes are generated for all language prefixes. Use `navigateToLang()` from `useSPA()` to switch languages.
|
|
198
|
-
|
|
199
|
-
_This file can be retrieved by intelligent agents reading its absolute physical path during reasoning._
|
|
1
|
+
# Blue Bird Framework - AI Agent Guide
|
|
2
|
+
|
|
3
|
+
This document serves as the primary manual for any AI Agent interacting with the codebase. It details the architecture of Blue Bird, its internal modules, and how features should be written or modified.
|
|
4
|
+
|
|
5
|
+
## 1. Core Architecture
|
|
6
|
+
|
|
7
|
+
Blue Bird is a full-stack framework built on **Express (Backend)** and **React + Vite (Frontend)**. It is designed to save developers from repetitive configuration, packing validation, security, authentication (JWT), and multi-language support (i18n) out of the box.
|
|
8
|
+
|
|
9
|
+
- **Backend (`backend/`)**: Initializes the server using `App` from `core/app.js` and invokes routing from `backend/routes/`.
|
|
10
|
+
- **Frontend (`frontend/`)**: A React SPA handled by Vite. Default components and assets live in `frontend/resources/js/`.
|
|
11
|
+
- **Core (`core/`)**: The framework core. Contains wrapper classes such as `Router`, `Validator`, `Template`, `Auth`, `Cache`, etc. **DO NOT MODIFY** the core unless explicitly requested, as it could break other apps.
|
|
12
|
+
|
|
13
|
+
## 2. Routing (Router)
|
|
14
|
+
|
|
15
|
+
Do not use Express' native router (`express.Router()`). Always use Blue Bird's `Router` wrapper.
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import Router from "@seip/blue-bird/core/router.js";
|
|
19
|
+
|
|
20
|
+
const routerApi = new Router("/api");
|
|
21
|
+
|
|
22
|
+
routerApi.get("/users", (req, res) => {
|
|
23
|
+
res.json({ users: [] });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export default routerApi;
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**For the Frontend (React Rendering / SEO):**
|
|
30
|
+
Blue Bird injects the SPA using its `Template` class.
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import Template from "@seip/blue-bird/core/template.js";
|
|
34
|
+
|
|
35
|
+
// Render the entire App (SPA fallback)
|
|
36
|
+
router.get("*", (req, res) => {
|
|
37
|
+
return Template.renderReact(res, "App", { title: "App Title" });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// SEO Routing (Meta tag SSR before React mounts)
|
|
41
|
+
// Automatically registers /sitemap.xml, /robots.txt, and language-prefixed routes
|
|
42
|
+
|
|
43
|
+
// Option A: Simple meta (no i18n)
|
|
44
|
+
router.seo([
|
|
45
|
+
{
|
|
46
|
+
path: "/",
|
|
47
|
+
component: "Home",
|
|
48
|
+
meta: { titleMeta: "Home", descriptionMeta: "Welcome" },
|
|
49
|
+
props: { id: 1 }
|
|
50
|
+
}
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
// Option B: Multilingual with external seoData file (recommended)
|
|
54
|
+
import seoData from "./seo.js";
|
|
55
|
+
router.seo([
|
|
56
|
+
{ path: "/", component: "Home", seoKey: "home", props: { id: 1 } },
|
|
57
|
+
{ path: "/about", component: "About", seoKey: "about" }
|
|
58
|
+
], { languages: ["en", "es"], defaultLanguage: "en", seoData });
|
|
59
|
+
// Generates: /, /en, /es, /about, /en/about, /es/about
|
|
60
|
+
|
|
61
|
+
// Option C: Multilingual inline meta
|
|
62
|
+
router.seo([
|
|
63
|
+
{
|
|
64
|
+
path: "/",
|
|
65
|
+
component: "Home",
|
|
66
|
+
meta: {
|
|
67
|
+
en: { titleMeta: "Home", descriptionMeta: "Welcome" },
|
|
68
|
+
es: { titleMeta: "Inicio", descriptionMeta: "Bienvenido" }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
], { languages: ["en", "es"], defaultLanguage: "en" });
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Advanced SEO Features:**
|
|
75
|
+
- **SPA Navigation:** When `?source=frontend` is detected, `renderReact` returns JSON `{meta, props, component, lang}` instead of HTML.
|
|
76
|
+
- **Automatic Sitemap:** Dynamic `sitemap.xml` with all language-prefixed routes.
|
|
77
|
+
- **Robots.txt:** Auto-served pointing to the generated sitemap.
|
|
78
|
+
- **Caching:** SEO templates are cached in memory for high performance.
|
|
79
|
+
- **External SEO Data:** Use a `seo.js` file (like PHP's `seo.php`) for centralized multilingual meta management.
|
|
80
|
+
|
|
81
|
+
**Static & Hybrid Rendering (renderHtml):**
|
|
82
|
+
For ultra-fast pages (Landing, Privacy, Terms) that don't initially need React, use `Template.renderHtml`. It fallbacks to `.env` SEO values automatically.
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
router.get("/", (req, res) => {
|
|
86
|
+
// Uses frontend/landing.html as base
|
|
87
|
+
return Template.renderHtml(res, "landing", { withAssets: false });
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Strategy: Controlled Collision**
|
|
92
|
+
You can use the same path for a static server page and a React route.
|
|
93
|
+
1. **Initial Load:** Express serves a static, cached HTML (instant LCP).
|
|
94
|
+
2. **Post-Mount:** React Router takes over. Navigation to `/` can then show a different component (like Login) without a full reload.
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## 3. Data Validation (Validator)
|
|
99
|
+
|
|
100
|
+
Incoming request data must be validated using `core/validate.js`, which automatically returns HTTP 400 multilingual JSON responses on error.
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import Validator from "@seip/blue-bird/core/validate.js";
|
|
104
|
+
|
|
105
|
+
const userSchema = {
|
|
106
|
+
email: { required: true, email: true },
|
|
107
|
+
password: { required: true, min: 8 },
|
|
108
|
+
bio: { required: false }, // *XSS mitigation is applied to all strings by default!
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
// If you need raw HTML without sanitization, disable XSS explicitly.
|
|
112
|
+
const postSchema = {
|
|
113
|
+
contentHtml: { required: true, xss: false },
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const validateUser = new Validator(userSchema, "en");
|
|
117
|
+
|
|
118
|
+
routerApi.post("/users", validateUser.middleware(), (req, res) => {
|
|
119
|
+
// Reaching here means data is safe and valid
|
|
120
|
+
res.json({ success: true });
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 4. Authentication (Auth)
|
|
125
|
+
|
|
126
|
+
The system includes built-in JWT handling. The framework assumes tokens are passed via Cookies or the `Authorization` header.
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import Auth from "@seip/blue-bird/core/auth.js";
|
|
130
|
+
|
|
131
|
+
// Protect an API route (returns 401 if failed):
|
|
132
|
+
router.get("/profile", Auth.protect(), (req, res) => {
|
|
133
|
+
// The user payload is attached to req.user
|
|
134
|
+
res.json({ user: req.user });
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Protect a React route (redirects to login):
|
|
138
|
+
router.get("/dashboard", Auth.protect({ redirect: "/login" }), (req, res) => { ... });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## 5. Performance Coaching (Cache)
|
|
142
|
+
|
|
143
|
+
If a route involves heavy processing or repetitive DB queries, utilize the in-memory `Cache` middleware.
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
import Cache from "@seip/blue-bird/core/cache.js";
|
|
147
|
+
|
|
148
|
+
// Cache this response for 60 seconds
|
|
149
|
+
router.get("/stats", Cache.middleware(60), (req, res) => {
|
|
150
|
+
// Only executed once every 60s
|
|
151
|
+
res.json({ ok: true });
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## 6. Security (Helmet)
|
|
156
|
+
|
|
157
|
+
Helmet is **not applied globally** by default. Apply it per-router where needed:
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
import App from "@seip/blue-bird/core/app.js";
|
|
161
|
+
|
|
162
|
+
// Apply helmet to a specific router
|
|
163
|
+
const webRouter = new Router("/web");
|
|
164
|
+
webRouter.use(App.helmet()); // Full helmet with defaults
|
|
165
|
+
webRouter.use(App.helmet({ contentSecurityPolicy: false })); // Custom options
|
|
166
|
+
|
|
167
|
+
// Or enable globally in App constructor (not recommended)
|
|
168
|
+
new App({ helmet: true });
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 7. SPA Navigation (SPAProvider)
|
|
172
|
+
|
|
173
|
+
The framework includes an `SPAProvider` that bridges React Router navigation with backend SEO data.
|
|
174
|
+
On every client-side `<Link>` navigation, it fetches meta/props from the backend and updates `document.title` + meta tags.
|
|
175
|
+
|
|
176
|
+
```javascript
|
|
177
|
+
// In App.jsx — already configured by default
|
|
178
|
+
import { SPAProvider } from './blue-bird/contexts/SPAContext.jsx';
|
|
179
|
+
|
|
180
|
+
<SPAProvider languages={["en", "es"]} defaultLanguage="en">
|
|
181
|
+
<Routes>...</Routes>
|
|
182
|
+
</SPAProvider>
|
|
183
|
+
|
|
184
|
+
// In components — use navigateToLang for language switching
|
|
185
|
+
import { useSPA } from './blue-bird/contexts/SPAContext.jsx';
|
|
186
|
+
const { navigateToLang, pageProps, pageMeta } = useSPA();
|
|
187
|
+
navigateToLang("es"); // Navigates to /es/current-path and updates meta
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 8. AI Development Guidelines
|
|
191
|
+
|
|
192
|
+
1. **Frontend**: Components must be Functional React components, leveraging Tailwind CSS. Avoid inline styles. Reuse components from `blue-bird/components/` (e.g., Card, Button, Input) if available.
|
|
193
|
+
2. **JSON Responses**: API endpoints should return standardized responses formatted as `{ message: "..." }` or `{ data: ... }`.
|
|
194
|
+
3. **i18n**: Check the `useLanguage` hook provided in React for multi-language components; avoid hardcoding display strings when localization is active.
|
|
195
|
+
4. **Magic Imports**: Stick to pure relative imports or well-configured aliases (imports natively resolve from `@seip/blue-bird/...` or relative directories like `../../`).
|
|
196
|
+
5. **SPA Navigation**: Use `<Link>` from `react-router-dom` for internal navigation. The `SPAProvider` automatically fetches and updates meta tags.
|
|
197
|
+
6. **Language Routes**: When using multilingual SEO, routes are generated for all language prefixes. Use `navigateToLang()` from `useSPA()` to switch languages.
|
|
198
|
+
|
|
199
|
+
_This file can be retrieved by intelligent agents reading its absolute physical path during reasoning._
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andres Paiva
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
# Blue Bird Framework
|
|
2
|
-
|
|
3
|
-
**The Future of Express & React Development**
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
[](https://www.npmjs.com/package/@seip/blue-bird)
|
|
8
|
-
[](https://opensource.org/licenses/MIT)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## 🌟 Introduction / Introducción
|
|
12
|
-
|
|
13
|
-
**Blue Bird** is a powerful, opinionated structure based on **Express** and **React**. It's designed to help developers build fast, scalable applications,apis and everything pre-configured.
|
|
14
|
-
|
|
15
|
-
**Blue Bird** es una estructura potente basada en **Express** y **React**. Está diseñada para ayudar a los desarrolladores a construir aplicaciones rápidas ,apis escalables y todo pre-configurado.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## 🚀 Key Features / Características Clave
|
|
20
|
-
|
|
21
|
-
- ⚡ **All-In-One**: Express, React, Vite, JWT Auth, and Validations ready to go.
|
|
22
|
-
- 💎 **Flexible**: Extensible via standard Express `.use()` middleware.
|
|
23
|
-
- 🔐 **Secure**: Integrated JWT authentication and multi-language validation.
|
|
24
|
-
- 📁 **Uploads**: Easy file handling with Multer-based helpers.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## 🛠️ Quick Start / Inicio Rápido
|
|
29
|
-
|
|
30
|
-
### 1. Installation / Instalación
|
|
31
|
-
```bash
|
|
32
|
-
npm install @seip/blue-bird
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### 2. Initialize / Inicializar
|
|
36
|
-
```bash
|
|
37
|
-
npx blue-bird
|
|
38
|
-
```
|
|
39
|
-
*This copies the base structure: `backend`, `frontend`, and `.env`.*
|
|
40
|
-
*Esto copia la estructura base: `backend`, `frontend` y `.env`.*
|
|
41
|
-
|
|
42
|
-
### 3. Setup React
|
|
43
|
-
```bash
|
|
44
|
-
npm run react
|
|
45
|
-
```
|
|
46
|
-
*Configures React, React Router, and Vite automatically.*
|
|
47
|
-
*Configura React, React Router y Vite automáticamente.*
|
|
48
|
-
|
|
49
|
-
### 4. Development / Desarrollo
|
|
50
|
-
```bash
|
|
51
|
-
# Start Backend (Express)
|
|
52
|
-
npm run dev
|
|
53
|
-
|
|
54
|
-
# Start Frontend (Vite)
|
|
55
|
-
npm run vite:dev
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
<hr />
|
|
59
|
-
|
|
60
|
-
## 📖 Documentation / Documentación
|
|
61
|
-
|
|
62
|
-
Check out our full documentation for detailed API reference and examples:
|
|
63
|
-
|
|
64
|
-
- 🇺🇸 [English Documentation](https://seip25.github.io/Blue-bird/en.html)
|
|
65
|
-
- 🇪🇸 [Documentación en Español](https://seip25.github.io/Blue-bird/index.html)
|
|
66
|
-
|
|
67
|
-
<hr />
|
|
68
|
-
|
|
69
|
-
## 📄 License / Licencia
|
|
70
|
-
|
|
71
|
-
Distributed under the **MIT License**. See `LICENSE` for more information.
|
|
72
|
-
|
|
73
|
-
Distribuido bajo la **Licencia MIT**. Mira `LICENSE` para más información.
|
|
74
|
-
|
|
75
|
-
<hr />
|
|
76
|
-
|
|
77
|
-
<div align="center">
|
|
78
|
-
<p>Made with ❤️ by <strong>Seip25</strong></p>
|
|
79
|
-
</div>
|
|
1
|
+
# Blue Bird Framework
|
|
2
|
+
|
|
3
|
+
**The Future of Express & React Development**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@seip/blue-bird)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## 🌟 Introduction / Introducción
|
|
12
|
+
|
|
13
|
+
**Blue Bird** is a powerful, opinionated structure based on **Express** and **React**. It's designed to help developers build fast, scalable applications,apis and everything pre-configured.
|
|
14
|
+
|
|
15
|
+
**Blue Bird** es una estructura potente basada en **Express** y **React**. Está diseñada para ayudar a los desarrolladores a construir aplicaciones rápidas ,apis escalables y todo pre-configurado.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 🚀 Key Features / Características Clave
|
|
20
|
+
|
|
21
|
+
- ⚡ **All-In-One**: Express, React, Vite, JWT Auth, and Validations ready to go.
|
|
22
|
+
- 💎 **Flexible**: Extensible via standard Express `.use()` middleware.
|
|
23
|
+
- 🔐 **Secure**: Integrated JWT authentication and multi-language validation.
|
|
24
|
+
- 📁 **Uploads**: Easy file handling with Multer-based helpers.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 🛠️ Quick Start / Inicio Rápido
|
|
29
|
+
|
|
30
|
+
### 1. Installation / Instalación
|
|
31
|
+
```bash
|
|
32
|
+
npm install @seip/blue-bird
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Initialize / Inicializar
|
|
36
|
+
```bash
|
|
37
|
+
npx blue-bird
|
|
38
|
+
```
|
|
39
|
+
*This copies the base structure: `backend`, `frontend`, and `.env`.*
|
|
40
|
+
*Esto copia la estructura base: `backend`, `frontend` y `.env`.*
|
|
41
|
+
|
|
42
|
+
### 3. Setup React
|
|
43
|
+
```bash
|
|
44
|
+
npm run react
|
|
45
|
+
```
|
|
46
|
+
*Configures React, React Router, and Vite automatically.*
|
|
47
|
+
*Configura React, React Router y Vite automáticamente.*
|
|
48
|
+
|
|
49
|
+
### 4. Development / Desarrollo
|
|
50
|
+
```bash
|
|
51
|
+
# Start Backend (Express)
|
|
52
|
+
npm run dev
|
|
53
|
+
|
|
54
|
+
# Start Frontend (Vite)
|
|
55
|
+
npm run vite:dev
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
<hr />
|
|
59
|
+
|
|
60
|
+
## 📖 Documentation / Documentación
|
|
61
|
+
|
|
62
|
+
Check out our full documentation for detailed API reference and examples:
|
|
63
|
+
|
|
64
|
+
- 🇺🇸 [English Documentation](https://seip25.github.io/Blue-bird/en.html)
|
|
65
|
+
- 🇪🇸 [Documentación en Español](https://seip25.github.io/Blue-bird/index.html)
|
|
66
|
+
|
|
67
|
+
<hr />
|
|
68
|
+
|
|
69
|
+
## 📄 License / Licencia
|
|
70
|
+
|
|
71
|
+
Distributed under the **MIT License**. See `LICENSE` for more information.
|
|
72
|
+
|
|
73
|
+
Distribuido bajo la **Licencia MIT**. Mira `LICENSE` para más información.
|
|
74
|
+
|
|
75
|
+
<hr />
|
|
76
|
+
|
|
77
|
+
<div align="center">
|
|
78
|
+
<p>Made with ❤️ by <strong>Seip25</strong></p>
|
|
79
|
+
</div>
|
package/backend/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import App from "@seip/blue-bird/core/app.js";
|
|
2
|
-
import routerApiExample from "./routes/api.js";
|
|
3
|
-
import routerFrontendExample from "./routes/frontend.js";
|
|
4
|
-
|
|
5
|
-
const app = new App({
|
|
6
|
-
routes: [routerApiExample, routerFrontendExample],
|
|
7
|
-
cors: [],
|
|
8
|
-
middlewares: [],
|
|
9
|
-
host: "http://localhost",
|
|
10
|
-
port: process.env.PORT,
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
app.run();
|
|
1
|
+
import App from "@seip/blue-bird/core/app.js";
|
|
2
|
+
import routerApiExample from "./routes/api.js";
|
|
3
|
+
import routerFrontendExample from "./routes/frontend.js";
|
|
4
|
+
|
|
5
|
+
const app = new App({
|
|
6
|
+
routes: [routerApiExample, routerFrontendExample],
|
|
7
|
+
cors: [],
|
|
8
|
+
middlewares: [],
|
|
9
|
+
host: "http://localhost",
|
|
10
|
+
port: process.env.PORT,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.run();
|