create-aziz-app 3.1.2 โ 3.1.3
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 +658 -207
- package/bin/create-aziz-app.js +302 -302
- package/package.json +1 -1
- package/template/README.md +402 -402
- package/template/_framework/api.js +219 -219
- package/template/_framework/boot.js +33 -33
- package/template/_framework/hooks.js +367 -291
- package/template/_framework/next-response.js +128 -128
- package/template/_framework/route-match.js +145 -145
- package/template/_framework/router.js +465 -259
- package/template/_framework/runtime.js +264 -264
- package/template/app/layout.js +18 -18
- package/template/app/page.js +33 -33
- package/template/docs/01-getting-started.md +151 -151
- package/template/docs/02-project-structure.md +109 -109
- package/template/docs/03-pages-and-layouts.md +140 -140
- package/template/docs/04-routing.md +120 -120
- package/template/docs/05-hooks.md +169 -169
- package/template/docs/06-api-routes.md +210 -210
- package/template/docs/07-api-client.md +151 -151
- package/template/docs/08-styling.md +94 -94
- package/template/docs/09-imports-and-modules.md +97 -97
- package/template/docs/10-database-and-models.md +154 -154
- package/template/docs/11-authentication.md +171 -171
- package/template/docs/12-production-and-deployment.md +121 -121
- package/template/docs/13-internals.md +179 -179
- package/template/docs/README.md +67 -67
- package/template/index.html +20 -20
- package/template/package.json +16 -16
- package/template/scripts/dev-server.js +493 -381
- package/template/scripts/lib/api-router.js +525 -525
- package/template/scripts/lib/js-transform.js +213 -195
- package/template/scripts/lib/module-resolver.js +132 -132
|
@@ -1,151 +1,151 @@
|
|
|
1
|
-
# 01 ยท Getting Started
|
|
2
|
-
|
|
3
|
-
From zero to a running Aziz.js app in a few minutes.
|
|
4
|
-
|
|
5
|
-
## Prerequisites
|
|
6
|
-
|
|
7
|
-
- **Node.js 18+** (20 LTS or newer recommended)
|
|
8
|
-
- **npm** (ships with Node)
|
|
9
|
-
|
|
10
|
-
Check:
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
node -v
|
|
14
|
-
npm -v
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## Create a project
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npx create-aziz-app my-app
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
The CLI walks you through a few choices:
|
|
24
|
-
|
|
25
|
-
```
|
|
26
|
-
๐ Project name (my-aziz-js-app): my-app
|
|
27
|
-
๐ Dev server port (3000):
|
|
28
|
-
Include example pages? (Y/n):
|
|
29
|
-
Include example API routes? (Y/n):
|
|
30
|
-
Include documentation? (Y/n):
|
|
31
|
-
|
|
32
|
-
๐จ CSS Framework:
|
|
33
|
-
1. None (custom CSS)
|
|
34
|
-
2. Bootstrap 5
|
|
35
|
-
3. Tailwind CSS
|
|
36
|
-
Choose (1/2/3):
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Flags (skip the prompts)
|
|
40
|
-
|
|
41
|
-
Every prompt has a flag, so CI and scripts can run non-interactively:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npx create-aziz-app my-app -y # accept all defaults
|
|
45
|
-
npx create-aziz-app shop --css tailwind # preselect CSS
|
|
46
|
-
npx create-aziz-app blog --port 4000 # change the default port
|
|
47
|
-
npx create-aziz-app min --no-examples --no-api --no-docs
|
|
48
|
-
npx create-aziz-app --help
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
| Flag | Meaning |
|
|
52
|
-
|------|---------|
|
|
53
|
-
| `-y`, `--yes` | Accept defaults, no prompts |
|
|
54
|
-
| `--port <n>` | Default dev-server port (3000) |
|
|
55
|
-
| `--css <name>` | `none` \| `bootstrap` \| `tailwind` |
|
|
56
|
-
| `--no-examples` | Skip the example `app/test` page |
|
|
57
|
-
| `--no-api` | Empty the example `api/` routes |
|
|
58
|
-
| `--no-docs` | Don't copy `docs/` |
|
|
59
|
-
|
|
60
|
-
## Install and run
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
cd my-app
|
|
64
|
-
npm install # installs @babel/standalone (used for JSX) + any deps you add
|
|
65
|
-
npm run dev
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Open **<http://localhost:3000>**. You should see the home page with a working counter.
|
|
69
|
-
|
|
70
|
-
The dev server watches your files and pushes a **live reload** to the browser whenever you save โ no manual refresh.
|
|
71
|
-
|
|
72
|
-
## npm scripts
|
|
73
|
-
|
|
74
|
-
Defined in your project's `package.json`:
|
|
75
|
-
|
|
76
|
-
```json
|
|
77
|
-
{
|
|
78
|
-
"scripts": {
|
|
79
|
-
"dev": "node scripts/dev-server.js",
|
|
80
|
-
"build": "node scripts/dev-server.js --production",
|
|
81
|
-
"start": "node scripts/dev-server.js --production",
|
|
82
|
-
"test": "node --test"
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
- `npm run dev` โ development server with live reload and no caching.
|
|
88
|
-
- `npm run build` / `npm start` โ the same server in **production mode**: no live-reload socket, cache headers enabled. (Aziz.js has no bundling step; it serves your source compiled on demand and caches by file mtime.)
|
|
89
|
-
- `npm test` โ runs any `**/*.test.js` files via Node's built-in test runner. With no tests present it exits 0.
|
|
90
|
-
|
|
91
|
-
## Your first page
|
|
92
|
-
|
|
93
|
-
Create `app/hello/page.js`:
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
// app/hello/page.js โ /hello
|
|
97
|
-
export default function Hello() {
|
|
98
|
-
const [name, setName] = useState('');
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<div style={{ padding: '40px' }}>
|
|
102
|
-
<h1>Hello ๐</h1>
|
|
103
|
-
<input
|
|
104
|
-
value={name}
|
|
105
|
-
onInput={e => setName(e.target.value)}
|
|
106
|
-
placeholder="Your name"
|
|
107
|
-
/>
|
|
108
|
-
<p>{name ? `Hi, ${name}!` : 'Type somethingโฆ'}</p>
|
|
109
|
-
</div>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Save. The browser reloads and you're at **<http://localhost:3000/hello>**.
|
|
115
|
-
|
|
116
|
-
Note: **you didn't import React or any hooks.** `useState`, `h` (the JSX factory), and the router are exposed globally by the framework. See [Hooks](./05-hooks.md).
|
|
117
|
-
|
|
118
|
-
## Your first API route
|
|
119
|
-
|
|
120
|
-
Create `api/greeting.js`:
|
|
121
|
-
|
|
122
|
-
```js
|
|
123
|
-
// api/greeting.js โ /api/greeting
|
|
124
|
-
module.exports = {
|
|
125
|
-
GET: async (request) => {
|
|
126
|
-
const name = request.query.get('name') || 'world';
|
|
127
|
-
return { hello: name };
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Visit **<http://localhost:3000/api/greeting?name=Aziz>** and you get JSON:
|
|
133
|
-
|
|
134
|
-
```json
|
|
135
|
-
{ "hello": "Aziz" }
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
Call it from a page with the global client:
|
|
139
|
-
|
|
140
|
-
```js
|
|
141
|
-
const data = await api.get('/api/greeting?name=Aziz');
|
|
142
|
-
console.log(data.hello); // "Aziz"
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
See [API Routes](./06-api-routes.md) and [API Client](./07-api-client.md).
|
|
146
|
-
|
|
147
|
-
## Next steps
|
|
148
|
-
|
|
149
|
-
1. Understand the folder layout โ [Project Structure](./02-project-structure.md)
|
|
150
|
-
2. Build real screens โ [Pages & Layouts](./03-pages-and-layouts.md)
|
|
151
|
-
3. Master routes โ [Routing](./04-routing.md)
|
|
1
|
+
# 01 ยท Getting Started
|
|
2
|
+
|
|
3
|
+
From zero to a running Aziz.js app in a few minutes.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
- **Node.js 18+** (20 LTS or newer recommended)
|
|
8
|
+
- **npm** (ships with Node)
|
|
9
|
+
|
|
10
|
+
Check:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
node -v
|
|
14
|
+
npm -v
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Create a project
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npx create-aziz-app my-app
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
The CLI walks you through a few choices:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
๐ Project name (my-aziz-js-app): my-app
|
|
27
|
+
๐ Dev server port (3000):
|
|
28
|
+
Include example pages? (Y/n):
|
|
29
|
+
Include example API routes? (Y/n):
|
|
30
|
+
Include documentation? (Y/n):
|
|
31
|
+
|
|
32
|
+
๐จ CSS Framework:
|
|
33
|
+
1. None (custom CSS)
|
|
34
|
+
2. Bootstrap 5
|
|
35
|
+
3. Tailwind CSS
|
|
36
|
+
Choose (1/2/3):
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Flags (skip the prompts)
|
|
40
|
+
|
|
41
|
+
Every prompt has a flag, so CI and scripts can run non-interactively:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx create-aziz-app my-app -y # accept all defaults
|
|
45
|
+
npx create-aziz-app shop --css tailwind # preselect CSS
|
|
46
|
+
npx create-aziz-app blog --port 4000 # change the default port
|
|
47
|
+
npx create-aziz-app min --no-examples --no-api --no-docs
|
|
48
|
+
npx create-aziz-app --help
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
| Flag | Meaning |
|
|
52
|
+
|------|---------|
|
|
53
|
+
| `-y`, `--yes` | Accept defaults, no prompts |
|
|
54
|
+
| `--port <n>` | Default dev-server port (3000) |
|
|
55
|
+
| `--css <name>` | `none` \| `bootstrap` \| `tailwind` |
|
|
56
|
+
| `--no-examples` | Skip the example `app/test` page |
|
|
57
|
+
| `--no-api` | Empty the example `api/` routes |
|
|
58
|
+
| `--no-docs` | Don't copy `docs/` |
|
|
59
|
+
|
|
60
|
+
## Install and run
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
cd my-app
|
|
64
|
+
npm install # installs @babel/standalone (used for JSX) + any deps you add
|
|
65
|
+
npm run dev
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Open **<http://localhost:3000>**. You should see the home page with a working counter.
|
|
69
|
+
|
|
70
|
+
The dev server watches your files and pushes a **live reload** to the browser whenever you save โ no manual refresh.
|
|
71
|
+
|
|
72
|
+
## npm scripts
|
|
73
|
+
|
|
74
|
+
Defined in your project's `package.json`:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"scripts": {
|
|
79
|
+
"dev": "node scripts/dev-server.js",
|
|
80
|
+
"build": "node scripts/dev-server.js --production",
|
|
81
|
+
"start": "node scripts/dev-server.js --production",
|
|
82
|
+
"test": "node --test"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- `npm run dev` โ development server with live reload and no caching.
|
|
88
|
+
- `npm run build` / `npm start` โ the same server in **production mode**: no live-reload socket, cache headers enabled. (Aziz.js has no bundling step; it serves your source compiled on demand and caches by file mtime.)
|
|
89
|
+
- `npm test` โ runs any `**/*.test.js` files via Node's built-in test runner. With no tests present it exits 0.
|
|
90
|
+
|
|
91
|
+
## Your first page
|
|
92
|
+
|
|
93
|
+
Create `app/hello/page.js`:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// app/hello/page.js โ /hello
|
|
97
|
+
export default function Hello() {
|
|
98
|
+
const [name, setName] = useState('');
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<div style={{ padding: '40px' }}>
|
|
102
|
+
<h1>Hello ๐</h1>
|
|
103
|
+
<input
|
|
104
|
+
value={name}
|
|
105
|
+
onInput={e => setName(e.target.value)}
|
|
106
|
+
placeholder="Your name"
|
|
107
|
+
/>
|
|
108
|
+
<p>{name ? `Hi, ${name}!` : 'Type somethingโฆ'}</p>
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Save. The browser reloads and you're at **<http://localhost:3000/hello>**.
|
|
115
|
+
|
|
116
|
+
Note: **you didn't import React or any hooks.** `useState`, `h` (the JSX factory), and the router are exposed globally by the framework. See [Hooks](./05-hooks.md).
|
|
117
|
+
|
|
118
|
+
## Your first API route
|
|
119
|
+
|
|
120
|
+
Create `api/greeting.js`:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
// api/greeting.js โ /api/greeting
|
|
124
|
+
module.exports = {
|
|
125
|
+
GET: async (request) => {
|
|
126
|
+
const name = request.query.get('name') || 'world';
|
|
127
|
+
return { hello: name };
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Visit **<http://localhost:3000/api/greeting?name=Aziz>** and you get JSON:
|
|
133
|
+
|
|
134
|
+
```json
|
|
135
|
+
{ "hello": "Aziz" }
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Call it from a page with the global client:
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
const data = await api.get('/api/greeting?name=Aziz');
|
|
142
|
+
console.log(data.hello); // "Aziz"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
See [API Routes](./06-api-routes.md) and [API Client](./07-api-client.md).
|
|
146
|
+
|
|
147
|
+
## Next steps
|
|
148
|
+
|
|
149
|
+
1. Understand the folder layout โ [Project Structure](./02-project-structure.md)
|
|
150
|
+
2. Build real screens โ [Pages & Layouts](./03-pages-and-layouts.md)
|
|
151
|
+
3. Master routes โ [Routing](./04-routing.md)
|
|
@@ -1,109 +1,109 @@
|
|
|
1
|
-
# 02 ยท Project Structure
|
|
2
|
-
|
|
3
|
-
Every folder in a generated Aziz.js app, and what goes in it.
|
|
4
|
-
|
|
5
|
-
```
|
|
6
|
-
my-app/
|
|
7
|
-
โโโ index.html โ entry point (loaded first, then the router takes over)
|
|
8
|
-
โโโ package.json โ name, scripts, dependencies
|
|
9
|
-
โ
|
|
10
|
-
โโโ app/ โ PAGES + LAYOUTS (file-based routing)
|
|
11
|
-
โ โโโ layout.js โ root layout, wraps every page
|
|
12
|
-
โ โโโ page.js โ route: /
|
|
13
|
-
โ โโโ not-found.js โ custom 404 screen
|
|
14
|
-
โ โโโ about/
|
|
15
|
-
โ โ โโโ page.js โ route: /about
|
|
16
|
-
โ โโโ blog/
|
|
17
|
-
โ โโโ [slug]/
|
|
18
|
-
โ โโโ page.js โ route: /blog/:slug (dynamic)
|
|
19
|
-
โ
|
|
20
|
-
โโโ api/ โ SERVER-SIDE API ROUTES (Node.js)
|
|
21
|
-
โ โโโ hello.js โ /api/hello
|
|
22
|
-
โ โโโ users.js โ /api/users
|
|
23
|
-
โ
|
|
24
|
-
โโโ components/ โ shared UI components
|
|
25
|
-
โ โโโ Navbar.js
|
|
26
|
-
โ โโโ Footer.js
|
|
27
|
-
โ
|
|
28
|
-
โโโ lib/ โ utilities, DB connections, helpers
|
|
29
|
-
โ โโโ db.js
|
|
30
|
-
โโโ models/ โ data models / schema definitions
|
|
31
|
-
โ โโโ User.js
|
|
32
|
-
โโโ styles/ โ CSS
|
|
33
|
-
โ โโโ globals.css
|
|
34
|
-
โ
|
|
35
|
-
โโโ _framework/ โ the framework itself (don't edit casually)
|
|
36
|
-
โ โโโ runtime.js โ h(), fibers, DOM materialization
|
|
37
|
-
โ โโโ hooks.js โ useState, useEffect, โฆ
|
|
38
|
-
โ โโโ router.js โ client router, Link, navigation
|
|
39
|
-
โ โโโ route-match.js โ path matching / layout collection
|
|
40
|
-
โ โโโ api.js โ browser API client (api.get, โฆ)
|
|
41
|
-
โ โโโ next-response.js โ NextResponse for API routes
|
|
42
|
-
โ โโโ boot.js โ boot sequence, exposes globals
|
|
43
|
-
โ
|
|
44
|
-
โโโ scripts/ โ dev server + tooling
|
|
45
|
-
โ โโโ dev-server.js โ the HTTP server (dev + production)
|
|
46
|
-
โ โโโ live-reload-client.js
|
|
47
|
-
โ โโโ lib/ โ js-transform, module-resolver, api-router
|
|
48
|
-
โ
|
|
49
|
-
โโโ docs/ โ these guides (optional, --no-docs to skip)
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## The two "worlds"
|
|
53
|
-
|
|
54
|
-
Aziz.js runs code in two places. Confusing them is the #1 beginner mistake.
|
|
55
|
-
|
|
56
|
-
| | **Browser** (`app/`, `components/`) | **Server** (`api/`, `lib/`, `models/`) |
|
|
57
|
-
|--|-------------------------------------|-----------------------------------------|
|
|
58
|
-
| Runs in | the browser | Node.js |
|
|
59
|
-
| Module system | ES modules (`import` / `export`) | CommonJS (`require`) or `.mjs` ESM |
|
|
60
|
-
| Imports | `/โฆ`, `@/โฆ`, bare npm โ `/_modules/โฆ` | normal Node resolution |
|
|
61
|
-
| Framework | `h`, hooks, router, `api` client | `NextResponse`, `require('../_framework/โฆ')` |
|
|
62
|
-
| Can touch | DOM, `window` | filesystem, DB, env vars, secrets |
|
|
63
|
-
|
|
64
|
-
- **Pages and components** are compiled (JSX โ `h()` calls) and sent to the browser.
|
|
65
|
-
- **API routes** are loaded by the dev server in Node and executed per request.
|
|
66
|
-
|
|
67
|
-
### Why API files use `require`
|
|
68
|
-
|
|
69
|
-
`api/*.js` files run in Node with the CommonJS loader, so you `require`:
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
const { NextResponse } = require('../_framework/next-response');
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
If you prefer native ESM on the server, name the file `.mjs` and use `export`:
|
|
76
|
-
|
|
77
|
-
```js
|
|
78
|
-
// api/todos.mjs
|
|
79
|
-
import { NextResponse } from '../_framework/next-response.js';
|
|
80
|
-
|
|
81
|
-
export async function GET() {
|
|
82
|
-
return NextResponse.json({ todos: [] });
|
|
83
|
-
}
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Both styles are supported โ see [API Routes](./06-api-routes.md).
|
|
87
|
-
|
|
88
|
-
## What the dev server does
|
|
89
|
-
|
|
90
|
-
`scripts/dev-server.js`:
|
|
91
|
-
|
|
92
|
-
1. Builds a **route manifest** by scanning `app/` and serves it at `/_framework/routes.json`.
|
|
93
|
-
2. Transforms **JSX** to `h()` calls on demand (cached by file mtime).
|
|
94
|
-
3. Resolves **bare npm imports** (`import mongoose from 'mongoose'`) via `/_modules/mongoose`.
|
|
95
|
-
4. Dispatches **API requests** to `api/**` and `app/api/**/route.js`.
|
|
96
|
-
5. Serves static files, with **path-traversal confined to the project root** (403 otherwise).
|
|
97
|
-
6. In development, opens a **WebSocket** and pushes reload events when you save.
|
|
98
|
-
|
|
99
|
-
## Conventions worth keeping
|
|
100
|
-
|
|
101
|
-
- **`app/`** is for pages and layouts only โ not arbitrary components.
|
|
102
|
-
- **`components/`** is for reusable UI shared across pages.
|
|
103
|
-
- **`lib/`** for shared server/browser helpers; **`models/`** for data shapes.
|
|
104
|
-
- **`_framework/`** and **`scripts/`** are framework internals โ prefer not to edit them, so upgrades stay easy.
|
|
105
|
-
- Names like `page.js`, `layout.js`, `route.js` are **reserved** by the file-based router. A `page.js` becomes a route; a random `utils.js` does not.
|
|
106
|
-
|
|
107
|
-
## Continue
|
|
108
|
-
|
|
109
|
-
โ [Pages & Layouts](./03-pages-and-layouts.md)
|
|
1
|
+
# 02 ยท Project Structure
|
|
2
|
+
|
|
3
|
+
Every folder in a generated Aziz.js app, and what goes in it.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
my-app/
|
|
7
|
+
โโโ index.html โ entry point (loaded first, then the router takes over)
|
|
8
|
+
โโโ package.json โ name, scripts, dependencies
|
|
9
|
+
โ
|
|
10
|
+
โโโ app/ โ PAGES + LAYOUTS (file-based routing)
|
|
11
|
+
โ โโโ layout.js โ root layout, wraps every page
|
|
12
|
+
โ โโโ page.js โ route: /
|
|
13
|
+
โ โโโ not-found.js โ custom 404 screen
|
|
14
|
+
โ โโโ about/
|
|
15
|
+
โ โ โโโ page.js โ route: /about
|
|
16
|
+
โ โโโ blog/
|
|
17
|
+
โ โโโ [slug]/
|
|
18
|
+
โ โโโ page.js โ route: /blog/:slug (dynamic)
|
|
19
|
+
โ
|
|
20
|
+
โโโ api/ โ SERVER-SIDE API ROUTES (Node.js)
|
|
21
|
+
โ โโโ hello.js โ /api/hello
|
|
22
|
+
โ โโโ users.js โ /api/users
|
|
23
|
+
โ
|
|
24
|
+
โโโ components/ โ shared UI components
|
|
25
|
+
โ โโโ Navbar.js
|
|
26
|
+
โ โโโ Footer.js
|
|
27
|
+
โ
|
|
28
|
+
โโโ lib/ โ utilities, DB connections, helpers
|
|
29
|
+
โ โโโ db.js
|
|
30
|
+
โโโ models/ โ data models / schema definitions
|
|
31
|
+
โ โโโ User.js
|
|
32
|
+
โโโ styles/ โ CSS
|
|
33
|
+
โ โโโ globals.css
|
|
34
|
+
โ
|
|
35
|
+
โโโ _framework/ โ the framework itself (don't edit casually)
|
|
36
|
+
โ โโโ runtime.js โ h(), fibers, DOM materialization
|
|
37
|
+
โ โโโ hooks.js โ useState, useEffect, โฆ
|
|
38
|
+
โ โโโ router.js โ client router, Link, navigation
|
|
39
|
+
โ โโโ route-match.js โ path matching / layout collection
|
|
40
|
+
โ โโโ api.js โ browser API client (api.get, โฆ)
|
|
41
|
+
โ โโโ next-response.js โ NextResponse for API routes
|
|
42
|
+
โ โโโ boot.js โ boot sequence, exposes globals
|
|
43
|
+
โ
|
|
44
|
+
โโโ scripts/ โ dev server + tooling
|
|
45
|
+
โ โโโ dev-server.js โ the HTTP server (dev + production)
|
|
46
|
+
โ โโโ live-reload-client.js
|
|
47
|
+
โ โโโ lib/ โ js-transform, module-resolver, api-router
|
|
48
|
+
โ
|
|
49
|
+
โโโ docs/ โ these guides (optional, --no-docs to skip)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## The two "worlds"
|
|
53
|
+
|
|
54
|
+
Aziz.js runs code in two places. Confusing them is the #1 beginner mistake.
|
|
55
|
+
|
|
56
|
+
| | **Browser** (`app/`, `components/`) | **Server** (`api/`, `lib/`, `models/`) |
|
|
57
|
+
|--|-------------------------------------|-----------------------------------------|
|
|
58
|
+
| Runs in | the browser | Node.js |
|
|
59
|
+
| Module system | ES modules (`import` / `export`) | CommonJS (`require`) or `.mjs` ESM |
|
|
60
|
+
| Imports | `/โฆ`, `@/โฆ`, bare npm โ `/_modules/โฆ` | normal Node resolution |
|
|
61
|
+
| Framework | `h`, hooks, router, `api` client | `NextResponse`, `require('../_framework/โฆ')` |
|
|
62
|
+
| Can touch | DOM, `window` | filesystem, DB, env vars, secrets |
|
|
63
|
+
|
|
64
|
+
- **Pages and components** are compiled (JSX โ `h()` calls) and sent to the browser.
|
|
65
|
+
- **API routes** are loaded by the dev server in Node and executed per request.
|
|
66
|
+
|
|
67
|
+
### Why API files use `require`
|
|
68
|
+
|
|
69
|
+
`api/*.js` files run in Node with the CommonJS loader, so you `require`:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
const { NextResponse } = require('../_framework/next-response');
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
If you prefer native ESM on the server, name the file `.mjs` and use `export`:
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
// api/todos.mjs
|
|
79
|
+
import { NextResponse } from '../_framework/next-response.js';
|
|
80
|
+
|
|
81
|
+
export async function GET() {
|
|
82
|
+
return NextResponse.json({ todos: [] });
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Both styles are supported โ see [API Routes](./06-api-routes.md).
|
|
87
|
+
|
|
88
|
+
## What the dev server does
|
|
89
|
+
|
|
90
|
+
`scripts/dev-server.js`:
|
|
91
|
+
|
|
92
|
+
1. Builds a **route manifest** by scanning `app/` and serves it at `/_framework/routes.json`.
|
|
93
|
+
2. Transforms **JSX** to `h()` calls on demand (cached by file mtime).
|
|
94
|
+
3. Resolves **bare npm imports** (`import mongoose from 'mongoose'`) via `/_modules/mongoose`.
|
|
95
|
+
4. Dispatches **API requests** to `api/**` and `app/api/**/route.js`.
|
|
96
|
+
5. Serves static files, with **path-traversal confined to the project root** (403 otherwise).
|
|
97
|
+
6. In development, opens a **WebSocket** and pushes reload events when you save.
|
|
98
|
+
|
|
99
|
+
## Conventions worth keeping
|
|
100
|
+
|
|
101
|
+
- **`app/`** is for pages and layouts only โ not arbitrary components.
|
|
102
|
+
- **`components/`** is for reusable UI shared across pages.
|
|
103
|
+
- **`lib/`** for shared server/browser helpers; **`models/`** for data shapes.
|
|
104
|
+
- **`_framework/`** and **`scripts/`** are framework internals โ prefer not to edit them, so upgrades stay easy.
|
|
105
|
+
- Names like `page.js`, `layout.js`, `route.js` are **reserved** by the file-based router. A `page.js` becomes a route; a random `utils.js` does not.
|
|
106
|
+
|
|
107
|
+
## Continue
|
|
108
|
+
|
|
109
|
+
โ [Pages & Layouts](./03-pages-and-layouts.md)
|