From bdd06105dd0a6632c2fc22ea5c2158950a53b123 Mon Sep 17 00:00:00 2001 From: Stan Date: Tue, 21 Apr 2026 23:26:13 +0200 Subject: [PATCH] modified version --- PROJECT_FILES_GUIDE.md | 910 ++++++------------ README.md | 870 +++++++++++++---- cookies.txt | 4 - copy/.env.example | 7 - copy/.gitignore | 3 - ...d_Initial_Solution_Project_Document_v1.txt | 724 -------------- copy/Initial_Solution_Proposal.md | 274 ------ copy/README.md | 137 --- copy/package.json | 20 - copy/sql/schema.sql | 97 -- copy/sql/seed.sql | 220 ----- copy/src/app.js | 31 - copy/src/config/env.js | 23 - copy/src/db/pool.js | 30 - copy/src/middleware/errorHandler.js | 15 - copy/src/routes/configRoutes.js | 46 - copy/src/routes/healthRoutes.js | 21 - copy/src/routes/lookupRoutes.js | 29 - copy/src/routes/templateRoutes.js | 49 - copy/src/server.js | 29 - copy/src/services/configService.js | 69 -- copy/src/services/lookupService.js | 76 -- copy/src/services/templateService.js | 89 -- copy/src/utils/asyncHandler.js | 9 - copy/src/utils/json.js | 15 - project.txt | 35 - public/admin.html | 56 +- public/app.js | 780 --------------- public/index.html | 280 ------ public/js/admin.js | 13 +- public/js/api.js | 20 +- public/js/export.js | 100 -- public/js/forms.js | 239 ----- public/js/i18n.js | 121 --- public/js/renderer.js | 389 -------- public/js/user.js | 130 ++- public/js/utils.js | 150 --- public/styles.css | 52 + public/sw.js | 118 --- public/user.html | 15 +- sql/schema.sql | 13 - sql/seed.sql | 9 - src/app.js | 53 +- src/middleware/authMiddleware.js | 28 +- src/routes/configRoutes.js | 50 +- src/services/configService.js | 50 - 46 files changed, 1250 insertions(+), 5248 deletions(-) delete mode 100644 cookies.txt delete mode 100644 copy/.env.example delete mode 100644 copy/.gitignore delete mode 100644 copy/Check_List_Hybrid_Initial_Solution_Project_Document_v1.txt delete mode 100644 copy/Initial_Solution_Proposal.md delete mode 100644 copy/README.md delete mode 100644 copy/package.json delete mode 100644 copy/sql/schema.sql delete mode 100644 copy/sql/seed.sql delete mode 100644 copy/src/app.js delete mode 100644 copy/src/config/env.js delete mode 100644 copy/src/db/pool.js delete mode 100644 copy/src/middleware/errorHandler.js delete mode 100644 copy/src/routes/configRoutes.js delete mode 100644 copy/src/routes/healthRoutes.js delete mode 100644 copy/src/routes/lookupRoutes.js delete mode 100644 copy/src/routes/templateRoutes.js delete mode 100644 copy/src/server.js delete mode 100644 copy/src/services/configService.js delete mode 100644 copy/src/services/lookupService.js delete mode 100644 copy/src/services/templateService.js delete mode 100644 copy/src/utils/asyncHandler.js delete mode 100644 copy/src/utils/json.js delete mode 100644 project.txt delete mode 100644 public/app.js delete mode 100644 public/index.html delete mode 100644 public/js/export.js delete mode 100644 public/js/forms.js delete mode 100644 public/js/i18n.js delete mode 100644 public/js/renderer.js delete mode 100644 public/js/utils.js delete mode 100644 public/sw.js diff --git a/PROJECT_FILES_GUIDE.md b/PROJECT_FILES_GUIDE.md index ba2c110..61e758f 100644 --- a/PROJECT_FILES_GUIDE.md +++ b/PROJECT_FILES_GUIDE.md @@ -1,676 +1,304 @@ # Project Files Guide -This document explains the role of the main files in this project in a way that should be easy to follow for a junior developer. +A junior-friendly walk-through of every folder and file that matters in this +repository. Read it alongside [README.md](README.md): the README tells you how +to run the project, this guide tells you where things live once it is running. -The project is split into a few clear parts: -- server code in [src/app.js](src/app.js) and the rest of [src](src) -- browser frontend files in [public](public) -- database structure and example data in [sql](sql) -- environment and local development helpers in the root folder and [scripts](scripts) +## How the application is organised -## How The Application Works At A High Level +There are three parts: -The project has two big sides: -- the backend, which provides templates, lookups, configuration, report storage, and audit logging through REST API endpoints -- the frontend, which runs in the browser, stores drafts locally, and uses the backend for centrally managed configuration and report submission +1. **Backend** — Node.js + Express in [src/](src/). Talks to MariaDB, serves + the API under `/api/v1/`, and serves the static frontend files. +2. **Frontend** — two single-page shells in [public/](public/): `user.html` for + operators and `admin.html` for administrators. Both are ES-module based + (no bundler) and use Bootstrap 5. +3. **Database** — MariaDB. Schema and seed data are in [sql/](sql/). Docker + loads them automatically on a fresh volume. -In simple terms: -1. Express starts the server. -2. The server exposes API endpoints under `/api/v1/...`. -3. The server also serves the frontend files from the [public](public) folder. -4. The browser loads the frontend entry point [public/app.js](public/app.js) which imports modules from [public/js/](public/js). -5. The frontend downloads templates and config from the API using a single batch request. -6. The frontend stores reports and images locally in IndexedDB. -7. Reports can be submitted to the server via `POST /api/v1/reports`. +### End-to-end request flow (simplified) -## Root Files +1. `docker compose up` starts three containers: `app`, `db`, `phpmyadmin`. +2. [src/server.js](src/server.js) boots Express and connects to MariaDB. +3. The browser loads `/` → `portal.html` (chooser page). +4. The user clicks a link and goes to `/login-admin` or `/login-user`. +5. After login, `/admin` or `/user` is served — both require a valid + `auth_token` cookie (see [src/middleware/authMiddleware.js](src/middleware/authMiddleware.js)). +6. The frontend shell loads either `admin-app.js` or `user-app.js`, which + hands off to `public/js/admin.js` or `public/js/user.js`. +7. The frontend calls `/api/v1/admin/all` to bulk-load every entity needed + for rendering, and keeps working drafts in IndexedDB. + +## Root files ### [package.json](package.json) -Role: -Defines the Node.js project itself. - -What it contains: -- project name and version -- npm scripts such as `start`, `dev`, and `test:environment` -- dependency list such as `express`, `mariadb`, and `dotenv` - -Why it matters: -When you run `npm install` or `npm start`, Node uses this file to know how the project should behave. - -### [README.md](README.md) - -Role: -Main entry document for developers. - -What it contains: -- project purpose -- setup steps -- available endpoints -- development notes - -Why it matters: -This is the first file a new developer should read before touching the code. +Defines the Node project: scripts (`start`, `dev`, `test:environment`), +dependencies (Express, MariaDB driver, cookie-parser, cors, dotenv), and the +minimum Node version. ### [docker-compose.yml](docker-compose.yml) -Role: -Starts the full local development environment. - -What it contains: -- the application container -- the MariaDB container -- the phpMyAdmin container -- port mappings and volume configuration - -Why it matters: -Instead of installing and configuring everything manually, you can start the full stack with one command. - -### [.env.example](.env.example) - -Role: -Example environment configuration. - -What it contains: -- default port values -- database host, name, user, and password placeholders - -Why it matters: -It shows which environment variables the application expects. - -### [.env](.env) - -Role: -Real environment file used on the current machine. - -What it contains: -- actual local values for ports and database credentials - -Why it matters: -The backend reads this file during startup through `dotenv`. - -## Public Folder - -The [public](public) folder contains files that are sent directly to the browser. - -### [public/user.html](public/user.html) - -Role: -Operator workspace HTML shell. - -What it contains: -- shared sidebar with template selector, sync button, report list, and search/filter -- report editor main area with hero, summary cards, form, inspector panel -- report list item `