@flexireact/core 4.0.0 → 4.1.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,496 +1,80 @@
1
- <p align="center">
2
- <img src="./assets/flexireact.webp" alt="FlexiReact Logo" width="400" />
3
- </p>
4
-
5
- <h1 align="center">⚡ FlexiReact v4</h1>
6
-
7
- <p align="center">
8
- <strong>The Future of React Development</strong>
9
- </p>
10
-
11
- <p align="center">
12
- The Modern React Framework - Better than Next.js with TypeScript, Tailwind CSS, SSR, SSG, Islands, Edge Runtime, and 50+ UI components.<br/>
13
- <b>Better than Next.js.</b> Simpler. Faster. More powerful.
14
- </p>
15
-
16
- <p align="center">
17
- <a href="https://www.npmjs.com/package/@flexireact/core"><img src="https://img.shields.io/npm/v/@flexireact/core.svg?color=00FF9C" alt="npm version" /></a>
18
- <a href="https://www.npmjs.com/package/@flexireact/core"><img src="https://img.shields.io/npm/dm/@flexireact/core.svg?color=00FF9C" alt="npm downloads" /></a>
19
- <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-00FF9C.svg" alt="License: MIT" /></a>
20
- <a href="#"><img src="https://img.shields.io/badge/TypeScript-Native-blue.svg" alt="TypeScript Native" /></a>
21
- </p>
22
-
23
- <p align="center">
24
- <a href="#-quick-start">Quick Start</a> •
25
- <a href="#-features">Features</a> •
26
- <a href="#-cli-commands">CLI</a> •
27
- <a href="#-flexi-ui">FlexiUI</a> •
28
- <a href="#-devtools">DevTools</a>
29
- </p>
1
+ <div align="center">
30
2
 
