free-framework 4.4.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.
Files changed (72) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -0
  3. package/bin/free.js +118 -0
  4. package/cli/commands/build.js +124 -0
  5. package/cli/commands/deploy.js +143 -0
  6. package/cli/commands/devtools.js +210 -0
  7. package/cli/commands/doctor.js +72 -0
  8. package/cli/commands/install.js +28 -0
  9. package/cli/commands/make.js +74 -0
  10. package/cli/commands/migrate.js +67 -0
  11. package/cli/commands/new.js +54 -0
  12. package/cli/commands/serve.js +73 -0
  13. package/cli/commands/test.js +57 -0
  14. package/compiler/analyzer.js +102 -0
  15. package/compiler/generator.js +386 -0
  16. package/compiler/lexer.js +166 -0
  17. package/compiler/parser.js +410 -0
  18. package/database/model.js +6 -0
  19. package/database/orm.js +379 -0
  20. package/database/query-builder.js +179 -0
  21. package/index.js +51 -0
  22. package/package.json +80 -0
  23. package/plugins/auth.js +212 -0
  24. package/plugins/cache.js +85 -0
  25. package/plugins/chat.js +32 -0
  26. package/plugins/mail.js +53 -0
  27. package/plugins/metrics.js +126 -0
  28. package/plugins/payments.js +59 -0
  29. package/plugins/queue.js +139 -0
  30. package/plugins/search.js +51 -0
  31. package/plugins/storage.js +123 -0
  32. package/plugins/upload.js +62 -0
  33. package/router/router.js +57 -0
  34. package/runtime/app.js +14 -0
  35. package/runtime/client.js +254 -0
  36. package/runtime/cluster.js +35 -0
  37. package/runtime/edge.js +62 -0
  38. package/runtime/middleware/maintenance.js +54 -0
  39. package/runtime/middleware/security.js +30 -0
  40. package/runtime/server.js +130 -0
  41. package/runtime/validator.js +102 -0
  42. package/runtime/views/error.free +104 -0
  43. package/runtime/views/maintenance.free +0 -0
  44. package/template-engine/renderer.js +24 -0
  45. package/templates/app-template/.env +23 -0
  46. package/templates/app-template/app/Exceptions/Handler.js +65 -0
  47. package/templates/app-template/app/Http/Controllers/AuthController.free +91 -0
  48. package/templates/app-template/app/Http/Middleware/AuthGuard.js +46 -0
  49. package/templates/app-template/app/Services/Storage.js +75 -0
  50. package/templates/app-template/app/Services/Validator.js +91 -0
  51. package/templates/app-template/app/controllers/AuthController.free +42 -0
  52. package/templates/app-template/app/middleware/auth.js +25 -0
  53. package/templates/app-template/app/models/User.free +32 -0
  54. package/templates/app-template/app/routes.free +12 -0
  55. package/templates/app-template/app/styles.css +23 -0
  56. package/templates/app-template/app/views/counter.free +23 -0
  57. package/templates/app-template/app/views/header.free +13 -0
  58. package/templates/app-template/config/app.js +32 -0
  59. package/templates/app-template/config/auth.js +39 -0
  60. package/templates/app-template/config/database.js +54 -0
  61. package/templates/app-template/package.json +28 -0
  62. package/templates/app-template/resources/css/app.css +11 -0
  63. package/templates/app-template/resources/views/dashboard.free +25 -0
  64. package/templates/app-template/resources/views/home.free +26 -0
  65. package/templates/app-template/routes/api.free +22 -0
  66. package/templates/app-template/routes/web.free +25 -0
  67. package/templates/app-template/tailwind.config.js +21 -0
  68. package/templates/app-template/views/about.ejs +47 -0
  69. package/templates/app-template/views/home.ejs +52 -0
  70. package/templates/auth/login.html +144 -0
  71. package/templates/auth/register.html +146 -0
  72. package/utils/logger.js +20 -0
