@adriankulik/create-fullstack-app 1.10.0 → 1.11.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 +2 -1
- package/cli/build-date.js +1 -1
- package/cli/index.js +18 -2
- package/package.json +3 -1
- package/templates/backend/dotnet/Program.cs +26 -4
- package/templates/backend/dotnet/dotnet.csproj +4 -0
- package/templates/backend/fastapi/main.py +22 -5
- package/templates/backend/fastapi/requirements.txt +6 -5
- package/templates/backend/flask/main.py +21 -3
- package/templates/backend/flask/requirements.txt +2 -1
- package/templates/backend/nodejs/package-lock.json +161 -1
- package/templates/backend/nodejs/package.json +3 -1
- package/templates/backend/nodejs/src/index.ts +13 -2
- package/templates/base/README.md +5 -3
- package/templates/base/database/README +1 -0
- package/templates/base/database/alembic.ini +147 -0
- package/templates/base/database/env.py +78 -0
- package/templates/base/database/requirements.txt +3 -0
- package/templates/base/database/script.py.mako +28 -0
- package/templates/base/database/versions/a6bb6e434c98_create_calculations_table.py +31 -0
- package/templates/base/docker-compose.yml +10 -0
- package/templates/base/start.sh +23 -0
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Before running the CLI or the scaffolded applications, ensure you have the follo
|
|
|
12
12
|
|
|
13
13
|
- **Node.js**: v20 or newer
|
|
14
14
|
- **npm**: v10 or newer
|
|
15
|
-
- **Python**:
|
|
15
|
+
- **Python**: The newest stable release _(only required for FastAPI / Flask backends. We frequently update frameworks to their latest versions, so using older Pythons may cause pip install errors)_
|
|
16
16
|
- **[.NET 9 SDK](https://aka.ms/dotnet/download)** _(only required for the .NET backend — the CLI will offer to install it automatically on macOS/Linux if not found)_
|
|
17
17
|
|
|
18
18
|
## Quickstart
|
|
@@ -39,6 +39,7 @@ You will be prompted to choose a project name, your preferred frontend, and back
|
|
|
39
39
|
- Flask (v3.1.3)
|
|
40
40
|
- .NET (v10.0.11)
|
|
41
41
|
- Node.js Express (v5.2.1)
|
|
42
|
+
- **Database**: PostgreSQL (v15) with Alembic (v1.16.5), SQLAlchemy (v2.0.52), and Psycopg2 (v2.9.12).
|
|
42
43
|
- **Opinionated Defaults**: We bake in sensible, predefined choices (e.g., Angular uses `zone.js`, testing is unified under Playwright and framework-native test runners).
|
|
43
44
|
- **Unified Scripts**: `start.sh`, `test.sh`, and `lint.sh` available out of the box to manage both frontend and backend seamlessly.
|
|
44
45
|
- **CI/CD Ready**: Includes a pre-configured `.github/workflows/cli-e2e.yml` that tests both ends. _Tip: To enforce this, enable branch protection in your GitHub repository settings and require the "test" status check to pass._
|
package/cli/build-date.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = '2026-08-
|
|
1
|
+
module.exports = '2026-08-22 22:04:01';
|
package/cli/index.js
CHANGED
|
@@ -117,6 +117,7 @@ async function main() {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
console.log(pc.blue(`\nScaffolding project in ${targetDir}...`));
|
|
120
|
+
console.log(pc.blue(`Configuring PostgreSQL (v15) database with Alembic, SQLAlchemy, and Psycopg2...`));
|
|
120
121
|
|
|
121
122
|
// Determine paths to templates relative to the CLI script
|
|
122
123
|
const templatesDir = path.resolve(__dirname, "../templates");
|
|
@@ -195,8 +196,23 @@ async function main() {
|
|
|
195
196
|
} catch (e) {
|
|
196
197
|
console.error(
|
|
197
198
|
pc.red(
|
|
198
|
-
" Failed to set up Python virtual environment or install dependencies."
|
|
199
|
-
)
|
|
199
|
+
"\n Failed to set up Python virtual environment or install dependencies."
|
|
200
|
+
)
|
|
201
|
+
);
|
|
202
|
+
console.error(
|
|
203
|
+
pc.yellow(
|
|
204
|
+
" TIP: We frequently update templates to use the latest framework versions."
|
|
205
|
+
)
|
|
206
|
+
);
|
|
207
|
+
console.error(
|
|
208
|
+
pc.yellow(
|
|
209
|
+
" If pip failed to find a matching version, your default 'python3' version might be too old."
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
console.error(
|
|
213
|
+
pc.yellow(
|
|
214
|
+
" Please try updating to the newest version of Python and run this again."
|
|
215
|
+
)
|
|
200
216
|
);
|
|
201
217
|
process.exit(1);
|
|
202
218
|
}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.11.0",
|
|
7
7
|
"description": "A CLI tool for scaffolding a full-stack web application with your choice of frontend and backend technologies.",
|
|
8
8
|
"main": "cli/index.js",
|
|
9
9
|
"bin": {
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@playwright/test": "^1.62.1",
|
|
26
|
+
"@types/pg": "^8.23.1",
|
|
27
|
+
"pg": "^8.23.0",
|
|
26
28
|
"vitest": "^4.1.11",
|
|
27
29
|
"wait-on": "^9.1.0"
|
|
28
30
|
},
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using Microsoft.AspNetCore.Mvc;
|
|
2
|
+
using Npgsql;
|
|
2
3
|
|
|
3
4
|
var builder = WebApplication.CreateBuilder(args);
|
|
4
5
|
|
|
@@ -15,12 +16,33 @@ var app = builder.Build();
|
|
|
15
16
|
|
|
16
17
|
app.UseCors();
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
var dbUrl = Environment.GetEnvironmentVariable("DATABASE_URL") ?? "postgresql://user:password@localhost:5432/appdb";
|
|
20
|
+
var connStr = dbUrl;
|
|
21
|
+
if (dbUrl.StartsWith("postgres://") || dbUrl.StartsWith("postgresql://"))
|
|
19
22
|
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
var uri = new Uri(dbUrl);
|
|
24
|
+
var userInfo = uri.UserInfo.Split(':');
|
|
25
|
+
connStr = $"Host={uri.Host};Port={uri.Port};Username={userInfo[0]};Password={userInfo[1]};Database={uri.LocalPath.Substring(1)}";
|
|
26
|
+
}
|
|
23
27
|
|
|
28
|
+
app.MapPost("/api/multiply", async ([FromBody] MultiplyRequest request) =>
|
|
29
|
+
{
|
|
30
|
+
var result = request.Number * 2;
|
|
31
|
+
try
|
|
32
|
+
{
|
|
33
|
+
await using var dataSource = NpgsqlDataSource.Create(connStr);
|
|
34
|
+
await using var cmd = dataSource.CreateCommand("INSERT INTO calculations (input_number, result) VALUES (@input_number, @result)");
|
|
35
|
+
cmd.Parameters.AddWithValue("input_number", request.Number);
|
|
36
|
+
cmd.Parameters.AddWithValue("result", result);
|
|
37
|
+
await cmd.ExecuteNonQueryAsync();
|
|
38
|
+
}
|
|
39
|
+
catch (Exception e)
|
|
40
|
+
{
|
|
41
|
+
Console.WriteLine($"Error saving to db: {e.Message}");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return new { result };
|
|
45
|
+
});
|
|
24
46
|
|
|
25
47
|
app.Run("http://localhost:8000");
|
|
26
48
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from fastapi import FastAPI
|
|
2
3
|
from fastapi.middleware.cors import CORSMiddleware
|
|
3
4
|
from pydantic import BaseModel
|
|
5
|
+
import psycopg2
|
|
4
6
|
|
|
5
7
|
app = FastAPI()
|
|
6
8
|
|
|
7
|
-
# Allow CORS for the frontend
|
|
8
9
|
app.add_middleware(
|
|
9
10
|
CORSMiddleware,
|
|
10
|
-
allow_origins=["*"],
|
|
11
|
+
allow_origins=["*"],
|
|
11
12
|
allow_credentials=True,
|
|
12
13
|
allow_methods=["*"],
|
|
13
14
|
allow_headers=["*"],
|
|
@@ -19,8 +20,24 @@ class MultiplyRequest(BaseModel):
|
|
|
19
20
|
class MultiplyResponse(BaseModel):
|
|
20
21
|
result: float
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
def multiply_number(request: MultiplyRequest):
|
|
24
|
-
return MultiplyResponse(result=request.number * 2)
|
|
23
|
+
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://user:password@localhost:5432/appdb")
|
|
25
24
|
|
|
25
|
+
def save_calculation(number: float, result: float):
|
|
26
|
+
conn = psycopg2.connect(DATABASE_URL)
|
|
27
|
+
cursor = conn.cursor()
|
|
28
|
+
cursor.execute(
|
|
29
|
+
"INSERT INTO calculations (input_number, result) VALUES (%s, %s)",
|
|
30
|
+
(number, result)
|
|
31
|
+
)
|
|
32
|
+
conn.commit()
|
|
33
|
+
cursor.close()
|
|
34
|
+
conn.close()
|
|
26
35
|
|
|
36
|
+
@app.post("/api/multiply", response_model=MultiplyResponse)
|
|
37
|
+
def multiply_number(request: MultiplyRequest):
|
|
38
|
+
result = request.number * 2
|
|
39
|
+
try:
|
|
40
|
+
save_calculation(request.number, result)
|
|
41
|
+
except psycopg2.Error as e:
|
|
42
|
+
print(f"Error saving to db: {e}")
|
|
43
|
+
return MultiplyResponse(result=result)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
fastapi
|
|
2
|
-
uvicorn
|
|
3
|
-
pytest
|
|
4
|
-
httpx
|
|
5
|
-
ruff
|
|
1
|
+
fastapi
|
|
2
|
+
uvicorn
|
|
3
|
+
pytest
|
|
4
|
+
httpx
|
|
5
|
+
ruff
|
|
6
|
+
psycopg2-binary
|
|
@@ -1,9 +1,24 @@
|
|
|
1
|
+
import os
|
|
1
2
|
from flask import Flask, request, jsonify
|
|
2
3
|
from flask_cors import CORS
|
|
4
|
+
import psycopg2
|
|
3
5
|
|
|
4
6
|
app = Flask(__name__)
|
|
5
7
|
CORS(app)
|
|
6
8
|
|
|
9
|
+
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://user:password@localhost:5432/appdb")
|
|
10
|
+
|
|
11
|
+
def save_calculation(number: float, result: float):
|
|
12
|
+
conn = psycopg2.connect(DATABASE_URL)
|
|
13
|
+
cursor = conn.cursor()
|
|
14
|
+
cursor.execute(
|
|
15
|
+
"INSERT INTO calculations (input_number, result) VALUES (%s, %s)",
|
|
16
|
+
(number, result)
|
|
17
|
+
)
|
|
18
|
+
conn.commit()
|
|
19
|
+
cursor.close()
|
|
20
|
+
conn.close()
|
|
21
|
+
|
|
7
22
|
@app.route("/api/multiply", methods=["POST"])
|
|
8
23
|
def multiply_number():
|
|
9
24
|
data = request.get_json()
|
|
@@ -12,11 +27,14 @@ def multiply_number():
|
|
|
12
27
|
|
|
13
28
|
try:
|
|
14
29
|
number = float(data["number"])
|
|
15
|
-
|
|
30
|
+
result = number * 2
|
|
31
|
+
try:
|
|
32
|
+
save_calculation(number, result)
|
|
33
|
+
except psycopg2.Error as e:
|
|
34
|
+
print(f"Error saving to db: {e}")
|
|
35
|
+
return jsonify({"result": result})
|
|
16
36
|
except ValueError:
|
|
17
37
|
return jsonify({"error": "Invalid number"}), 400
|
|
18
38
|
|
|
19
|
-
|
|
20
|
-
|
|
21
39
|
if __name__ == "__main__":
|
|
22
40
|
app.run(port=8000)
|
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"cors": "^2.8.6",
|
|
12
|
-
"express": "^5.2.1"
|
|
12
|
+
"express": "^5.2.1",
|
|
13
|
+
"pg": "^8.23.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@eslint/js": "^10.0.1",
|
|
16
17
|
"@types/cors": "^2.8.19",
|
|
17
18
|
"@types/express": "^5.0.6",
|
|
18
19
|
"@types/node": "^26.2.0",
|
|
20
|
+
"@types/pg": "^8.23.1",
|
|
19
21
|
"@types/supertest": "^7.2.1",
|
|
20
22
|
"eslint": "^10.4.0",
|
|
21
23
|
"supertest": "^7.2.2",
|
|
@@ -1114,6 +1116,18 @@
|
|
|
1114
1116
|
"undici-types": "~8.3.0"
|
|
1115
1117
|
}
|
|
1116
1118
|
},
|
|
1119
|
+
"node_modules/@types/pg": {
|
|
1120
|
+
"version": "8.23.1",
|
|
1121
|
+
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.23.1.tgz",
|
|
1122
|
+
"integrity": "sha512-fKVHpikPdg4GKks3JuLEhvwSyvwzF23hnabPy6DD8ljVbC7+6J5dQzdv4arV6jqq57djnMgs1HKBxX4P8aBI3A==",
|
|
1123
|
+
"dev": true,
|
|
1124
|
+
"license": "MIT",
|
|
1125
|
+
"dependencies": {
|
|
1126
|
+
"@types/node": "*",
|
|
1127
|
+
"pg-protocol": "*",
|
|
1128
|
+
"pg-types": "^2.2.0"
|
|
1129
|
+
}
|
|
1130
|
+
},
|
|
1117
1131
|
"node_modules/@types/qs": {
|
|
1118
1132
|
"version": "6.15.1",
|
|
1119
1133
|
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.15.1.tgz",
|
|
@@ -3332,6 +3346,95 @@
|
|
|
3332
3346
|
"dev": true,
|
|
3333
3347
|
"license": "MIT"
|
|
3334
3348
|
},
|
|
3349
|
+
"node_modules/pg": {
|
|
3350
|
+
"version": "8.23.0",
|
|
3351
|
+
"resolved": "https://registry.npmjs.org/pg/-/pg-8.23.0.tgz",
|
|
3352
|
+
"integrity": "sha512-Ip2EQCngowJLGOfCwkFhPXU7/ljlhn6Rxlmy4XYfL2Y+vyRM59+8uR2xqRWKdYmbXmxCFOAmKxBuSUCdF34qLg==",
|
|
3353
|
+
"license": "MIT",
|
|
3354
|
+
"dependencies": {
|
|
3355
|
+
"pg-connection-string": "^2.14.0",
|
|
3356
|
+
"pg-pool": "^3.14.0",
|
|
3357
|
+
"pg-protocol": "^1.16.0",
|
|
3358
|
+
"pg-types": "2.2.0",
|
|
3359
|
+
"pgpass": "1.0.5"
|
|
3360
|
+
},
|
|
3361
|
+
"engines": {
|
|
3362
|
+
"node": ">= 16.0.0"
|
|
3363
|
+
},
|
|
3364
|
+
"optionalDependencies": {
|
|
3365
|
+
"pg-cloudflare": "^1.4.0"
|
|
3366
|
+
},
|
|
3367
|
+
"peerDependencies": {
|
|
3368
|
+
"pg-native": ">=3.0.1"
|
|
3369
|
+
},
|
|
3370
|
+
"peerDependenciesMeta": {
|
|
3371
|
+
"pg-native": {
|
|
3372
|
+
"optional": true
|
|
3373
|
+
}
|
|
3374
|
+
}
|
|
3375
|
+
},
|
|
3376
|
+
"node_modules/pg-cloudflare": {
|
|
3377
|
+
"version": "1.4.0",
|
|
3378
|
+
"resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.4.0.tgz",
|
|
3379
|
+
"integrity": "sha512-Vo7z/6rrQYxpNRylp4Tlob2elzbh+N/MOQbxFVWCxS7oEx6jF53GTJFxK2WWpKuBRkmiin4Mt+xofFDjx09R0A==",
|
|
3380
|
+
"license": "MIT",
|
|
3381
|
+
"optional": true
|
|
3382
|
+
},
|
|
3383
|
+
"node_modules/pg-connection-string": {
|
|
3384
|
+
"version": "2.14.0",
|
|
3385
|
+
"resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.14.0.tgz",
|
|
3386
|
+
"integrity": "sha512-XwWDGcLRGCXAR8F/AM5bG7Q+A3Wm2s6QeEjlOKZLlH3UYcguiqCWKyWXVag5TLTIjR7oOJUY8kcADaZgWPyLeg==",
|
|
3387
|
+
"license": "MIT"
|
|
3388
|
+
},
|
|
3389
|
+
"node_modules/pg-int8": {
|
|
3390
|
+
"version": "1.0.1",
|
|
3391
|
+
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
|
|
3392
|
+
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
|
|
3393
|
+
"license": "ISC",
|
|
3394
|
+
"engines": {
|
|
3395
|
+
"node": ">=4.0.0"
|
|
3396
|
+
}
|
|
3397
|
+
},
|
|
3398
|
+
"node_modules/pg-pool": {
|
|
3399
|
+
"version": "3.14.0",
|
|
3400
|
+
"resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.14.0.tgz",
|
|
3401
|
+
"integrity": "sha512-gKtPkFdQPU3DksooVLi9LsjZxrsBUZIpa+7aVx+LV5pNh0KzP4Zleud2po+ConrxbuXGBJ6Hfer6hdgpIBpBaw==",
|
|
3402
|
+
"license": "MIT",
|
|
3403
|
+
"peerDependencies": {
|
|
3404
|
+
"pg": ">=8.0"
|
|
3405
|
+
}
|
|
3406
|
+
},
|
|
3407
|
+
"node_modules/pg-protocol": {
|
|
3408
|
+
"version": "1.16.0",
|
|
3409
|
+
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.16.0.tgz",
|
|
3410
|
+
"integrity": "sha512-sILXutLVjCLjcDuOmvhX5e2Z4cS5qG/6Bu3VkpFwdf/633ElGLpEh9bgmuI5I4sqKqkifQiGyiCcx1HdtrK7tg==",
|
|
3411
|
+
"license": "MIT"
|
|
3412
|
+
},
|
|
3413
|
+
"node_modules/pg-types": {
|
|
3414
|
+
"version": "2.2.0",
|
|
3415
|
+
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
|
|
3416
|
+
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
|
|
3417
|
+
"license": "MIT",
|
|
3418
|
+
"dependencies": {
|
|
3419
|
+
"pg-int8": "1.0.1",
|
|
3420
|
+
"postgres-array": "~2.0.0",
|
|
3421
|
+
"postgres-bytea": "~1.0.0",
|
|
3422
|
+
"postgres-date": "~1.0.4",
|
|
3423
|
+
"postgres-interval": "^1.1.0"
|
|
3424
|
+
},
|
|
3425
|
+
"engines": {
|
|
3426
|
+
"node": ">=4"
|
|
3427
|
+
}
|
|
3428
|
+
},
|
|
3429
|
+
"node_modules/pgpass": {
|
|
3430
|
+
"version": "1.0.5",
|
|
3431
|
+
"resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz",
|
|
3432
|
+
"integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==",
|
|
3433
|
+
"license": "MIT",
|
|
3434
|
+
"dependencies": {
|
|
3435
|
+
"split2": "^4.1.0"
|
|
3436
|
+
}
|
|
3437
|
+
},
|
|
3335
3438
|
"node_modules/picocolors": {
|
|
3336
3439
|
"version": "1.1.1",
|
|
3337
3440
|
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz",
|
|
@@ -3381,6 +3484,45 @@
|
|
|
3381
3484
|
"node": "^10 || ^12 || >=14"
|
|
3382
3485
|
}
|
|
3383
3486
|
},
|
|
3487
|
+
"node_modules/postgres-array": {
|
|
3488
|
+
"version": "2.0.0",
|
|
3489
|
+
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
|
|
3490
|
+
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
|
|
3491
|
+
"license": "MIT",
|
|
3492
|
+
"engines": {
|
|
3493
|
+
"node": ">=4"
|
|
3494
|
+
}
|
|
3495
|
+
},
|
|
3496
|
+
"node_modules/postgres-bytea": {
|
|
3497
|
+
"version": "1.0.1",
|
|
3498
|
+
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.1.tgz",
|
|
3499
|
+
"integrity": "sha512-5+5HqXnsZPE65IJZSMkZtURARZelel2oXUEO8rH83VS/hxH5vv1uHquPg5wZs8yMAfdv971IU+kcPUczi7NVBQ==",
|
|
3500
|
+
"license": "MIT",
|
|
3501
|
+
"engines": {
|
|
3502
|
+
"node": ">=0.10.0"
|
|
3503
|
+
}
|
|
3504
|
+
},
|
|
3505
|
+
"node_modules/postgres-date": {
|
|
3506
|
+
"version": "1.0.7",
|
|
3507
|
+
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
|
|
3508
|
+
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
|
|
3509
|
+
"license": "MIT",
|
|
3510
|
+
"engines": {
|
|
3511
|
+
"node": ">=0.10.0"
|
|
3512
|
+
}
|
|
3513
|
+
},
|
|
3514
|
+
"node_modules/postgres-interval": {
|
|
3515
|
+
"version": "1.2.0",
|
|
3516
|
+
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
|
|
3517
|
+
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
|
|
3518
|
+
"license": "MIT",
|
|
3519
|
+
"dependencies": {
|
|
3520
|
+
"xtend": "^4.0.0"
|
|
3521
|
+
},
|
|
3522
|
+
"engines": {
|
|
3523
|
+
"node": ">=0.10.0"
|
|
3524
|
+
}
|
|
3525
|
+
},
|
|
3384
3526
|
"node_modules/prelude-ls": {
|
|
3385
3527
|
"version": "1.2.1",
|
|
3386
3528
|
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
|
|
@@ -3714,6 +3856,15 @@
|
|
|
3714
3856
|
"node": ">=0.10.0"
|
|
3715
3857
|
}
|
|
3716
3858
|
},
|
|
3859
|
+
"node_modules/split2": {
|
|
3860
|
+
"version": "4.2.0",
|
|
3861
|
+
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
|
|
3862
|
+
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
|
|
3863
|
+
"license": "ISC",
|
|
3864
|
+
"engines": {
|
|
3865
|
+
"node": ">= 10.x"
|
|
3866
|
+
}
|
|
3867
|
+
},
|
|
3717
3868
|
"node_modules/stackback": {
|
|
3718
3869
|
"version": "0.0.2",
|
|
3719
3870
|
"resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz",
|
|
@@ -4230,6 +4381,15 @@
|
|
|
4230
4381
|
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
|
|
4231
4382
|
"license": "ISC"
|
|
4232
4383
|
},
|
|
4384
|
+
"node_modules/xtend": {
|
|
4385
|
+
"version": "4.0.2",
|
|
4386
|
+
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
|
|
4387
|
+
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
|
|
4388
|
+
"license": "MIT",
|
|
4389
|
+
"engines": {
|
|
4390
|
+
"node": ">=0.4"
|
|
4391
|
+
}
|
|
4392
|
+
},
|
|
4233
4393
|
"node_modules/yocto-queue": {
|
|
4234
4394
|
"version": "0.1.0",
|
|
4235
4395
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
|
@@ -9,13 +9,15 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"cors": "^2.8.6",
|
|
12
|
-
"express": "^5.2.1"
|
|
12
|
+
"express": "^5.2.1",
|
|
13
|
+
"pg": "^8.23.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@eslint/js": "^10.0.1",
|
|
16
17
|
"@types/cors": "^2.8.19",
|
|
17
18
|
"@types/express": "^5.0.6",
|
|
18
19
|
"@types/node": "^26.2.0",
|
|
20
|
+
"@types/pg": "^8.23.1",
|
|
19
21
|
"@types/supertest": "^7.2.1",
|
|
20
22
|
"eslint": "^10.4.0",
|
|
21
23
|
"supertest": "^7.2.2",
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import express, { Request, Response } from 'express';
|
|
2
2
|
import cors from 'cors';
|
|
3
|
+
import { Pool } from 'pg';
|
|
3
4
|
|
|
4
5
|
const app = express();
|
|
5
6
|
app.use(cors());
|
|
6
7
|
app.use(express.json());
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const pool = new Pool({
|
|
10
|
+
connectionString: process.env.DATABASE_URL || 'postgresql://user:password@localhost:5432/appdb'
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
app.post('/api/multiply', async (req: Request, res: Response) => {
|
|
9
14
|
const { number } = req.body;
|
|
10
15
|
if (typeof number !== 'number') {
|
|
11
16
|
return res.status(400).json({ error: 'Invalid number' });
|
|
12
17
|
}
|
|
13
|
-
|
|
18
|
+
const result = number * 2;
|
|
19
|
+
try {
|
|
20
|
+
await pool.query('INSERT INTO calculations (input_number, result) VALUES ($1, $2)', [number, result]);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('Error saving to db:', error);
|
|
23
|
+
}
|
|
24
|
+
return res.json({ result });
|
|
14
25
|
});
|
|
15
26
|
|
|
16
27
|
if (process.env.NODE_ENV !== 'test') {
|
package/templates/base/README.md
CHANGED
|
@@ -17,13 +17,15 @@ chmod +x *.sh
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
### Running the App
|
|
20
|
-
|
|
21
|
-
To start
|
|
22
|
-
|
|
20
|
+
|
|
21
|
+
To start the database, backend, and frontend development servers, simply run:
|
|
22
|
+
|
|
23
23
|
```bash
|
|
24
24
|
./start.sh
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
**Database Note:** The `start.sh` script will automatically spin up a **PostgreSQL (v15)** database using Docker Compose, and it will run **Alembic (v1.16.5)** (using SQLAlchemy v2.0.52 and Psycopg2 v2.9.12) to handle migrations before starting the rest of your app.
|
|
28
|
+
|
|
27
29
|
### Testing and Linting
|
|
28
30
|
|
|
29
31
|
- **Test:** Run all frontend and backend tests:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Generic single-database configuration.
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# A generic, single database configuration.
|
|
2
|
+
|
|
3
|
+
[alembic]
|
|
4
|
+
# path to migration scripts.
|
|
5
|
+
# this is typically a path given in POSIX (e.g. forward slashes)
|
|
6
|
+
# format, relative to the token %(here)s which refers to the location of this
|
|
7
|
+
# ini file
|
|
8
|
+
script_location = %(here)s
|
|
9
|
+
|
|
10
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
|
11
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
|
12
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
|
13
|
+
# for all available tokens
|
|
14
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
|
15
|
+
|
|
16
|
+
# sys.path path, will be prepended to sys.path if present.
|
|
17
|
+
# defaults to the current working directory. for multiple paths, the path separator
|
|
18
|
+
# is defined by "path_separator" below.
|
|
19
|
+
prepend_sys_path = .
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# timezone to use when rendering the date within the migration file
|
|
23
|
+
# as well as the filename.
|
|
24
|
+
# If specified, requires the python>=3.9 or backports.zoneinfo library and tzdata library.
|
|
25
|
+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
|
26
|
+
# string value is passed to ZoneInfo()
|
|
27
|
+
# leave blank for localtime
|
|
28
|
+
# timezone =
|
|
29
|
+
|
|
30
|
+
# max length of characters to apply to the "slug" field
|
|
31
|
+
# truncate_slug_length = 40
|
|
32
|
+
|
|
33
|
+
# set to 'true' to run the environment during
|
|
34
|
+
# the 'revision' command, regardless of autogenerate
|
|
35
|
+
# revision_environment = false
|
|
36
|
+
|
|
37
|
+
# set to 'true' to allow .pyc and .pyo files without
|
|
38
|
+
# a source .py file to be detected as revisions in the
|
|
39
|
+
# versions/ directory
|
|
40
|
+
# sourceless = false
|
|
41
|
+
|
|
42
|
+
# version location specification; This defaults
|
|
43
|
+
# to <script_location>/versions. When using multiple version
|
|
44
|
+
# directories, initial revisions must be specified with --version-path.
|
|
45
|
+
# The path separator used here should be the separator specified by "path_separator"
|
|
46
|
+
# below.
|
|
47
|
+
# version_locations = %(here)s/bar:%(here)s/bat:%(here)s/alembic/versions
|
|
48
|
+
|
|
49
|
+
# path_separator; This indicates what character is used to split lists of file
|
|
50
|
+
# paths, including version_locations and prepend_sys_path within configparser
|
|
51
|
+
# files such as alembic.ini.
|
|
52
|
+
# The default rendered in new alembic.ini files is "os", which uses os.pathsep
|
|
53
|
+
# to provide os-dependent path splitting.
|
|
54
|
+
#
|
|
55
|
+
# Note that in order to support legacy alembic.ini files, this default does NOT
|
|
56
|
+
# take place if path_separator is not present in alembic.ini. If this
|
|
57
|
+
# option is omitted entirely, fallback logic is as follows:
|
|
58
|
+
#
|
|
59
|
+
# 1. Parsing of the version_locations option falls back to using the legacy
|
|
60
|
+
# "version_path_separator" key, which if absent then falls back to the legacy
|
|
61
|
+
# behavior of splitting on spaces and/or commas.
|
|
62
|
+
# 2. Parsing of the prepend_sys_path option falls back to the legacy
|
|
63
|
+
# behavior of splitting on spaces, commas, or colons.
|
|
64
|
+
#
|
|
65
|
+
# Valid values for path_separator are:
|
|
66
|
+
#
|
|
67
|
+
# path_separator = :
|
|
68
|
+
# path_separator = ;
|
|
69
|
+
# path_separator = space
|
|
70
|
+
# path_separator = newline
|
|
71
|
+
#
|
|
72
|
+
# Use os.pathsep. Default configuration used for new projects.
|
|
73
|
+
path_separator = os
|
|
74
|
+
|
|
75
|
+
# set to 'true' to search source files recursively
|
|
76
|
+
# in each "version_locations" directory
|
|
77
|
+
# new in Alembic version 1.10
|
|
78
|
+
# recursive_version_locations = false
|
|
79
|
+
|
|
80
|
+
# the output encoding used when revision files
|
|
81
|
+
# are written from script.py.mako
|
|
82
|
+
# output_encoding = utf-8
|
|
83
|
+
|
|
84
|
+
# database URL. This is consumed by the user-maintained env.py script only.
|
|
85
|
+
# other means of configuring database URLs may be customized within the env.py
|
|
86
|
+
# file.
|
|
87
|
+
sqlalchemy.url = postgresql://user:password@localhost:5432/appdb
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
[post_write_hooks]
|
|
91
|
+
# post_write_hooks defines scripts or Python functions that are run
|
|
92
|
+
# on newly generated revision scripts. See the documentation for further
|
|
93
|
+
# detail and examples
|
|
94
|
+
|
|
95
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
|
96
|
+
# hooks = black
|
|
97
|
+
# black.type = console_scripts
|
|
98
|
+
# black.entrypoint = black
|
|
99
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
|
100
|
+
|
|
101
|
+
# lint with attempts to fix using "ruff" - use the module runner, against the "ruff" module
|
|
102
|
+
# hooks = ruff
|
|
103
|
+
# ruff.type = module
|
|
104
|
+
# ruff.module = ruff
|
|
105
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
106
|
+
|
|
107
|
+
# Alternatively, use the exec runner to execute a binary found on your PATH
|
|
108
|
+
# hooks = ruff
|
|
109
|
+
# ruff.type = exec
|
|
110
|
+
# ruff.executable = ruff
|
|
111
|
+
# ruff.options = check --fix REVISION_SCRIPT_FILENAME
|
|
112
|
+
|
|
113
|
+
# Logging configuration. This is also consumed by the user-maintained
|
|
114
|
+
# env.py script only.
|
|
115
|
+
[loggers]
|
|
116
|
+
keys = root,sqlalchemy,alembic
|
|
117
|
+
|
|
118
|
+
[handlers]
|
|
119
|
+
keys = console
|
|
120
|
+
|
|
121
|
+
[formatters]
|
|
122
|
+
keys = generic
|
|
123
|
+
|
|
124
|
+
[logger_root]
|
|
125
|
+
level = WARNING
|
|
126
|
+
handlers = console
|
|
127
|
+
qualname =
|
|
128
|
+
|
|
129
|
+
[logger_sqlalchemy]
|
|
130
|
+
level = WARNING
|
|
131
|
+
handlers =
|
|
132
|
+
qualname = sqlalchemy.engine
|
|
133
|
+
|
|
134
|
+
[logger_alembic]
|
|
135
|
+
level = INFO
|
|
136
|
+
handlers =
|
|
137
|
+
qualname = alembic
|
|
138
|
+
|
|
139
|
+
[handler_console]
|
|
140
|
+
class = StreamHandler
|
|
141
|
+
args = (sys.stderr,)
|
|
142
|
+
level = NOTSET
|
|
143
|
+
formatter = generic
|
|
144
|
+
|
|
145
|
+
[formatter_generic]
|
|
146
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
|
147
|
+
datefmt = %H:%M:%S
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
from logging.config import fileConfig
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import engine_from_config
|
|
4
|
+
from sqlalchemy import pool
|
|
5
|
+
|
|
6
|
+
from alembic import context
|
|
7
|
+
|
|
8
|
+
# this is the Alembic Config object, which provides
|
|
9
|
+
# access to the values within the .ini file in use.
|
|
10
|
+
config = context.config
|
|
11
|
+
|
|
12
|
+
# Interpret the config file for Python logging.
|
|
13
|
+
# This line sets up loggers basically.
|
|
14
|
+
if config.config_file_name is not None:
|
|
15
|
+
fileConfig(config.config_file_name)
|
|
16
|
+
|
|
17
|
+
# add your model's MetaData object here
|
|
18
|
+
# for 'autogenerate' support
|
|
19
|
+
# from myapp import mymodel
|
|
20
|
+
# target_metadata = mymodel.Base.metadata
|
|
21
|
+
target_metadata = None
|
|
22
|
+
|
|
23
|
+
# other values from the config, defined by the needs of env.py,
|
|
24
|
+
# can be acquired:
|
|
25
|
+
# my_important_option = config.get_main_option("my_important_option")
|
|
26
|
+
# ... etc.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def run_migrations_offline() -> None:
|
|
30
|
+
"""Run migrations in 'offline' mode.
|
|
31
|
+
|
|
32
|
+
This configures the context with just a URL
|
|
33
|
+
and not an Engine, though an Engine is acceptable
|
|
34
|
+
here as well. By skipping the Engine creation
|
|
35
|
+
we don't even need a DBAPI to be available.
|
|
36
|
+
|
|
37
|
+
Calls to context.execute() here emit the given string to the
|
|
38
|
+
script output.
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
url = config.get_main_option("sqlalchemy.url")
|
|
42
|
+
context.configure(
|
|
43
|
+
url=url,
|
|
44
|
+
target_metadata=target_metadata,
|
|
45
|
+
literal_binds=True,
|
|
46
|
+
dialect_opts={"paramstyle": "named"},
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
with context.begin_transaction():
|
|
50
|
+
context.run_migrations()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def run_migrations_online() -> None:
|
|
54
|
+
"""Run migrations in 'online' mode.
|
|
55
|
+
|
|
56
|
+
In this scenario we need to create an Engine
|
|
57
|
+
and associate a connection with the context.
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
connectable = engine_from_config(
|
|
61
|
+
config.get_section(config.config_ini_section, {}),
|
|
62
|
+
prefix="sqlalchemy.",
|
|
63
|
+
poolclass=pool.NullPool,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
with connectable.connect() as connection:
|
|
67
|
+
context.configure(
|
|
68
|
+
connection=connection, target_metadata=target_metadata
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
with context.begin_transaction():
|
|
72
|
+
context.run_migrations()
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if context.is_offline_mode():
|
|
76
|
+
run_migrations_offline()
|
|
77
|
+
else:
|
|
78
|
+
run_migrations_online()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""${message}
|
|
2
|
+
|
|
3
|
+
Revision ID: ${up_revision}
|
|
4
|
+
Revises: ${down_revision | comma,n}
|
|
5
|
+
Create Date: ${create_date}
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
${imports if imports else ""}
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = ${repr(up_revision)}
|
|
16
|
+
down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
"""Upgrade schema."""
|
|
23
|
+
${upgrades if upgrades else "pass"}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def downgrade() -> None:
|
|
27
|
+
"""Downgrade schema."""
|
|
28
|
+
${downgrades if downgrades else "pass"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""create calculations table
|
|
2
|
+
|
|
3
|
+
Revision ID: a6bb6e434c98
|
|
4
|
+
Revises:
|
|
5
|
+
Create Date: 2026-08-21 23:59:25
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
from typing import Sequence, Union
|
|
9
|
+
|
|
10
|
+
from alembic import op
|
|
11
|
+
import sqlalchemy as sa
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# revision identifiers, used by Alembic.
|
|
15
|
+
revision: str = 'a6bb6e434c98'
|
|
16
|
+
down_revision: Union[str, None] = None
|
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
|
18
|
+
depends_on: Union[str, Sequence[str], None] = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def upgrade() -> None:
|
|
22
|
+
op.create_table(
|
|
23
|
+
'calculations',
|
|
24
|
+
sa.Column('id', sa.Integer, primary_key=True),
|
|
25
|
+
sa.Column('input_number', sa.Float, nullable=False),
|
|
26
|
+
sa.Column('result', sa.Float, nullable=False),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def downgrade() -> None:
|
|
31
|
+
op.drop_table('calculations')
|
package/templates/base/start.sh
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
set -e
|
|
3
3
|
|
|
4
|
+
echo "Starting Database via docker-compose..."
|
|
5
|
+
docker compose up -d
|
|
6
|
+
|
|
7
|
+
echo "Running Database Migrations (Alembic)..."
|
|
8
|
+
(
|
|
9
|
+
cd database
|
|
10
|
+
if [ ! -d "venv" ]; then
|
|
11
|
+
python3 -m venv venv
|
|
12
|
+
fi
|
|
13
|
+
source venv/bin/activate
|
|
14
|
+
pip install -r requirements.txt
|
|
15
|
+
|
|
16
|
+
echo "Waiting for PostgreSQL to be ready..."
|
|
17
|
+
for i in {1..60}; do
|
|
18
|
+
if alembic current >/dev/null 2>&1; then
|
|
19
|
+
break
|
|
20
|
+
fi
|
|
21
|
+
sleep 1
|
|
22
|
+
done
|
|
23
|
+
|
|
24
|
+
alembic upgrade head
|
|
25
|
+
)
|
|
26
|
+
|
|
4
27
|
echo "Starting Backend..."
|
|
5
28
|
(cd backend && ./start.sh) &
|
|
6
29
|
BACKEND_PID=$!
|