31
- ---
32
-
33
- ## 🚀 Quick Start
34
-
35
- ```bash
36
- # Create a new project
37
- npx create-flexireact my-app
38
-
39
- # Or with a specific template
40
- npx create-flexireact my-app --template app-router
41
-
42
- # Start development
43
- cd my-app
44
- npm run dev
45
- ```
46
-
47
- Open [http://localhost:3000](http://localhost:3000) 🎉
48
-
49
- ---
50
-
51
- ## 🆕 What's New in v4
52
-
53
- ### v4.0.0 — React 19 Native Edition
54
- - **⚛️ React 19 Native** — Full support for React 19 (Actions, `useActionState`, `useOptimistic`, `useFormStatus`, `use()`)
55
- - **🚀 Enhanced Actions** — Simplified server action handling with native React 19 primitives
56
- - **🔄 Improved Hydration** — Leveraging React 19 `onRecoverableError` for better error resilience
57
- - **📦 New Hooks API** — Centralized `core/hooks` module for React 19 + FlexiReact utilities
58
- - **⚡ Version 4.0** — Major release with stability improvements and updated CLI templates
59
-
60
- ## ✨ Features
61
-
62
- ### 🏗️ Core Framework
63
-
64
- | Feature | Description |
65
- |---------|-------------|
66
- | 📘 **TypeScript First** | Full TypeScript support with strict type checking and excellent DX |
67
- | ⚡ **Lightning Fast** | Powered by esbuild for instant builds and sub-second HMR |
68
- | 📁 **File-based Routing** | Create a file in `pages/`, get a route automatically |
69
- | 🏝️ **Islands Architecture** | Partial hydration for minimal JavaScript and maximum performance |
70
- | 🖥️ **SSR / SSG / ISR** | Server-side rendering, static generation, and incremental regeneration |
71
- | 🔌 **API Routes** | Build your REST/GraphQL API alongside your frontend |
72
-
73
- ### 🧩 Layouts & Components
74
-
75
- | Feature | Description |
76
- |---------|-------------|
77
- | 📐 **Nested Layouts** | Shared layouts with `_layout.tsx` that persist across navigation |
78
- | 🎭 **Server Components** | `'use server'` directive for server-only components (zero JS) |
79
- | 💻 **Client Components** | `'use client'` directive for interactive client-side components |
80
- | 🎨 **Tailwind CSS** | Pre-configured with beautiful defaults, dark mode, and CSS variables |
81
- | 🧱 **UI Components** | Button, Card, Modal, Tooltip, Drawer, Table, Input, Skeleton... |
82
- | ✨ **shadcn/ui Ready** | Compatible component system with CVA variants |
83
-
84
- ### 📊 Data Fetching & State
85
-
86
- | Feature | Description |
87
- |---------|-------------|
88
- | 🔄 **getServerSideProps** | Fetch data on every request (SSR) |
89
- | 📦 **getStaticProps** | Fetch data at build time (SSG) |
90
- | 🚀 **Prefetch** | Automatic link prefetching for instant navigation |
91
- | 🔍 **TanStack Query** | Built-in support for useQuery, useMutation, and caching |
92
- | 🐻 **Zustand / Jotai** | Lightweight state management integration |
93
- | ⚡ **Optimistic Updates** | Instant UI feedback with `useOptimistic` (React 19) |
94
- | ⏳ **Suspense Ready** | React Suspense and `use()` hook for async data |
95
- | 🏗️ **Actions State** | Native `useActionState` and `useFormStatus` support |
96
-
97
- ### 🛡️ Middleware & Security
98
-
99
- | Feature | Description |
100
- |---------|-------------|
101
- | � **Middleware System** | Run code before every request (auth, logging, redirects) |
102
- | 🔐 **Authentication** | Email/password + OAuth (Google, GitHub, Discord) |
103
- | 👥 **RBAC** | Role-based access control with permissions |
104
- | 🛡️ **Security** | Built-in CSRF, XSS, CORS protection |
105
- | ⏱️ **Rate Limiting** | Protect your API from abuse |
106
- | 📝 **Request Logging** | Structured logging with levels and formatting |
3
+ <img src="./assets/flexireact.webp" alt="FlexiReact Logo" width="280" />
107
4
 
108
- ### 🚀 Performance & Build
5
+ # FlexiReact v4.1
109
6
 
110
- | Feature | Description |
111
- |---------|-------------|
112
- | 📦 **Code Splitting** | Automatic route-based code splitting |
113
- | 🦥 **Lazy Loading** | Dynamic imports with `React.lazy()` support |
114
- | 🌳 **Tree Shaking** | Dead code elimination for minimal bundles |
115
- | 📊 **Bundle Analysis** | Visualize your bundle size with built-in analyzer |
116
- | �️ **Compression** | Gzip/Brotli compression out of the box |
117
- | 🖼️ **Image Optimization** | Automatic image resizing, WebP conversion, lazy loading |
7
+ ### The Edge-First React Framework
118
8
 
119
- ### 🔧 Developer Experience
9
+ [![npm version](https://img.shields.io/npm/v/@flexireact/core.svg?style=flat-square&color=00FF9C&labelColor=0a0a0a)](https://www.npmjs.com/package/@flexireact/core)
10
+ [![npm downloads](https://img.shields.io/npm/dm/@flexireact/core.svg?style=flat-square&color=00FF9C&labelColor=0a0a0a)](https://www.npmjs.com/package/@flexireact/core)
11
+ [![License](https://img.shields.io/badge/license-MIT-00FF9C.svg?style=flat-square&labelColor=0a0a0a)](https://opensource.org/licenses/MIT)
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-native-3178c6.svg?style=flat-square&labelColor=0a0a0a)](https://www.typescriptlang.org/)
120
13
 
121
- | Feature | Description |
122
- |---------|-------------|
123
- | 🔥 **Hot Reloading** | Instant updates without losing state |
124
- | 🐛 **Error Overlay** | Beautiful error messages with stack traces |
125
- | � **ESLint + Prettier** | Pre-configured linting and formatting |
126
- | 🎨 **Tailwind IntelliSense** | Full autocomplete for Tailwind classes |
127
- | 📋 **Multiple Templates** | Starter templates: minimal, blog, dashboard, e-commerce |
128
- | 🩺 **Doctor Command** | `flexi doctor` to diagnose project issues |
14
+ A modern React framework focused on **performance**, **clarity** and **modern React APIs**.
15
+ Inspired by Next.js, Remix and Astro — but simpler, lighter and edge-native.
129
16
 
130
- ### 🔍 SEO & Analytics
17
+ [Quick Start](#-quick-start) · [Features](#-features) · [Documentation](#-documentation) · [Roadmap](#-roadmap)
131
18
 
132
- | Feature | Description |
133
- |---------|-------------|
134
- | 🏷️ **Auto Meta Tags** | Automatic title, description, and canonical URLs |
135
- | 📱 **Open Graph** | Social media preview cards (Twitter, Facebook, LinkedIn) |
136
- | 🗺️ **Sitemap** | Auto-generated sitemap.xml for search engines |
137
- | 📈 **Performance Monitoring** | Core Web Vitals tracking built-in |
138
- | � **robots.txt** | Configurable robots.txt generation |
139
- | 📊 **Analytics Ready** | Easy integration with Google Analytics, Plausible, etc. |
140
-
141
- ### 🔌 Extensibility
142
-
143
- | Feature | Description |
144
- |---------|-------------|
145
- | 🧩 **Plugin System** | Extend FlexiReact with community plugins |
146
- | 🎣 **Lifecycle Hooks** | `beforeRender`, `afterRender`, `onError` hooks |
147
- | 📦 **Custom Templates** | Create and share your own project templates |
148
- | 🔄 **Migration Tools** | Automatic migration from Next.js, CRA, Vite |
149
- | ⚙️ **Config API** | Fully customizable `@flexireact/core.config.ts` |
150
-
151
- ---
152
-
153
- ## 🆚 Why FlexiReact?
154
-
155
- | | FlexiReact v3 | Next.js 15 | Remix | Astro |
156
- |---|:---:|:---:|:---:|:---:|
157
- | **Zero Config** | ✅ | ⚠️ | ⚠️ | ✅ |
158
- | **Edge Runtime** | ✅ | ✅ | ⚠️ | ⚠️ |
159
- | **Islands Architecture** | ✅ | ❌ | ❌ | ✅ |
160
- | **UI Components** | ✅ 50+ | ❌ | ❌ | ❌ |
161
- | **CLI Scaffolding** | ✅ | ❌ | ❌ | ❌ |
162
- | **DevTools** | ✅ | ⚠️ | ⚠️ | ⚠️ |
163
- | **PPR** | ✅ | ✅ | ❌ | ❌ |
164
- | **Bundle Size** | 🟢 ~90kb | � ~250kb | 🟡 ~150kb | 🟢 ~50kb |
165
- | **Build Speed** | 🟢 <1s | 🟡 ~5s | 🟡 ~3s | 🟢 <2s |
19
+ </div>
166
20
 
167
21
  ---
168
22
 
169
- ## 🖥️ CLI Commands
170
-
171
- ```bash
172
- # Project
173
- flexi create <name> # Create new project
174
- flexi dev # Start dev server (HMR)
175
- flexi build # Build for production
176
- flexi build --analyze # Build with bundle analysis
177
- flexi start # Start production server
178
- flexi doctor # Check project health
179
-
180
- # Scaffolding (NEW in v3!)
181
- flexi g page dashboard # Generate a page
182
- flexi g component Button # Generate a component
183
- flexi g hook useAuth # Generate a custom hook
184
- flexi g api users # Generate an API route
185
- flexi g action submit # Generate a server action
186
- flexi g context theme # Generate a React context
187
- flexi g middleware auth # Generate middleware
188
- flexi g loading # Generate loading.tsx
189
- flexi g error # Generate error.tsx
190
- ```
191
-
192
- ---
193
-
194
- ## 🎨 FlexiUI — 50+ Components
195
-
196
- FlexiReact includes [@flexireact/flexi-ui](https://www.npmjs.com/package/@flexireact/flexi-ui), a complete UI library:
23
+ ## 🚀 Quick Start
197
24
 
198
25
  ```bash
199
- npm install @flexireact/flexi-ui
200
- ```
201
-
202
- ```tsx
203
- import { Button, Card, Input, Modal, Toast } from '@flexireact/flexi-ui';
204
- ```
205
-
206
- ### Available Components
207
-
208
- | Category | Components |
209
- |----------|------------|
210
- | **Form** | Button, Input, Textarea, Checkbox, Switch, Select, Slider, Radio, Toggle, Rating, DatePicker, FileUpload |
211
- | **Layout** | Stack, Separator, AspectRatio, ScrollArea, Resizable |
212
- | **Navigation** | Tabs, Breadcrumb, Pagination, Menubar, Navbar, Sidebar, Stepper |
213
- | **Data** | Card, Badge, Avatar, Table, Accordion, Calendar, Timeline, Stat, Code, Carousel |
214
- | **Feedback** | Alert, Toast, Spinner, Skeleton, Progress, Empty |
215
- | **Overlay** | Modal, Dialog, Drawer, Sheet, Dropdown, Popover, HoverCard, ContextMenu, Command, Collapsible |
216
-
217
- ---
218
-
219
- ## 🔧 DevTools
220
-
221
- Built-in development tools (press `Ctrl+Shift+D`):
222
-
223
- ```tsx
224
- import { DevToolsOverlay } from '@flexireact/core';
225
-
226
- // In your layout
227
- {process.env.NODE_ENV === 'development' && <DevToolsOverlay />}
26
+ npx create-flexireact my-app
27
+ cd my-app
28
+ npm run dev
228
29
  ```
229
30
 
230
- Features:
231
- - 🗺️ **Routes** — Navigation history and params
232
- - 🧩 **Components** — Render counts, props, Islands detection
233
- - 🌐 **Network** — Fetch/XHR/Actions monitoring
234
- - 📊 **Performance** — Core Web Vitals (LCP, FID, CLS, TTFB)
235
- - 📝 **Console** — Centralized logs
31
+ Open [http://localhost:3000](http://localhost:3000) and start building! 🎉
236
32
 
237
33
  ---
238
34
 
239
- ## 🌐 Edge Runtime
240
-
241
- Deploy anywhere with universal edge support:
242
-
243
- ```tsx
244
- import { createEdgeHandler, detectRuntime } from '@flexireact/core';
245
-
246
- // Automatic runtime detection
247
- const runtime = detectRuntime();
248
- // → 'node' | 'bun' | 'deno' | 'cloudflare' | 'vercel-edge' | 'netlify-edge'
35
+ ## Why FlexiReact?
249
36
 
250
- // Universal handler
251
- const handler = createEdgeHandler({
252
- routes: [...],
253
- middleware: [...],
254
- });
255
-
256
- export default handler;
257
- ```
258
-
259
- ---
260
-
261
- ## ⚡ Smart Caching
262
-
263
- ```tsx
264
- import { smartCache } from '@flexireact/core';
37
+ FlexiReact is for developers who want:
265
38
 
266
- const cache = smartCache({
267
- backend: 'auto', // auto-detect: memory, KV, Redis
268
- defaultTTL: 60,
269
- staleWhileRevalidate: true,
270
- });
271
-
272
- // Cache with tags
273
- await cache.set('user:123', userData, {
274
- ttl: 300,
275
- tags: ['users']
276
- });
277
-
278
- // Invalidate by tag
279
- await cache.invalidateTag('users');
280
- ```
281
-
282
- ---
283
-
284
- ## 🎯 Partial Prerendering (PPR)
285
-
286
- Static shell + streaming dynamic content:
287
-
288
- ```tsx
289
- import { withPPR, DynamicBoundary } from '@flexireact/core';
290
-
291
- export default withPPR(function Page() {
292
- return (
293
- <div>
294
- {/* Static - rendered at build time */}
295
- <Header />
296
- <Sidebar />
297
-
298
- {/* Dynamic - streamed at request time */}
299
- <DynamicBoundary fallback={<Skeleton />}>
300
- <UserDashboard />
301
- </DynamicBoundary>
302
- </div>
303
- );
304
- });
305
- ```
39
+ | Feature | Description |
40
+ |---------|-------------|
41
+ | ⚛️ **Modern React** | React 19, Server Components, Server Actions, Suspense |
42
+ | 🏝️ **Islands** | Partial hydration — zero JS for static content |
43
+ | ⚡ **Edge-First** | Runs on Node, Bun, Deno, Cloudflare Workers |
44
+ | 📁 **File Routing** | Three conventions: `routes/`, `app/`, `pages/` |
45
+ | 🎯 **Explicit** | No hidden caching, no magic behavior |
306
46
 
307
47
  ---
308
48
 
309
- ## 📁 Project Structure
310
-
311
- FlexiReact v2 introduces a new `routes/` directory with enhanced routing capabilities:
312
-
313
- ```
314
- myapp/
315
- ├── app/ # App directory (layout, components, styles)
316
- │ ├── components/
317
- │ │ ├── ui/ # UI components (Button, Card, etc.)
318
- │ │ └── layout/ # Layout components (Navbar, Footer)
319
- │ ├── styles/
320
- │ │ └── globals.css # Global styles + Tailwind v4
321
- │ ├── providers/ # React context providers
322
- │ └── layout.tsx # Root layout
323
- ├── routes/ # FlexiReact v3 file-based routing
324
- │ ├── (public)/ # Route groups (don't affect URL)
325
- │ │ ├── home.tsx # → /
326
- │ │ └── about.tsx # → /about
327
- │ ├── blog/
328
- │ │ ├── index.tsx # → /blog
329
- │ │ └── [slug].tsx # → /blog/:slug
330
- │ └── api/
331
- │ └── hello.ts # → /api/hello
332
- ├── lib/ # Utilities
333
- │ └── utils.ts
334
- ├── public/ # Static assets
335
- ├── tsconfig.json # TypeScript configuration
336
- ├── flexireact.config.ts # FlexiReact configuration
337
- └── package.json
338
- ```
339
-
340
- ## 🛣️ Routing (v2)
341
-
342
- FlexiReact v2 supports three routing conventions (in priority order):
343
-
344
- ### 1. Routes Directory (Recommended)
345
-
346
- | File | Route |
347
- |------|-------|
348
- | `routes/(public)/home.tsx` | `/` |
349
- | `routes/(public)/about.tsx` | `/about` |
350
- | `routes/blog/index.tsx` | `/blog` |
351
- | `routes/blog/[slug].tsx` | `/blog/:slug` |
352
- | `routes/[...path].tsx` | Catch-all route |
353
- | `routes/api/hello.ts` | `/api/hello` |
354
-
355
- ### 2. App Directory (Next.js style)
356
-
357
- | File | Route |
358
- |------|-------|
359
- | `app/page.tsx` | `/` |
360
- | `app/about/page.tsx` | `/about` |
361
- | `app/blog/[slug]/page.tsx` | `/blog/:slug` |
362
-
363
- ### 3. Pages Directory (Legacy)
364
-
365
- | File | Route |
366
- |------|-------|
367
- | `pages/index.tsx` | `/` |
368
- | `pages/about.tsx` | `/about` |
369
-
370
- ### Dynamic Routes
371
-
372
- ```tsx
373
- // routes/blog/[slug].tsx
374
- export default function BlogPost({ params }: { params: { slug: string } }) {
375
- return <h1>Post: {params.slug}</h1>;
376
- }
377
- ```
378
-
379
- ### Route Groups
380
-
381
- Use parentheses to group routes without affecting the URL:
382
-
383
- ```
384
- routes/
385
- (public)/
386
- home.tsx # → /
387
- about.tsx # → /about
388
- (dashboard)/
389
- settings.tsx # → /settings
390
- ```
391
-
392
- ## 📐 Layouts
49
+ ## 🧩 Features
393
50
 
394
- Create layouts in `app/layout.tsx` or within route directories:
51
+ ### ⚛️ React 19 Native
395
52
 
396
53
  ```tsx
397
- // app/layout.tsx
398
- import { Navbar } from './components/layout/Navbar';
399
- import { Footer } from './components/layout/Footer';
400
-
401
- export default function RootLayout({ children }: { children: React.ReactNode }) {
402
- return (
403
- <html lang="en" className="dark">
404
- <head>
405
- <link rel="stylesheet" href="/styles.css" />
406
- </head>
407
- <body className="bg-background text-foreground">
408
- <Navbar />
409
- <main>{children}</main>
410
- <Footer />
411
- </body>
412
- </html>
413
- );
54
+ // Server Component (default)
55
+ export default async function Page() {
56
+ const data = await db.query('SELECT * FROM posts');
57
+ return <PostList posts={data} />;
414
58
  }
415
59
  ```
416
60
 
417
- ## ⏳ Loading & Error States
418
-
419
61
  ```tsx
420
- // routes/loading.tsx
421
- export default function Loading() {
422
- return (
423
- <div className="flex items-center justify-center min-h-screen">
424
- <div className="w-8 h-8 border-2 border-primary border-t-transparent rounded-full animate-spin" />
425
- </div>
426
- );
427
- }
428
-
429
- // routes/error.tsx
430
- export default function Error({ error, reset }: { error: Error; reset: () => void }) {
431
- return (
432
- <div className="flex flex-col items-center justify-center min-h-screen">
433
- <h1 className="text-4xl font-bold text-red-500">Something went wrong</h1>
434
- <p className="text-gray-400 mt-4">{error.message}</p>
435
- <button onClick={reset} className="mt-8 px-6 py-3 bg-primary text-black rounded-lg">
436
- Try again
437
- </button>
438
- </div>
439
- );
440
- }
441
- ```
442
-
443
- ## 🔄 Data Fetching
444
-
445
- ### Server-Side Rendering (SSR)
446
-
447
- ```jsx
448
- export async function getServerSideProps({ params, req }) {
449
- const data = await fetchData(params.id);
450
-
451
- if (!data) {
452
- return { notFound: true };
453
- }
454
-
455
- return { props: { data } };
456
- }
457
-
458
- export default function Page({ data }) {
459
- return <div>{data.title}</div>;
460
- }
461
- ```
462
-
463
- ### Static Site Generation (SSG)
464
-
465
- ```jsx
466
- // For dynamic routes
467
- export async function getStaticPaths() {
468
- return {
469
- paths: [
470
- { params: { slug: 'hello' } },
471
- { params: { slug: 'world' } }
472
- ],
473
- fallback: false
474
- };
475
- }
476
-
477
- export async function getStaticProps({ params }) {
478
- const post = await getPost(params.slug);
479
- return { props: { post } };
62
+ 'use client';
63
+ // Client Component
64
+ export function LikeButton() {
65
+ const [liked, setLiked] = useState(false);
66
+ return <button onClick={() => setLiked(!liked)}>❤️</button>;
480
67
  }
481
68
  ```
482
69
 
483
- ## 🏝️ Islands Architecture
70
+ ### 🏝️ Islands Architecture
484
71
 
485
- Islands allow partial hydration — only interactive components load JavaScript:
72
+ Only hydrate what needs interactivity:
486
73
 
487
- ```jsx
74
+ ```tsx
488
75
  'use island';
489
76
 
490
- import { useState } from 'react';
491
-
492
- // This component will be hydrated on the client
493
- export default function Counter() {
77
+ export function Counter() {
494
78
  const [count, setCount] = useState(0);
495
79
  return (
496
80
  <button onClick={() => setCount(c => c + 1)}>
@@ -500,390 +84,183 @@ export default function Counter() {
500
84
  }
501
85
  ```
502
86
 
503
- Static content around islands remains as pure HTML with zero JavaScript.
504
-
505
- ## 🖥️ React Server Components
87
+ ### 📁 File-Based Routing
506
88
 
507
- Mark components to run only on the server:
508
-
509
- ```jsx
510
- 'use server';
511
-
512
- // This component never ships to the client
513
- export default async function ServerData() {
514
- const data = await db.query('SELECT * FROM users');
515
- return <UserList users={data} />;
516
- }
517
89
  ```
518
-
519
- Mark client components explicitly:
520
-
521
- ```jsx
522
- 'use client';
523
-
524
- // This component will be hydrated
525
- export default function InteractiveWidget() {
526
- // Client-side interactivity here
527
- }
90
+ routes/
91
+ ├── home.tsx → /
92
+ ├── about.tsx → /about
93
+ ├── blog/
94
+ │ ├── index.tsx → /blog
95
+ │ └── [slug].tsx → /blog/:slug
96
+ └── api/
97
+ └── users.ts → /api/users
528
98
  ```
529
99
 
530
- ## 🔌 API Routes
531
-
532
- ```js
533
- // pages/api/users.js
100
+ ### 🔌 API Routes
534
101
 
535
- export function get(req, res) {
536
- res.json({ users: [] });
102
+ ```ts
103
+ // routes/api/users.ts
104
+ export async function GET() {
105
+ return Response.json({ users: await getUsers() });
537
106
  }
538
107
 
539
- export function post(req, res) {
540
- const { name } = req.body;
541
- res.status(201).json({ id: 1, name });
108
+ export async function POST(req: Request) {
109
+ const body = await req.json();
110
+ return Response.json({ created: true });
542
111
  }
543
112
  ```
544
113
 
545
- ## Server Actions (v2.2+)
546
-
547
- Call server functions directly from client components:
114
+ ### 🛡️ Middleware
548
115
 
549
- ```tsx
550
- // actions.ts
551
- 'use server';
552
- import { serverAction, redirect, cookies } from '@flexireact/core';
553
-
554
- export const createUser = serverAction(async (formData: FormData) => {
555
- const name = formData.get('name') as string;
556
- const user = await db.users.create({ name });
557
-
558
- // Set a cookie
559
- cookies.set('userId', user.id);
560
-
561
- // Redirect after action
562
- redirect('/users');
563
- });
564
-
565
- // Form.tsx
566
- 'use client';
567
- import { createUser } from './actions';
568
-
569
- export function CreateUserForm() {
570
- return (
571
- <form action={createUser}>
572
- <input name="name" placeholder="Name" required />
573
- <button type="submit">Create User</button>
574
- </form>
575
- );
116
+ ```ts
117
+ // middleware.ts
118
+ export default function middleware(request) {
119
+ if (!request.headers.get('authorization')) {
120
+ return Response.redirect('/login');
121
+ }
576
122
  }
577
- ```
578
-
579
- ## 🔗 Link with Prefetching (v2.1+)
580
-
581
- Enhanced Link component with automatic prefetching:
582
-
583
- ```tsx
584
- import { Link } from '@flexireact/core/client';
585
-
586
- // Prefetch on hover (default)
587
- <Link href="/about">About</Link>
588
123
 
589
- // Prefetch when visible in viewport
590
- <Link href="/products" prefetch="viewport">Products</Link>
591
-
592
- // Replace history instead of push
593
- <Link href="/login" replace>Login</Link>
594
-
595
- // Programmatic navigation
596
- import { useRouter } from '@flexireact/core/client';
597
-
598
- function MyComponent() {
599
- const router = useRouter();
600
-
601
- return (
602
- <button onClick={() => router.push('/dashboard')}>
603
- Go to Dashboard
604
- </button>
605
- );
606
- }
124
+ export const config = {
125
+ matcher: ['/dashboard/:path*']
126
+ };
607
127
  ```
608
128
 
609
- ## 🛠️ Server Helpers (v2.1+)
610
-
611
- Utility functions for server-side operations:
612
-
613
- ```tsx
614
- import { redirect, notFound, json, cookies, headers } from '@flexireact/core';
615
-
616
- // Redirect
617
- redirect('/dashboard');
618
- redirect('/login', 'permanent'); // 308 redirect
129
+ ---
619
130
 
620
- // Not Found
621
- notFound(); // Throws 404
131
+ ## 🖥️ Rendering Modes
622
132
 
623
- // JSON Response (in API routes)
624
- return json({ data: 'hello' }, { status: 200 });
133
+ | Mode | Description |
134
+ |------|-------------|
135
+ | **SSR** | Server-side rendering (default) |
136
+ | **SSG** | Static generation at build time |
137
+ | **ISR** | Incremental Static Regeneration |
138
+ | **Streaming** | Progressive HTML rendering |
625
139
 
626
- // Cookies
627
- const token = cookies.get(request, 'token');
628
- const setCookie = cookies.set('session', 'abc123', {
629
- httpOnly: true,
630
- maxAge: 86400
631
- });
140
+ ```tsx
141
+ // Enable ISR with revalidation
142
+ export const revalidate = 60; // seconds
632
143
 
633
- // Headers
634
- const auth = headers.bearerToken(request);
635
- const corsHeaders = headers.cors({ origin: '*' });
636
- const securityHeaders = headers.security();
144
+ export default function Page() {
145
+ return <div>This page revalidates every 60s</div>;
146
+ }
637
147
  ```
638
148
 
639
- ## 🛡️ Middleware
149
+ ---
640
150
 
641
- ### Global Middleware
151
+ ## 🛠️ CLI
642
152
 
643
- Create `middleware.ts` in your project root:
153
+ ```bash
154
+ # Create & Run
155
+ npx create-flexireact my-app # Create new project
156
+ flexi dev # Development server
157
+ flexi build # Production build
158
+ flexi start # Start production server
644
159
 
645
- ```ts
646
- import { redirect, cookies } from '@flexireact/core';
160
+ # Scaffolding
161
+ flexi g page dashboard # Generate page
162
+ flexi g component Button # Generate component
163
+ flexi g api users # Generate API route
647
164
 
648
- export default function middleware(request) {
649
- // Protect routes
650
- if (request.pathname.startsWith('/admin')) {
651
- const token = cookies.get(request, 'token');
652
- if (!token) {
653
- redirect('/login');
654
- }
655
- }
656
- }
657
-
658
- export const config = {
659
- matcher: ['/admin/:path*', '/api/:path*']
660
- };
165
+ # Utilities
166
+ flexi doctor # Diagnose issues
167
+ flexi upgrade # Upgrade FlexiReact
661
168
  ```
662
169
 
663
- ### Route Middleware (v2.1+)
170
+ ---
664
171
 
665
- Create `_middleware.ts` in any route directory:
172
+ ## ⚙️ Configuration
666
173
 
667
- ```
668
- routes/
669
- admin/
670
- _middleware.ts # Runs for all /admin/* routes
671
- dashboard.tsx
672
- settings.tsx
673
- ```
174
+ Create a `flexireact.config.ts` in your project root:
674
175
 
675
176
  ```ts
676
- // routes/admin/_middleware.ts
677
- export default async function middleware(req, res, { route, params }) {
678
- const user = await getUser(req);
679
-
680
- if (!user?.isAdmin) {
681
- return { redirect: '/login' };
682
- }
683
-
684
- // Continue to route
685
- return { user };
686
- }
687
- ```
177
+ // flexireact.config.ts
178
+ import { defineConfig } from '@flexireact/core/config';
688
179
 
689
- ## 🔧 Configuration
180
+ export default defineConfig({
181
+ // Directories
182
+ pagesDir: 'pages',
183
+ layoutsDir: 'layouts',
184
+ publicDir: 'public',
185
+ outDir: '.flexi',
690
186
 
691
- Create `flexireact.config.js`:
692
-
693
- ```js
694
- export default {
187
+ // Server
695
188
  server: {
696
189
  port: 3000,
697
190
  host: 'localhost'
698
191
  },
699
-
192
+
193
+ // Build
700
194
  build: {
701
195
  target: 'es2022',
702
196
  minify: true,
703
197
  sourcemap: true
704
198
  },
705
-
199
+
200
+ // Features
706
201
  islands: {
707
202
  enabled: true
708
203
  },
709
-
710
204
  rsc: {
711
205
  enabled: true
712
206
  },
713
-
714
207
  ssg: {
715
208
  enabled: false,
716
209
  paths: []
717
- },
718
-
719
- plugins: []
720
- };
721
- ```
722
-
723
- ## 🧩 Plugins
724
-
725
- Create `flexireact.plugin.js`:
726
-
727
- ```js
728
- export default {
729
- name: 'my-plugin',
730
-
731
- onServerStart(server) {
732
- console.log('Server started!');
733
- },
734
-
735
- onBeforeRender(page, props) {
736
- return { ...props, injected: true };
737
- },
738
-
739
- onAfterRender(html) {
740
- return html.replace('</head>', '<script>...</script></head>');
741
210
  }
742
- };
743
- ```
744
-
745
- ### Built-in Plugins
746
-
747
- ```js
748
- import { builtinPlugins } from '@flexireact/core';
749
-
750
- export default {
751
- plugins: [
752
- builtinPlugins.analytics({ trackingId: 'UA-XXX' }),
753
- builtinPlugins.pwa({ manifest: '/manifest.json' }),
754
- builtinPlugins.securityHeaders()
755
- ]
756
- };
757
- ```
758
-
759
- ## 🖥️ CLI Commands
760
-
761
- ```bash
762
- flexi create <name> # Create new project
763
- flexi dev # Start dev server
764
- flexi build # Build for production
765
- flexi build --analyze # Build with bundle analysis
766
- flexi start # Start production server
767
- flexi doctor # Check project health
768
- flexi --version # Show version
769
- flexi help # Show help
770
- ```
771
-
772
- ### Bundle Analysis (v2.1+)
773
-
774
- ```bash
775
- flexi build --analyze
776
- ```
777
-
778
- Output:
779
- ```
780
- 📊 Bundle Analysis:
781
-
782
- ─────────────────────────────────────────────────
783
- File Size
784
- ─────────────────────────────────────────────────
785
- client/main.js 45.2 KB (13.56 KB gzip)
786
- client/vendor.js 120.5 KB (38.2 KB gzip)
787
- server/pages.js 12.3 KB
788
- ─────────────────────────────────────────────────
789
- Total: 178 KB
790
- Gzipped: 51.76 KB
791
- ```
792
-
793
- ## 🌊 Streaming SSR (v2.2+)
794
-
795
- Progressive HTML rendering with React 18:
796
-
797
- ```tsx
798
- import { renderPageStream, streamToResponse } from '@flexireact/core';
799
-
800
- // In your server handler
801
- const { stream, shellReady } = await renderPageStream({
802
- Component: MyPage,
803
- props: { data },
804
- loading: LoadingSpinner,
805
- error: ErrorBoundary,
806
- title: 'My Page',
807
- styles: ['/styles.css']
808
211
  });
809
-
810
- // Wait for shell (initial HTML) to be ready
811
- await shellReady;
812
-
813
- // Stream to response
814
- res.setHeader('Content-Type', 'text/html');
815
- streamToResponse(res, stream);
816
212
  ```
817
213
 
818
- Benefits:
819
- - **Faster Time to First Byte (TTFB)** — Send HTML as it's ready
820
- - **Progressive Loading** — Users see content immediately
821
- - **Suspense Support** — Loading states stream in as data resolves
822
- - **Better UX** — No blank screen while waiting for data
823
-
824
- ## 📚 Concepts Explained
214
+ Configuration is validated with Zod. Invalid options will show clear error messages.
825
215
 
826
- ### React Server Components (RSC)
827
-
828
- RSC allows components to execute exclusively on the server:
829
- - **Zero client JavaScript** for server components
830
- - **Direct database/filesystem access** in components
831
- - **Smaller bundles** — server code never ships to client
832
- - **Better security** — sensitive logic stays on server
833
-
834
- ### Static Site Generation (SSG)
835
-
836
- SSG pre-renders pages at build time:
837
- - **Fastest possible loads** — pages are static HTML
838
- - **CDN cacheable** — serve from edge locations
839
- - **SEO friendly** — full HTML for crawlers
840
- - **Incremental regeneration** — update without full rebuild
216
+ ---
841
217
 
842
- ### Islands Architecture
218
+ ## 📦 Packages
843
219
 
844
- Islands provide partial hydration:
845
- - **Minimal JavaScript** — only interactive parts hydrate
846
- - **Progressive enhancement** works without JS
847
- - **Better performance** less code to parse/execute
848
- - **Selective loading** hydrate on visibility, interaction, etc.
220
+ | Package | Description |
221
+ |---------|-------------|
222
+ | [`@flexireact/core`](https://www.npmjs.com/package/@flexireact/core) | Core framework |
223
+ | [`create-flexireact`](https://www.npmjs.com/package/create-flexireact) | Project scaffolding CLI |
224
+ | `@flexireact/flexi-ui` | UI component library (coming soon) |
849
225
 
850
226
  ---
851
227
 
852
- ## 📋 Requirements
228
+ ## 🛣️ Roadmap
853
229
 
854
- - Node.js 18+
855
- - React 18+
856
-
857
- ## 📦 Packages
230
+ ### v4.x (Current)
231
+ - [x] React 19 support
232
+ - [x] Islands architecture
233
+ - [x] File-based routing (3 conventions)
234
+ - [x] SSR / SSG / ISR
235
+ - [x] Middleware system
236
+ - [ ] Plugin system v1
237
+ - [ ] Image optimization
858
238
 
859
- | Package | Version | Description |
860
- |---------|---------|-------------|
861
- | [flexireact](https://www.npmjs.com/package/flexireact) | ![npm](https://img.shields.io/npm/v/@flexireact/core?color=00FF9C) | Core framework |
862
- | [@flexireact/flexi-ui](https://www.npmjs.com/package/@flexireact/flexi-ui) | ![npm](https://img.shields.io/npm/v/@flexireact/flexi-ui?color=00FF9C) | UI components |
863
- | [create-flexireact](https://www.npmjs.com/package/create-flexireact) | ![npm](https://img.shields.io/npm/v/create-flexireact?color=00FF9C) | Project scaffolding |
239
+ ### v5 (Future)
240
+ - [ ] Unified compiler pipeline
241
+ - [ ] First-class plugin ecosystem
242
+ - [ ] Advanced DevTools
243
+ - [ ] Partial Prerendering (PPR)
864
244
 
865
- ## 🔗 Links
245
+ ---
866
246
 
867
- - [GitHub Repository](https://github.com/flexireact/flexireact)
868
- - [FlexiUI Repository](https://github.com/flexireact/flexi-ui)
869
- - [npm Package](https://www.npmjs.com/package/@flexireact/core)
870
- - [Discord Community](https://discord.gg/rFSZxFtpAA) 💬
871
- - [Issues](https://github.com/flexireact/flexireact/issues)
247
+ ## 🤝 Contributing
872
248
 
873
- ## 🙏 Contributing
249
+ FlexiReact is open-source and community-driven.
250
+ Contributions, feedback and discussions are welcome!
874
251
 
875
- Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) first.
252
+ ---
876
253
 
877
254
  ## 📄 License
878
255
 
879
- MIT © [FlexiReact Team](https://github.com/flexireact)
256
+ MIT © FlexiReact Team
880
257
 
881
258
  ---
882
259
 
883
- <p align="center">
884
- <b>Built with ❤️ by the FlexiReact Team</b>
885
- </p>
260
+ <div align="center">
261
+
262
+ **Built with ❤️ for developers who value clarity and performance.**
263
+
264
+ [⬆ Back to top](#-flexireact-v41)
886
265
 
887
- <p align="center">
888
- <a href="https://github.com/flexireact/flexireact">⭐ Star us on GitHub</a>
889
- </p>
266
+ </div>