@nitronjs/framework 0.1.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/README.md +429 -0
- package/cli/create.js +260 -0
- package/cli/njs.js +164 -0
- package/lib/Auth/Manager.js +111 -0
- package/lib/Build/Manager.js +1232 -0
- package/lib/Console/Commands/BuildCommand.js +25 -0
- package/lib/Console/Commands/DevCommand.js +385 -0
- package/lib/Console/Commands/MakeCommand.js +110 -0
- package/lib/Console/Commands/MigrateCommand.js +98 -0
- package/lib/Console/Commands/MigrateFreshCommand.js +97 -0
- package/lib/Console/Commands/SeedCommand.js +92 -0
- package/lib/Console/Commands/StorageLinkCommand.js +31 -0
- package/lib/Console/Stubs/controller.js +19 -0
- package/lib/Console/Stubs/middleware.js +9 -0
- package/lib/Console/Stubs/migration.js +23 -0
- package/lib/Console/Stubs/model.js +7 -0
- package/lib/Console/Stubs/page-hydration.tsx +54 -0
- package/lib/Console/Stubs/seeder.js +9 -0
- package/lib/Console/Stubs/vendor.tsx +11 -0
- package/lib/Core/Config.js +86 -0
- package/lib/Core/Environment.js +21 -0
- package/lib/Core/Paths.js +188 -0
- package/lib/Database/Connection.js +61 -0
- package/lib/Database/DB.js +84 -0
- package/lib/Database/Drivers/MySQLDriver.js +234 -0
- package/lib/Database/Manager.js +162 -0
- package/lib/Database/Model.js +161 -0
- package/lib/Database/QueryBuilder.js +714 -0
- package/lib/Database/QueryValidation.js +62 -0
- package/lib/Database/Schema/Blueprint.js +126 -0
- package/lib/Database/Schema/Manager.js +116 -0
- package/lib/Date/DateTime.js +108 -0
- package/lib/Date/Locale.js +68 -0
- package/lib/Encryption/Manager.js +47 -0
- package/lib/Filesystem/Manager.js +49 -0
- package/lib/Hashing/Manager.js +25 -0
- package/lib/Http/Server.js +317 -0
- package/lib/Logging/Manager.js +153 -0
- package/lib/Mail/Manager.js +120 -0
- package/lib/Route/Loader.js +81 -0
- package/lib/Route/Manager.js +265 -0
- package/lib/Runtime/Entry.js +11 -0
- package/lib/Session/File.js +299 -0
- package/lib/Session/Manager.js +259 -0
- package/lib/Session/Memory.js +67 -0
- package/lib/Session/Session.js +196 -0
- package/lib/Support/Str.js +100 -0
- package/lib/Translation/Manager.js +49 -0
- package/lib/Validation/MimeTypes.js +39 -0
- package/lib/Validation/Validator.js +691 -0
- package/lib/View/Manager.js +544 -0
- package/lib/View/Templates/default/Home.tsx +262 -0
- package/lib/View/Templates/default/MainLayout.tsx +44 -0
- package/lib/View/Templates/errors/404.tsx +13 -0
- package/lib/View/Templates/errors/500.tsx +13 -0
- package/lib/View/Templates/errors/ErrorLayout.tsx +112 -0
- package/lib/View/Templates/messages/Maintenance.tsx +17 -0
- package/lib/View/Templates/messages/MessageLayout.tsx +136 -0
- package/lib/index.js +57 -0
- package/package.json +47 -0
- package/skeleton/.env.example +26 -0
- package/skeleton/app/Controllers/HomeController.js +9 -0
- package/skeleton/app/Kernel.js +11 -0
- package/skeleton/app/Middlewares/Authentication.js +9 -0
- package/skeleton/app/Middlewares/Guest.js +9 -0
- package/skeleton/app/Middlewares/VerifyCsrf.js +24 -0
- package/skeleton/app/Models/User.js +7 -0
- package/skeleton/config/app.js +4 -0
- package/skeleton/config/auth.js +16 -0
- package/skeleton/config/database.js +27 -0
- package/skeleton/config/hash.js +3 -0
- package/skeleton/config/server.js +28 -0
- package/skeleton/config/session.js +21 -0
- package/skeleton/database/migrations/2025_01_01_00_00_users.js +20 -0
- package/skeleton/database/seeders/UserSeeder.js +15 -0
- package/skeleton/globals.d.ts +1 -0
- package/skeleton/package.json +24 -0
- package/skeleton/public/.gitkeep +0 -0
- package/skeleton/resources/css/.gitkeep +0 -0
- package/skeleton/resources/langs/.gitkeep +0 -0
- package/skeleton/resources/views/Site/Home.tsx +66 -0
- package/skeleton/routes/web.js +4 -0
- package/skeleton/storage/app/private/.gitkeep +0 -0
- package/skeleton/storage/app/public/.gitkeep +0 -0
- package/skeleton/storage/framework/sessions/.gitkeep +0 -0
- package/skeleton/storage/logs/.gitkeep +0 -0
- package/skeleton/tsconfig.json +33 -0
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nitronjs/framework",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NitronJS is a modern and extensible Node.js MVC framework built on Fastify. It focuses on clean architecture, modular structure, and developer productivity, offering built-in routing, middleware, configuration management, CLI tooling, and native React integration for scalable full-stack applications.",
|
|
5
|
+
"bin": {
|
|
6
|
+
"njs": "./cli/njs.js"
|
|
7
|
+
},
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@fastify/cookie": "^11.0.2",
|
|
13
|
+
"@fastify/cors": "^11.2.0",
|
|
14
|
+
"@fastify/formbody": "^8.0.2",
|
|
15
|
+
"@fastify/helmet": "^13.0.2",
|
|
16
|
+
"@fastify/multipart": "^9.3.0",
|
|
17
|
+
"@fastify/static": "^8.3.0",
|
|
18
|
+
"bcrypt": "^5.1.1",
|
|
19
|
+
"dotenv": "^17.2.3",
|
|
20
|
+
"fastify": "^5.6.2",
|
|
21
|
+
"mysql2": "^3.16.0",
|
|
22
|
+
"nodemailer": "^7.0.11",
|
|
23
|
+
"react": "^19.2.3",
|
|
24
|
+
"react-dom": "^19.2.3",
|
|
25
|
+
"socket.io": "^4.8.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@babel/parser": "^7.28.5",
|
|
29
|
+
"@babel/traverse": "^7.28.5",
|
|
30
|
+
"@tailwindcss/postcss": "^4.1.18",
|
|
31
|
+
"@types/react": "^19.2.7",
|
|
32
|
+
"@types/react-dom": "^19.2.3",
|
|
33
|
+
"chokidar": "^5.0.0",
|
|
34
|
+
"esbuild": "^0.27.2",
|
|
35
|
+
"postcss": "^8.5.6",
|
|
36
|
+
"tailwindcss": "^4.1.18",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"nitronjs",
|
|
41
|
+
"framework",
|
|
42
|
+
"mvc"
|
|
43
|
+
],
|
|
44
|
+
"author": "Burak AKBULUT",
|
|
45
|
+
"license": "ISC",
|
|
46
|
+
"type": "module"
|
|
47
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
APP_NAME=nitronjs
|
|
2
|
+
APP_KEY=
|
|
3
|
+
APP_URL=http://localhost
|
|
4
|
+
APP_PORT=3000
|
|
5
|
+
APP_DEV=true
|
|
6
|
+
APP_DEBUG=true
|
|
7
|
+
|
|
8
|
+
FILESYSTEM_DRIVER=disk
|
|
9
|
+
|
|
10
|
+
# Driver: mysql | postgresql | mongodb | none
|
|
11
|
+
DATABASE_DRIVER=mysql
|
|
12
|
+
DATABASE_HOST=127.0.0.1
|
|
13
|
+
DATABASE_PORT=3306
|
|
14
|
+
DATABASE_NAME=nitronjs
|
|
15
|
+
DATABASE_USERNAME=root
|
|
16
|
+
DATABASE_PASSWORD=
|
|
17
|
+
|
|
18
|
+
MAIL_HOST=
|
|
19
|
+
MAIL_PORT=
|
|
20
|
+
MAIL_USERNAME=
|
|
21
|
+
MAIL_PASSWORD=
|
|
22
|
+
MAIL_SECURE=
|
|
23
|
+
|
|
24
|
+
REDIS_HOST=127.0.0.1
|
|
25
|
+
REDIS_PORT=6379
|
|
26
|
+
REDIS_PASSWORD=
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Authentication from "./Middlewares/Authentication.js";
|
|
2
|
+
import Guest from "./Middlewares/Guest.js";
|
|
3
|
+
import VerifyCsrf from "./Middlewares/VerifyCsrf.js";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
routeMiddlewares: {
|
|
7
|
+
"guest": Guest,
|
|
8
|
+
"auth": Authentication,
|
|
9
|
+
"verify-csrf": VerifyCsrf,
|
|
10
|
+
}
|
|
11
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import sessionConfig from "../../config/session.js";
|
|
2
|
+
|
|
3
|
+
class VerifyCsrf {
|
|
4
|
+
static async handler(req, res) {
|
|
5
|
+
const csrf = sessionConfig.csrf;
|
|
6
|
+
const token = req.body?.[csrf.tokenField] || req.headers[csrf.headerField];
|
|
7
|
+
|
|
8
|
+
if (!token) {
|
|
9
|
+
return res.code(403).send({
|
|
10
|
+
status: "error",
|
|
11
|
+
message: "CSRF token is required."
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!req.session.verifyCsrfToken(token)) {
|
|
16
|
+
return res.code(403).send({
|
|
17
|
+
status: "error",
|
|
18
|
+
message: "Invalid CSRF token."
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default VerifyCsrf;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
connections: {
|
|
3
|
+
mysql: {
|
|
4
|
+
driver: 'mysql',
|
|
5
|
+
charset: 'utf8mb4',
|
|
6
|
+
collation: 'utf8mb4_unicode_ci',
|
|
7
|
+
prefix: '',
|
|
8
|
+
pool: {
|
|
9
|
+
min: 2,
|
|
10
|
+
max: 10,
|
|
11
|
+
queueLimit: 100
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
postgres: {
|
|
16
|
+
driver: 'postgres',
|
|
17
|
+
charset: 'utf8',
|
|
18
|
+
prefix: '',
|
|
19
|
+
schema: 'public',
|
|
20
|
+
pool: {
|
|
21
|
+
min: 2,
|
|
22
|
+
max: 10,
|
|
23
|
+
queueLimit: 100
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
web_server: {
|
|
3
|
+
maxParamLength: 150,
|
|
4
|
+
bodyLimit: 50 * 1024 * 1024,
|
|
5
|
+
trustProxy: true,
|
|
6
|
+
multipart: {
|
|
7
|
+
fieldNameSize: 100,
|
|
8
|
+
fieldSize: 2 * 1024 * 1024,
|
|
9
|
+
maxFields: 50,
|
|
10
|
+
maxFileSize: 20 * 1024 * 1024,
|
|
11
|
+
maxFiles: 10,
|
|
12
|
+
maxParts: 60,
|
|
13
|
+
attachFieldsToBody: true,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
cors: {
|
|
18
|
+
origin: 'auto',
|
|
19
|
+
credentials: true,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
log: {
|
|
23
|
+
channel: 'file',
|
|
24
|
+
level: 'info',
|
|
25
|
+
file: './storage/logs/app.log',
|
|
26
|
+
sync: false,
|
|
27
|
+
},
|
|
28
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const SESSION_LIFETIME = 1000 * 60 * 60 * 2;
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
driver: "file",
|
|
5
|
+
lifetime: SESSION_LIFETIME,
|
|
6
|
+
cookieName: "session",
|
|
7
|
+
cookie: {
|
|
8
|
+
httpOnly: true,
|
|
9
|
+
secure: process.env.APP_DEV !== "true",
|
|
10
|
+
sameSite: "lax",
|
|
11
|
+
path: "/",
|
|
12
|
+
maxAge: SESSION_LIFETIME
|
|
13
|
+
},
|
|
14
|
+
csrf: {
|
|
15
|
+
enabled: true,
|
|
16
|
+
methods: ["POST", "PUT", "DELETE"],
|
|
17
|
+
except: ["/api/*"],
|
|
18
|
+
tokenField: "_csrf",
|
|
19
|
+
headerField: "x-csrf-token"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Schema } from "@nitronjs/framework";
|
|
2
|
+
|
|
3
|
+
class Users {
|
|
4
|
+
static async up() {
|
|
5
|
+
await Schema.create("users", (table) => {
|
|
6
|
+
table.id();
|
|
7
|
+
table.string("name");
|
|
8
|
+
table.string("email").unique();
|
|
9
|
+
table.text("password");
|
|
10
|
+
table.timestamp("created_at");
|
|
11
|
+
table.timestamp("updated_at").nullable();
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static async down() {
|
|
16
|
+
await Schema.dropIfExists("users");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default Users;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Hash } from "@nitronjs/framework";
|
|
2
|
+
import User from "../../app/Models/User.js";
|
|
3
|
+
|
|
4
|
+
class UserSeeder {
|
|
5
|
+
static async run() {
|
|
6
|
+
const user = new User();
|
|
7
|
+
user.name = "Admin";
|
|
8
|
+
user.email = "admin@example.com";
|
|
9
|
+
user.password = await Hash.make("password");
|
|
10
|
+
user.created_at = new Date();
|
|
11
|
+
await user.save();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default UserSeeder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {} from 'nitronjs';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "my-nitronjs-app",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "njs dev",
|
|
7
|
+
"build": "njs build",
|
|
8
|
+
"start": "njs start",
|
|
9
|
+
"migrate": "njs migrate",
|
|
10
|
+
"migrate:seed": "njs migrate --seed",
|
|
11
|
+
"migrate:fresh": "njs migrate:fresh",
|
|
12
|
+
"migrate:fresh:seed": "njs migrate:fresh --seed",
|
|
13
|
+
"seed": "njs seed",
|
|
14
|
+
"storage:link": "njs storage:link",
|
|
15
|
+
"make:controller": "njs make:controller",
|
|
16
|
+
"make:middleware": "njs make:middleware",
|
|
17
|
+
"make:model": "njs make:model",
|
|
18
|
+
"make:migration": "njs make:migration",
|
|
19
|
+
"make:seeder": "njs make:seeder"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@nitronjs/framework": "^0.1.0"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
type HomeProps = {
|
|
2
|
+
name?: string;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export default function Home({ name = "NitronJS" }: HomeProps) {
|
|
6
|
+
return (
|
|
7
|
+
<main style={{
|
|
8
|
+
minHeight: "100vh",
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
alignItems: "center",
|
|
12
|
+
justifyContent: "center",
|
|
13
|
+
gap: "1.5rem",
|
|
14
|
+
color: "#fff",
|
|
15
|
+
background: "radial-gradient(circle at top, #111827, #0b0f19)",
|
|
16
|
+
fontFamily: "system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif",
|
|
17
|
+
padding: "4rem 1.5rem"
|
|
18
|
+
}}>
|
|
19
|
+
<h1 style={{
|
|
20
|
+
fontSize: "3.5rem",
|
|
21
|
+
lineHeight: "1.1",
|
|
22
|
+
margin: 0,
|
|
23
|
+
textAlign: "center"
|
|
24
|
+
}}>
|
|
25
|
+
Welcome to {name}
|
|
26
|
+
</h1>
|
|
27
|
+
<p style={{
|
|
28
|
+
maxWidth: "680px",
|
|
29
|
+
textAlign: "center",
|
|
30
|
+
color: "#94a3b8",
|
|
31
|
+
margin: 0,
|
|
32
|
+
fontSize: "1.125rem"
|
|
33
|
+
}}>
|
|
34
|
+
Your project is ready. Start building pages with React SSR and the NitronJS MVC structure.
|
|
35
|
+
</p>
|
|
36
|
+
<div style={{
|
|
37
|
+
display: "flex",
|
|
38
|
+
gap: "0.75rem",
|
|
39
|
+
flexWrap: "wrap",
|
|
40
|
+
justifyContent: "center"
|
|
41
|
+
}}>
|
|
42
|
+
<a href="https://nitronjs.dev/docs" style={{
|
|
43
|
+
padding: "0.75rem 1.5rem",
|
|
44
|
+
borderRadius: "10px",
|
|
45
|
+
background: "#3b82f6",
|
|
46
|
+
color: "#fff",
|
|
47
|
+
textDecoration: "none",
|
|
48
|
+
fontWeight: 600
|
|
49
|
+
}}>
|
|
50
|
+
Documentation
|
|
51
|
+
</a>
|
|
52
|
+
<a href="https://nitronjs.dev" style={{
|
|
53
|
+
padding: "0.75rem 1.5rem",
|
|
54
|
+
borderRadius: "10px",
|
|
55
|
+
background: "transparent",
|
|
56
|
+
color: "#e2e8f0",
|
|
57
|
+
textDecoration: "none",
|
|
58
|
+
border: "1px solid #334155",
|
|
59
|
+
fontWeight: 600
|
|
60
|
+
}}>
|
|
61
|
+
Website
|
|
62
|
+
</a>
|
|
63
|
+
</div>
|
|
64
|
+
</main>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Node",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"jsxImportSource": "react",
|
|
8
|
+
"lib": ["ES2022", "DOM"],
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"declarationMap": true,
|
|
16
|
+
"outDir": "./dist",
|
|
17
|
+
"rootDir": "."
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"app/**/*",
|
|
21
|
+
"config/**/*",
|
|
22
|
+
"database/**/*",
|
|
23
|
+
"routes/**/*",
|
|
24
|
+
"resources/**/*",
|
|
25
|
+
"globals.d.ts"
|
|
26
|
+
],
|
|
27
|
+
"exclude": [
|
|
28
|
+
"node_modules",
|
|
29
|
+
"dist",
|
|
30
|
+
"build",
|
|
31
|
+
"storage"
|
|
32
|
+
]
|
|
33
|
+
}
|