@adriankulik/create-fullstack-app 1.9.5 → 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.
@@ -8,20 +8,22 @@
8
8
  "lint": "eslint . --fix"
9
9
  },
10
10
  "dependencies": {
11
- "cors": "^2.8.5",
12
- "express": "^4.22.2"
11
+ "cors": "^2.8.6",
12
+ "express": "^5.2.1",
13
+ "pg": "^8.23.0"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@eslint/js": "^10.0.1",
16
- "@types/cors": "^2.8.17",
17
- "@types/express": "^4.17.21",
18
- "@types/node": "^20.12.7",
19
- "@types/supertest": "^6.0.2",
17
+ "@types/cors": "^2.8.19",
18
+ "@types/express": "^5.0.6",
19
+ "@types/node": "^26.2.0",
20
+ "@types/pg": "^8.23.1",
21
+ "@types/supertest": "^7.2.1",
20
22
  "eslint": "^10.4.0",
21
- "supertest": "^7.0.0",
22
- "tsx": "^4.7.2",
23
+ "supertest": "^7.2.2",
24
+ "tsx": "^4.23.12",
23
25
  "typescript": "^5.9.0",
24
- "typescript-eslint": "^8.59.3",
25
- "vitest": "^4.1.6"
26
+ "typescript-eslint": "^8.67.0",
27
+ "vitest": "^4.1.11"
26
28
  }
27
29
  }
@@ -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
- app.post('/api/multiply', (req: Request, res: Response) => {
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
- return res.json({ result: number * 2 });
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') {
@@ -17,13 +17,15 @@ chmod +x *.sh
17
17
  ```
18
18
 
19
19
  ### Running the App
20
-
21
- To start both the frontend and backend development servers, simply run:
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,3 @@
1
+ alembic==1.16.5
2
+ psycopg2-binary==2.9.12
3
+ SQLAlchemy==2.0.52
@@ -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')
@@ -0,0 +1,10 @@
1
+ version: '3.8'
2
+ services:
3
+ db:
4
+ image: postgres:15
5
+ environment:
6
+ POSTGRES_USER: user
7
+ POSTGRES_PASSWORD: password
8
+ POSTGRES_DB: appdb
9
+ ports:
10
+ - "5432:5432"
@@ -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=$!