@flexireact/core 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 FlexiReact Team
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 ADDED
@@ -0,0 +1,549 @@
1
+ <p align="center">
2
+ <img src="./assets/logo.png" alt="FlexiReact Logo" width="400" />
3
+ </p>
4
+
5
+ <h1 align="center">FlexiReact</h1>
6
+
7
+ <p align="center">
8
+ <strong>The Modern React Framework</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ A blazing-fast React framework with TypeScript, Tailwind CSS, SSR, SSG, Islands architecture, and file-based routing.<br/>
13
+ Inspired by Next.js, Remix, Astro, and TanStack Start — but simpler and lighter.
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://www.npmjs.com/package/flexireact"><img src="https://img.shields.io/npm/v/flexireact.svg" alt="npm version" /></a>
18
+ <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT" /></a>
19
+ <a href="#"><img src="https://img.shields.io/badge/TypeScript-Ready-blue.svg" alt="TypeScript Ready" /></a>
20
+ <a href="#"><img src="https://img.shields.io/badge/Tailwind-CSS-38B2AC.svg" alt="Tailwind CSS" /></a>
21
+ </p>
22
+
23
+ ## ✨ Features
24
+
25
+ ### 🏗️ Core Framework
26
+
27
+ | Feature | Description |
28
+ |---------|-------------|
29
+ | 📘 **TypeScript First** | Full TypeScript support with strict type checking and excellent DX |
30
+ | ⚡ **Lightning Fast** | Powered by esbuild for instant builds and sub-second HMR |
31
+ | 📁 **File-based Routing** | Create a file in `pages/`, get a route automatically |
32
+ | 🏝️ **Islands Architecture** | Partial hydration for minimal JavaScript and maximum performance |
33
+ | 🖥️ **SSR / SSG / ISR** | Server-side rendering, static generation, and incremental regeneration |
34
+ | 🔌 **API Routes** | Build your REST/GraphQL API alongside your frontend |
35
+
36
+ ### 🧩 Layouts & Components
37
+
38
+ | Feature | Description |
39
+ |---------|-------------|
40
+ | 📐 **Nested Layouts** | Shared layouts with `_layout.tsx` that persist across navigation |
41
+ | 🎭 **Server Components** | `'use server'` directive for server-only components (zero JS) |
42
+ | 💻 **Client Components** | `'use client'` directive for interactive client-side components |
43
+ | 🎨 **Tailwind CSS** | Pre-configured with beautiful defaults, dark mode, and CSS variables |
44
+ | 🧱 **UI Components** | Button, Card, Modal, Tooltip, Drawer, Table, Input, Skeleton... |
45
+ | ✨ **shadcn/ui Ready** | Compatible component system with CVA variants |
46
+
47
+ ### 📊 Data Fetching & State
48
+
49
+ | Feature | Description |
50
+ |---------|-------------|
51
+ | 🔄 **getServerSideProps** | Fetch data on every request (SSR) |
52
+ | 📦 **getStaticProps** | Fetch data at build time (SSG) |
53
+ | 🚀 **Prefetch** | Automatic link prefetching for instant navigation |
54
+ | 🔍 **TanStack Query** | Built-in support for useQuery, useMutation, and caching |
55
+ | 🐻 **Zustand / Jotai** | Lightweight state management integration |
56
+ | ⚡ **Optimistic Updates** | Instant UI feedback with automatic rollback |
57
+ | ⏳ **Suspense Ready** | React Suspense for loading states and streaming |
58
+
59
+ ### 🛡️ Middleware & Security
60
+
61
+ | Feature | Description |
62
+ |---------|-------------|
63
+ | � **Middleware System** | Run code before every request (auth, logging, redirects) |
64
+ | 🔐 **Authentication** | Email/password + OAuth (Google, GitHub, Discord) |
65
+ | 👥 **RBAC** | Role-based access control with permissions |
66
+ | 🛡️ **Security** | Built-in CSRF, XSS, CORS protection |
67
+ | ⏱️ **Rate Limiting** | Protect your API from abuse |
68
+ | 📝 **Request Logging** | Structured logging with levels and formatting |
69
+
70
+ ### 🚀 Performance & Build
71
+
72
+ | Feature | Description |
73
+ |---------|-------------|
74
+ | 📦 **Code Splitting** | Automatic route-based code splitting |
75
+ | 🦥 **Lazy Loading** | Dynamic imports with `React.lazy()` support |
76
+ | 🌳 **Tree Shaking** | Dead code elimination for minimal bundles |
77
+ | 📊 **Bundle Analysis** | Visualize your bundle size with built-in analyzer |
78
+ | �️ **Compression** | Gzip/Brotli compression out of the box |
79
+ | 🖼️ **Image Optimization** | Automatic image resizing, WebP conversion, lazy loading |
80
+
81
+ ### 🔧 Developer Experience
82
+
83
+ | Feature | Description |
84
+ |---------|-------------|
85
+ | 🔥 **Hot Reloading** | Instant updates without losing state |
86
+ | 🐛 **Error Overlay** | Beautiful error messages with stack traces |
87
+ | � **ESLint + Prettier** | Pre-configured linting and formatting |
88
+ | 🎨 **Tailwind IntelliSense** | Full autocomplete for Tailwind classes |
89
+ | 📋 **Multiple Templates** | Starter templates: minimal, blog, dashboard, e-commerce |
90
+ | 🩺 **Doctor Command** | `flexi doctor` to diagnose project issues |
91
+
92
+ ### 🔍 SEO & Analytics
93
+
94
+ | Feature | Description |
95
+ |---------|-------------|
96
+ | 🏷️ **Auto Meta Tags** | Automatic title, description, and canonical URLs |
97
+ | 📱 **Open Graph** | Social media preview cards (Twitter, Facebook, LinkedIn) |
98
+ | 🗺️ **Sitemap** | Auto-generated sitemap.xml for search engines |
99
+ | 📈 **Performance Monitoring** | Core Web Vitals tracking built-in |
100
+ | � **robots.txt** | Configurable robots.txt generation |
101
+ | 📊 **Analytics Ready** | Easy integration with Google Analytics, Plausible, etc. |
102
+
103
+ ### 🔌 Extensibility
104
+
105
+ | Feature | Description |
106
+ |---------|-------------|
107
+ | 🧩 **Plugin System** | Extend FlexiReact with community plugins |
108
+ | 🎣 **Lifecycle Hooks** | `beforeRender`, `afterRender`, `onError` hooks |
109
+ | 📦 **Custom Templates** | Create and share your own project templates |
110
+ | 🔄 **Migration Tools** | Automatic migration from Next.js, CRA, Vite |
111
+ | ⚙️ **Config API** | Fully customizable `flexireact.config.ts` |
112
+
113
+ ---
114
+
115
+ ## 🆚 Why FlexiReact?
116
+
117
+ | | FlexiReact | Next.js | Remix | Astro |
118
+ |---|:---:|:---:|:---:|:---:|
119
+ | **Zero Config** | ✅ | ⚠️ | ⚠️ | ✅ |
120
+ | **TypeScript** | ✅ | ✅ | ✅ | ✅ |
121
+ | **Islands Architecture** | ✅ | ❌ | ❌ | ✅ |
122
+ | **File Routing** | ✅ | ✅ | ✅ | ✅ |
123
+ | **API Routes** | ✅ | ✅ | ✅ | ⚠️ |
124
+ | **Server Components** | ✅ | ✅ | ❌ | ✅ |
125
+ | **Bundle Size** | 🟢 Tiny | 🟡 Medium | 🟡 Medium | 🟢 Tiny |
126
+ | **Build Speed** | 🟢 <1s | 🟡 ~5s | 🟡 ~3s | 🟢 <2s |
127
+ | **Learning Curve** | 🟢 Easy | 🟡 Medium | 🟡 Medium | 🟢 Easy |
128
+ | **Plugin System** | ✅ | ⚠️ | ❌ | ✅ |
129
+
130
+ ### 💡 Perfect For
131
+
132
+ - **Startups** — Ship fast with zero configuration
133
+ - **Enterprises** — Scale with TypeScript, security, and performance
134
+ - **Developers** — Enjoy excellent DX with hot reload and error overlays
135
+ - **Agencies** — Reuse templates and plugins across projects
136
+
137
+ ---
138
+
139
+ ## 🚀 Quick Start
140
+
141
+ ```bash
142
+ # Create a new project
143
+ npx flexireact create myapp
144
+ cd myapp
145
+
146
+ # Start development server
147
+ npm run dev
148
+
149
+ # Build for production
150
+ npm run build
151
+
152
+ # Start production server
153
+ npm run start
154
+ ```
155
+
156
+ Open http://localhost:3000
157
+
158
+ ## 📁 Project Structure
159
+
160
+ ```
161
+ myapp/
162
+ ├── app/ # App directory
163
+ │ ├── components/ # Reusable components
164
+ │ │ ├── Button.tsx # Button component
165
+ │ │ ├── Card.tsx # Card component
166
+ │ │ ├── Navbar.tsx # Navigation bar
167
+ │ │ └── index.ts # Component exports
168
+ │ ├── styles/
169
+ │ │ └── globals.css # Global styles + Tailwind
170
+ │ └── layout.tsx # Root layout
171
+ ├── pages/ # Routes (file-based)
172
+ │ ├── index.tsx # → /
173
+ │ ├── about.tsx # → /about
174
+ │ ├── blog/
175
+ │ │ ├── index.tsx # → /blog
176
+ │ │ └── [slug].tsx # → /blog/:slug
177
+ │ └── api/
178
+ │ └── hello.ts # → /api/hello
179
+ ├── public/ # Static assets
180
+ ├── tailwind.config.js # Tailwind configuration
181
+ ├── tsconfig.json # TypeScript configuration
182
+ ├── flexireact.config.ts # FlexiReact configuration
183
+ └── package.json
184
+ ```
185
+
186
+ ## 🛣️ Routing
187
+
188
+ ### Page Routes
189
+
190
+ | File | Route |
191
+ |------|-------|
192
+ | `pages/index.jsx` | `/` |
193
+ | `pages/about.jsx` | `/about` |
194
+ | `pages/blog/[slug].jsx` | `/blog/:slug` |
195
+ | `pages/[...path].jsx` | Catch-all route |
196
+
197
+ ### Dynamic Routes
198
+
199
+ ```jsx
200
+ // pages/users/[id].jsx
201
+ export default function User({ params }) {
202
+ return <h1>User: {params.id}</h1>;
203
+ }
204
+ ```
205
+
206
+ ### Route Groups
207
+
208
+ Use parentheses to group routes without affecting the URL:
209
+
210
+ ```
211
+ pages/
212
+ (marketing)/
213
+ about.jsx # → /about
214
+ contact.jsx # → /contact
215
+ (app)/
216
+ dashboard.jsx # → /dashboard
217
+ ```
218
+
219
+ ## 📐 Layouts
220
+
221
+ Create persistent layouts in `layouts/`:
222
+
223
+ ```jsx
224
+ // layouts/root.jsx
225
+ export default function RootLayout({ children }) {
226
+ return (
227
+ <div>
228
+ <header>My App</header>
229
+ <main>{children}</main>
230
+ <footer>© 2024</footer>
231
+ </div>
232
+ );
233
+ }
234
+ ```
235
+
236
+ ## ⏳ Loading & Error States
237
+
238
+ ```jsx
239
+ // pages/loading.jsx
240
+ export default function Loading() {
241
+ return <div>Loading...</div>;
242
+ }
243
+
244
+ // pages/error.jsx
245
+ export default function Error({ error }) {
246
+ return <div>Error: {error.message}</div>;
247
+ }
248
+ ```
249
+
250
+ ## 🔄 Data Fetching
251
+
252
+ ### Server-Side Rendering (SSR)
253
+
254
+ ```jsx
255
+ export async function getServerSideProps({ params, req }) {
256
+ const data = await fetchData(params.id);
257
+
258
+ if (!data) {
259
+ return { notFound: true };
260
+ }
261
+
262
+ return { props: { data } };
263
+ }
264
+
265
+ export default function Page({ data }) {
266
+ return <div>{data.title}</div>;
267
+ }
268
+ ```
269
+
270
+ ### Static Site Generation (SSG)
271
+
272
+ ```jsx
273
+ // For dynamic routes
274
+ export async function getStaticPaths() {
275
+ return {
276
+ paths: [
277
+ { params: { slug: 'hello' } },
278
+ { params: { slug: 'world' } }
279
+ ],
280
+ fallback: false
281
+ };
282
+ }
283
+
284
+ export async function getStaticProps({ params }) {
285
+ const post = await getPost(params.slug);
286
+ return { props: { post } };
287
+ }
288
+ ```
289
+
290
+ ## 🏝️ Islands Architecture
291
+
292
+ Islands allow partial hydration — only interactive components load JavaScript:
293
+
294
+ ```jsx
295
+ 'use island';
296
+
297
+ import { useState } from 'react';
298
+
299
+ // This component will be hydrated on the client
300
+ export default function Counter() {
301
+ const [count, setCount] = useState(0);
302
+ return (
303
+ <button onClick={() => setCount(c => c + 1)}>
304
+ Count: {count}
305
+ </button>
306
+ );
307
+ }
308
+ ```
309
+
310
+ Static content around islands remains as pure HTML with zero JavaScript.
311
+
312
+ ## 🖥️ React Server Components
313
+
314
+ Mark components to run only on the server:
315
+
316
+ ```jsx
317
+ 'use server';
318
+
319
+ // This component never ships to the client
320
+ export default async function ServerData() {
321
+ const data = await db.query('SELECT * FROM users');
322
+ return <UserList users={data} />;
323
+ }
324
+ ```
325
+
326
+ Mark client components explicitly:
327
+
328
+ ```jsx
329
+ 'use client';
330
+
331
+ // This component will be hydrated
332
+ export default function InteractiveWidget() {
333
+ // Client-side interactivity here
334
+ }
335
+ ```
336
+
337
+ ## 🔌 API Routes
338
+
339
+ ```js
340
+ // pages/api/users.js
341
+
342
+ export function get(req, res) {
343
+ res.json({ users: [] });
344
+ }
345
+
346
+ export function post(req, res) {
347
+ const { name } = req.body;
348
+ res.status(201).json({ id: 1, name });
349
+ }
350
+ ```
351
+
352
+ ## 🛡️ Middleware
353
+
354
+ Create `middleware.js` in your project root:
355
+
356
+ ```js
357
+ export default function middleware(request) {
358
+ // Protect routes
359
+ if (request.pathname.startsWith('/admin')) {
360
+ if (!request.cookie('token')) {
361
+ return MiddlewareResponse.redirect('/login');
362
+ }
363
+ }
364
+
365
+ // Continue
366
+ return MiddlewareResponse.next();
367
+ }
368
+
369
+ export const config = {
370
+ matcher: ['/admin/:path*', '/api/:path*']
371
+ };
372
+ ```
373
+
374
+ ## 🔧 Configuration
375
+
376
+ Create `flexireact.config.js`:
377
+
378
+ ```js
379
+ export default {
380
+ server: {
381
+ port: 3000,
382
+ host: 'localhost'
383
+ },
384
+
385
+ build: {
386
+ target: 'es2022',
387
+ minify: true,
388
+ sourcemap: true
389
+ },
390
+
391
+ islands: {
392
+ enabled: true
393
+ },
394
+
395
+ rsc: {
396
+ enabled: true
397
+ },
398
+
399
+ ssg: {
400
+ enabled: false,
401
+ paths: []
402
+ },
403
+
404
+ plugins: []
405
+ };
406
+ ```
407
+
408
+ ## 🧩 Plugins
409
+
410
+ Create `flexireact.plugin.js`:
411
+
412
+ ```js
413
+ export default {
414
+ name: 'my-plugin',
415
+
416
+ onServerStart(server) {
417
+ console.log('Server started!');
418
+ },
419
+
420
+ onBeforeRender(page, props) {
421
+ return { ...props, injected: true };
422
+ },
423
+
424
+ onAfterRender(html) {
425
+ return html.replace('</head>', '<script>...</script></head>');
426
+ }
427
+ };
428
+ ```
429
+
430
+ ### Built-in Plugins
431
+
432
+ ```js
433
+ import { builtinPlugins } from 'flexireact';
434
+
435
+ export default {
436
+ plugins: [
437
+ builtinPlugins.analytics({ trackingId: 'UA-XXX' }),
438
+ builtinPlugins.pwa({ manifest: '/manifest.json' }),
439
+ builtinPlugins.securityHeaders()
440
+ ]
441
+ };
442
+ ```
443
+
444
+ ## 🖥️ CLI Commands
445
+
446
+ ```bash
447
+ flexi create <name> # Create new project
448
+ flexi dev # Start dev server
449
+ flexi build # Build for production
450
+ flexi start # Start production server
451
+ flexi doctor # Check project health
452
+ flexi --version # Show version
453
+ flexi help # Show help
454
+ ```
455
+
456
+ ## 📚 Concepts Explained
457
+
458
+ ### React Server Components (RSC)
459
+
460
+ RSC allows components to execute exclusively on the server:
461
+ - **Zero client JavaScript** for server components
462
+ - **Direct database/filesystem access** in components
463
+ - **Smaller bundles** — server code never ships to client
464
+ - **Better security** — sensitive logic stays on server
465
+
466
+ ### Static Site Generation (SSG)
467
+
468
+ SSG pre-renders pages at build time:
469
+ - **Fastest possible loads** — pages are static HTML
470
+ - **CDN cacheable** — serve from edge locations
471
+ - **SEO friendly** — full HTML for crawlers
472
+ - **Incremental regeneration** — update without full rebuild
473
+
474
+ ### Islands Architecture
475
+
476
+ Islands provide partial hydration:
477
+ - **Minimal JavaScript** — only interactive parts hydrate
478
+ - **Progressive enhancement** — works without JS
479
+ - **Better performance** — less code to parse/execute
480
+ - **Selective loading** — hydrate on visibility, interaction, etc.
481
+
482
+ ## 🎨 FlexiUI - Official UI Library
483
+
484
+ FlexiReact comes with an official UI component library: **@flexireact/flexi-ui**
485
+
486
+ ```bash
487
+ npm install @flexireact/flexi-ui
488
+ ```
489
+
490
+ ### Features
491
+ - 🌙 **Dark-first design** with neon emerald accents
492
+ - ♿ **Fully accessible** (ARIA-compliant, Radix UI primitives)
493
+ - 🎯 **TypeScript native** with full type safety
494
+ - 🌳 **Tree-shakeable** — import only what you need
495
+ - ⚡ **SSR ready** — works with FlexiReact SSR
496
+
497
+ ### Quick Setup
498
+
499
+ ```js
500
+ // tailwind.config.js
501
+ const { flexiUIPlugin } = require('@flexireact/flexi-ui/tailwind');
502
+
503
+ module.exports = {
504
+ darkMode: 'class',
505
+ content: [
506
+ './pages/**/*.{js,ts,jsx,tsx}',
507
+ './node_modules/@flexireact/flexi-ui/dist/**/*.js',
508
+ ],
509
+ plugins: [flexiUIPlugin],
510
+ };
511
+ ```
512
+
513
+ ### Usage
514
+
515
+ ```jsx
516
+ import { Button, Card, Badge, Input } from '@flexireact/flexi-ui';
517
+
518
+ export default function MyPage() {
519
+ return (
520
+ <Card>
521
+ <Badge variant="success">New</Badge>
522
+ <h2>Welcome!</h2>
523
+ <Input placeholder="Enter your email" />
524
+ <Button>Get Started</Button>
525
+ </Card>
526
+ );
527
+ }
528
+ ```
529
+
530
+ ### Available Components
531
+ - **Core**: Button, Input, Textarea, Checkbox, Switch, Select
532
+ - **Display**: Card, Badge, Avatar, Tooltip
533
+ - **Feedback**: Alert, Toast, Spinner, Skeleton, Progress
534
+ - **Overlay**: Modal, Drawer, Dropdown
535
+ - **Layout**: Separator, Tabs
536
+
537
+ 📖 [FlexiUI Documentation](https://github.com/flexireact/flexi-ui)
538
+
539
+ ---
540
+
541
+ ## 📋 Requirements
542
+
543
+ - Node.js 18+
544
+ - React 18+
545
+
546
+ ## 📄 License
547
+
548
+ MIT
549
+