@@ -0,0 +1,23 @@
1
+ component Counter {
2
+ state count = 0
3
+
4
+ div class="glass p-8 flex flex-col items-center gap-6 max-w-sm mx-auto mt-20" {
5
+ h2 class="text-2xl font-bold" {
6
+ text "Interactive Island"
7
+ }
8
+
9
+ div class="text-6xl font-black text-glow" {
10
+ span class="state-bind" data-bind="count" { text "{count}" }
11
+ }
12
+
13
+ div class="flex gap-4" {
14
+ button class="btn-premium" onclick="count++" {
15
+ text "Increment"
16
+ }
17
+
18
+ button class="px-6 py-3 bg-white/10 hover:bg-white/20 rounded-xl transition-all" onclick="Free.call('addTask', { title: 'Count is ' + state.count }).then(() => alert('Saved!'))" {
19
+ text "Save Task to DB"
20
+ }
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,13 @@
1
+ component Header {
2
+ nav class="fixed top-0 left-0 right-0 z-50 px-8 py-4 glass flex justify-between items-center m-4" {
3
+ h1 class="text-xl font-black text-glow" {
4
+ text "Free Ultra"
5
+ }
6
+
7
+ div class="flex gap-6 text-sm font-medium opacity-70" {
8
+ link "Docs" "/docs" class="hover:text-primary transition-colors"
9
+ link "Benchmarks" "/benchmarks" class="hover:text-primary transition-colors"
10
+ link "Community" "/community" class="hover:text-primary transition-colors"
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * config/app.js
3
+ *
4
+ * --------------------------------------------------------------------------
5
+ * Application Configuration
6
+ * --------------------------------------------------------------------------
7
+ *
8
+ * This file contains the core configuration for your Free Framework application.
9
+ * You can set the application name, environment, and debug mode here.
10
+ * It is highly recommended to use the .env file to manage these settings
11
+ * across different environments (local, staging, production).
12
+ *
13
+ * @security This file should NEVER contain hardcoded secrets. Always use process.env.
14
+ */
15
+
16
+ module.exports = {
17
+ // The name of your application, used in logs, emails, and UI elements.
18
+ name: process.env.APP_NAME || 'Free Enterprise App',
19
+
20
+ // The environment the application is running in (e.g., 'local', 'staging', 'production').
21
+ env: process.env.NODE_ENV || 'development',
22
+
23
+ // Debug mode determines if detailed error stack traces are shown to the user.
24
+ // [SECURITY WARNING]: ALWAYS set this to 'false' in production to prevent sensitive logic leaks!
25
+ debug: process.env.APP_DEBUG === 'true' || true,
26
+
27
+ // The base URL of your application, used for generating absolute links.
28
+ url: process.env.APP_URL || 'http://localhost:3000',
29
+
30
+ // The default timezone for your application's dates and logging.
31
+ timezone: 'UTC',
32
+ };
@@ -0,0 +1,39 @@
1
+ /**
2
+ * config/auth.js
3
+ *
4
+ * --------------------------------------------------------------------------
5
+ * Authentication & Security Configuration
6
+ * --------------------------------------------------------------------------
7
+ *
8
+ * This file governs how your application handles user authentication,
9
+ * password hashing (bcrypt), and stateless API protection using JSON Web Tokens (JWT).
10
+ *
11
+ * @security The JWT_SECRET must be a long, cryptographically secure random string.
12
+ * Do NOT commit your actual production `.env` file to version control.
13
+ */
14
+
15
+ module.exports = {
16
+ // ── JSON Web Token (JWT) Settings ─────────────────────────────────────────
17
+
18
+ // The secret key used to sign and verify JWT tokens.
19
+ // If compromised, attackers can forge logins. Keeps this extremely safe.
20
+ jwt_secret: process.env.JWT_SECRET || 'CHANGE_THIS_FATAL_DEFAULT_SECRET_IMMEDIATELY',
21
+
22
+ // How long until the JWT token expires (e.g., '1h', '7d', '30d').
23
+ // Shorter lifespans are more secure but require users to log in more often.
24
+ jwt_expires_in: process.env.JWT_EXPIRES_IN || '7d',
25
+
26
+
27
+ // ── Password Hashing Settings ──────────────────────────────────────────────
28
+
29
+ // The number of salt rounds for bcrypt.
30
+ // 10 is the industry standard balance between security and performance.
31
+ // Higher numbers = more secure against brute-force, but slower logins/registrations.
32
+ bcrypt_rounds: 10,
33
+
34
+
35
+ // ── CSRF (Cross-Site Request Forgery) Protection ───────────────────────────
36
+
37
+ // Free Framework can automatically protect form submissions from CSRF attacks.
38
+ csrf_enabled: process.env.CSRF_ENABLED === 'true' || true,
39
+ };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * config/database.js
3
+ *
4
+ * --------------------------------------------------------------------------
5
+ * Database Configuration
6
+ * --------------------------------------------------------------------------
7
+ *
8
+ * Free Framework uses a powerful ORM connection pool (Knex.js) under the hood.
9
+ * This file maps your environment variables into the actual database driver settings.
10
+ * MySQL (mysql2) is the recommended production default for maximum throughput.
11
+ *
12
+ * @security Ensure database ports are not exposed publicly, and use strong passwords.
13
+ */
14
+
15
+ module.exports = {
16
+ // The default database connection to use.
17
+ default: process.env.DB_CLIENT || 'mysql2',
18
+
19
+ connections: {
20
+ // High-performance MySQL connection settings
21
+ mysql2: {
22
+ host: process.env.DB_HOST || '127.0.0.1',
23
+ port: process.env.DB_PORT || 3306,
24
+ user: process.env.DB_USER || 'root',
25
+ password: process.env.DB_PASS || '',
26
+ database: process.env.DB_NAME || 'free_db',
27
+
28
+ // Connection pooling is crucial for enterprise apps handling thousands of requests.
29
+ // It prevents the server from creating a new connection for every single query.
30
+ pool: {
31
+ min: Number(process.env.DB_POOL_MIN) || 5,
32
+ max: Number(process.env.DB_POOL_MAX) || 50
33
+ }
34
+ },
35
+
36
+ // PostgreSQL settings
37
+ pg: {
38
+ host: process.env.DB_HOST || '127.0.0.1',
39
+ port: process.env.DB_PORT || 5432,
40
+ user: process.env.DB_USER || 'postgres',
41
+ password: process.env.DB_PASS || '',
42
+ database: process.env.DB_NAME || 'free_db',
43
+ pool: {
44
+ min: Number(process.env.DB_POOL_MIN) || 2,
45
+ max: Number(process.env.DB_POOL_MAX) || 20
46
+ }
47
+ },
48
+
49
+ // SQLite settings (For rapid local development/testing only. NOT for high-traffic production)
50
+ sqlite3: {
51
+ filename: process.env.DB_PATH || 'database/database.sqlite'
52
+ }
53
+ }
54
+ };
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "free-app",
3
+ "version": "1.0.0",
4
+ "description": "A new Free Framework application",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "free serve",
8
+ "build": "free build"
9
+ },
10
+ "dependencies": {
11
+ "hyper-express": "^6.14.0",
12
+ "knex": "^3.1.0",
13
+ "mysql2": "^3.9.2",
14
+ "pg": "^8.11.3",
15
+ "live-directory": "^2.1.0",
16
+ "lru-cache": "^10.2.0",
17
+ "clean-css": "^5.3.3",
18
+ "html-minifier-terser": "^7.2.0",
19
+ "dotenv": "^16.4.5",
20
+ "bcryptjs": "^2.4.3",
21
+ "jsonwebtoken": "^9.0.2"
22
+ },
23
+ "devDependencies": {
24
+ "tailwindcss": "^3.4.1",
25
+ "postcss": "^8.4.35",
26
+ "autoprefixer": "^10.4.18"
27
+ }
28
+ }
@@ -0,0 +1,11 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ /* --------------------------------------------------------------------------
6
+ * Free Framework Enterprise Styles
7
+ * --------------------------------------------------------------------------
8
+ *
9
+ * You can write custom CSS here or use Tailwind's utility classes directly
10
+ * in your .free components.
11
+ */
@@ -0,0 +1,25 @@
1
+ /**
2
+ * resources/views/dashboard.free
3
+ *
4
+ * An example of a protected dashboard view.
5
+ * Demonstrates querying data from a Database (if configured).
6
+ */
7
+
8
+ component Dashboard {
9
+ style {
10
+ .dashboard-container { padding: 2rem; background: #f3f4f6; min-height: 100vh; }
11
+ .card { background: white; padding: 1.5rem; border-radius: 0.5rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); }
12
+ }
13
+
14
+ div class="dashboard-container" {
15
+ div class="max-w-4xl mx-auto" {
16
+ h1 class="text-3xl font-bold mb-6 text-gray-800" { text "Secure Dashboard" }
17
+
18
+ div class="card" {
19
+ h2 class="text-xl font-semibold mb-2" { text "System Status" }
20
+ p class="text-gray-600" { text "If you are seeing this, your enterprise framework was successfully generated and routed!" }
21
+ p class="text-sm mt-4 text-gray-400" { text "Tip: Check routes/web.free and app/Http/Controllers to see how this page operates." }
22
+ }
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * resources/views/home.free
3
+ *
4
+ * The default landing page component.
5
+ * Features modern Tailwind styling and demonstrates basic reactive state.
6
+ */
7
+
8
+ component Home {
9
+ style {
10
+ .hero { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; background: linear-gradient(to right, #1f2937, #111827); color: white; }
11
+ }
12
+
13
+ div class="hero text-center" {
14
+ h1 class="text-6xl font-extrabold mb-4 bg-clip-text text-transparent bg-gradient-to-r from-blue-400 to-emerald-400" {
15
+ text "Free Framework"
16
+ }
17
+ p class="text-xl mb-8 text-gray-300" {
18
+ text "The Enterprise Node.js Ecosystem. MVC, JWT, and Extreme Performance."
19
+ }
20
+
21
+ div class="flex gap-4" {
22
+ a href="https://github.com/omartolba" class="px-6 py-3 bg-blue-600 hover:bg-blue-700 rounded-lg font-bold transition-colors" { text "Documentation" }
23
+ a href="/dashboard" class="px-6 py-3 bg-gray-700 hover:bg-gray-600 rounded-lg font-bold transition-colors" { text "View Dashboard" }
24
+ }
25
+ }
26
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * routes/api.free
3
+ *
4
+ * --------------------------------------------------------------------------
5
+ * API Routes
6
+ * --------------------------------------------------------------------------
7
+ *
8
+ * Here is where you can register API routes for your application. These
9
+ * routes are loaded by the RouteServiceProvider and are typically assigned
10
+ * to the "api" middleware group. They generate RESTful JSON responses.
11
+ *
12
+ * Security: All API endpoints dealing with sensitive data MUST be protected
13
+ * by JWT authentication middleware.
14
+ */
15
+
16
+ // Auth Endpoints - These point to the AuthController actions
17
+ post "/api/register" -> register
18
+ post "/api/login" -> login
19
+
20
+ // Example of a protected API Endpoint
21
+ // Any route defined here should have its logic handled purely in a Controller (action)
22
+ // returning JSON objects { success: true, data: [...] }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * routes/web.free
3
+ *
4
+ * --------------------------------------------------------------------------
5
+ * Web Routes
6
+ * --------------------------------------------------------------------------
7
+ *
8
+ * Here is where you can register web routes for your application. These
9
+ * routes are typically meant to return HTML/Views to the user's browser.
10
+ *
11
+ * Security: These routes are public by default. To protect a route, you can
12
+ * attach middleware globally via server configuration, or handle checks inside the
13
+ * individual controller actions.
14
+ */
15
+
16
+ // A simple GET request that renders the 'Home' view component
17
+ get "/" -> Home
18
+
19
+ // Example of a route that points to a dedicated controller logic before rendering
20
+ // Ensure the 'Dashboard' view is defined in resources/views
21
+ get "/dashboard" {
22
+ // Calling an action/controller before returning the view
23
+ // The controller should handle checking if the user is authenticated
24
+ // return Dashboard;
25
+ }
@@ -0,0 +1,21 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ module.exports = {
3
+ content: [
4
+ "./app/**/*.free",
5
+ "./views/**/*.html",
6
+ "./public/**/*.js"
7
+ ],
8
+ theme: {
9
+ extend: {
10
+ colors: {
11
+ primary: '#00ff88',
12
+ secondary: '#00bdff',
13
+ dark: '#0a0a0a',
14
+ },
15
+ fontFamily: {
16
+ sans: ['Outfit', 'sans-serif'],
17
+ },
18
+ },
19
+ },
20
+ plugins: [],
21
+ }
@@ -0,0 +1,47 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>About Free</title>
8
+ <style>
9
+ body {
10
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
11
+ display: flex;
12
+ justify-content: center;
13
+ align-items: center;
14
+ height: 100vh;
15
+ margin: 0;
16
+ background: #f0f2f5;
17
+ }
18
+
19
+ .card {
20
+ background: white;
21
+ padding: 2rem;
22
+ border-radius: 12px;
23
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
24
+ text-align: center;
25
+ }
26
+
27
+ h1 {
28
+ color: #1a73e8;
29
+ }
30
+
31
+ a {
32
+ color: #1a73e8;
33
+ text-decoration: none;
34
+ font-weight: bold;
35
+ }
36
+ </style>
37
+ </head>
38
+
39
+ <body>
40
+ <div class="card">
41
+ <h1>About Free Framework</h1>
42
+ <p>Free is a modern full-stack web framework built for speed and simplicity.</p>
43
+ <p><a href="/">Back to Home</a></p>
44
+ </div>
45
+ </body>
46
+
47
+ </html>
@@ -0,0 +1,52 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Welcome to Free</title>
8
+ <meta name="csrf-token" content="<%= csrfToken %>">
9
+ <script src="/free-runtime.js" defer></script>
10
+ <style>
11
+ body {
12
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
13
+ display: flex;
14
+ justify-content: center;
15
+ align-items: center;
16
+ height: 100vh;
17
+ margin: 0;
18
+ background: #f0f2f5;
19
+ }
20
+
21
+ .card {
22
+ background: white;
23
+ padding: 2rem;
24
+ border-radius: 12px;
25
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
26
+ text-align: center;
27
+ }
28
+
29
+ h1 {
30
+ color: #1a73e8;
31
+ }
32
+
33
+ p {
34
+ color: #5f6368;
35
+ }
36
+ </style>
37
+ </head>
38
+
39
+ <body>
40
+ <div class="card">
41
+ <h1>Welcome to Free Framework</h1>
42
+ <p>Your full-stack application is up and running!</p>
43
+ <p>Edit <code>app/routes.free</code> to get started.</p>
44
+
45
+ <div style="margin-top: 2rem; padding: 1rem; border: 1px dashed #ccc;">
46
+ <h3>Interactive Demo</h3>
47
+ <%- renderComponent('Counter') %>
48
+ </div>
49
+ </div>
50
+ </body>
51
+
52
+ </html>
@@ -0,0 +1,144 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <title>Login</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;700;900&display=swap" rel="stylesheet">
8
+ <style>
9
+ * {
10
+ box-sizing: border-box;
11
+ margin: 0;
12
+ padding: 0
13
+ }
14
+
15
+ body {
16
+ min-height: 100vh;
17
+ background: #050505;
18
+ color: white;
19
+ font-family: 'Outfit', sans-serif;
20
+ display: flex;
21
+ flex-direction: column;
22
+ align-items: center;
23
+ justify-content: center
24
+ }
25
+
26
+ .card {
27
+ background: #111;
28
+ border: 1px solid #222;
29
+ border-radius: 20px;
30
+ padding: 3rem;
31
+ width: 100%;
32
+ max-width: 400px
33
+ }
34
+
35
+ h1 {
36
+ font-size: 2rem;
37
+ font-weight: 900;
38
+ margin-bottom: 0.5rem;
39
+ background: linear-gradient(90deg, #00ff88, #00bdff);
40
+ -webkit-background-clip: text;
41
+ -webkit-text-fill-color: transparent
42
+ }
43
+
44
+ p {
45
+ color: #666;
46
+ margin-bottom: 2rem;
47
+ font-size: 0.9rem
48
+ }
49
+
50
+ input {
51
+ width: 100%;
52
+ padding: 1rem;
53
+ border-radius: 10px;
54
+ background: #000;
55
+ border: 1px solid #333;
56
+ color: white;
57
+ margin-bottom: 1rem;
58
+ font-size: 1rem;
59
+ outline: none;
60
+ transition: 0.2s
61
+ }
62
+
63
+ input:focus {
64
+ border-color: #00ff88
65
+ }
66
+
67
+ button {
68
+ width: 100%;
69
+ padding: 1rem;
70
+ background: #00ff88;
71
+ color: #000;
72
+ font-weight: 900;
73
+ border: none;
74
+ border-radius: 10px;
75
+ cursor: pointer;
76
+ font-size: 1rem;
77
+ transition: 0.2s
78
+ }
79
+
80
+ button:hover {
81
+ background: #00e077
82
+ }
83
+
84
+ .footer {
85
+ margin-top: 1.5rem;
86
+ text-align: center;
87
+ color: #555;
88
+ font-size: 0.9rem
89
+ }
90
+
91
+ a {
92
+ color: #00ff88;
93
+ text-decoration: none
94
+ }
95
+
96
+ .err {
97
+ background: #ff336622;
98
+ border: 1px solid #ff3366;
99
+ color: #ff3366;
100
+ padding: 0.8rem;
101
+ border-radius: 8px;
102
+ margin-bottom: 1rem;
103
+ font-size: 0.9rem;
104
+ display: none
105
+ }
106
+ </style>
107
+ </head>
108
+
109
+ <body>
110
+ <div class="card">
111
+ <h1>Welcome back</h1>
112
+ <p>Login to your account to continue</p>
113
+ <div class="err" id="err"></div>
114
+ <form onsubmit="doLogin(event)">
115
+ <input type="email" id="email" placeholder="Email" required>
116
+ <input type="password" id="password" placeholder="Password" required>
117
+ <button type="submit">Login</button>
118
+ </form>
119
+ <div class="footer">No account? <a href="{{registerPath}}">Register &rarr;</a></div>
120
+ </div>
121
+ <script>
122
+ async function doLogin(e) {
123
+ e.preventDefault();
124
+ const r = await fetch('/_free/auth/login', {
125
+ method: 'POST',
126
+ headers: { 'Content-Type': 'application/json' },
127
+ body: JSON.stringify({
128
+ email: document.getElementById('email').value,
129
+ password: document.getElementById('password').value
130
+ })
131
+ });
132
+ const d = await r.json();
133
+ if (d.success) {
134
+ window.location = '/dashboard';
135
+ } else {
136
+ const el = document.getElementById('err');
137
+ el.textContent = d.error || 'Login failed';
138
+ el.style.display = 'block';
139
+ }
140
+ }
141
+ </script>
142
+ </body>
143
+
144
+ </html>