diff --git a/.env.example b/.env.example index cddd17c..b571df9 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,9 @@ DB_PASSWORD= -DB_PASSWORD_V2= \ No newline at end of file +BACKEND_URL= +MAIL_HOST= +MAIL_PORT= +MAIL_USER= +MAIL_PASSWORD= +MAIL_SENDEES_CONTACT= +MAIL_SENDEES= +NAAS_URL= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 72ec119..0bcb26b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ dist/ build/ out/ +docker-compose.override.yml + # Environment variables .env .env.local diff --git a/Docs/docker/README.md b/Docs/docker/README.md new file mode 100644 index 0000000..2837171 --- /dev/null +++ b/Docs/docker/README.md @@ -0,0 +1,78 @@ +# Docker + +## Prerequisites + +You have created an empty `docker-compose.override.yml` file in the root directory of this repository. + +## Docker Network + +If you want to run the stack in a docker network, you need to change the `BACKEND_HOST` variable in the root `.env` file +to `stockhome-backend`. To add a docker network, create a `docker-compose.override.yml` file in the root directory of +this repository with the following content: + +```yaml +services: + admin-frontend: + networks: + - proxynet + + backend: + networks: + - proxynet + + usr-frontend: + networks: + - proxynet + + no-as-a-service: + networks: + - proxynet + + mysql: + networks: + - proxynet + +networks: + proxynet: + external: true +``` + +To start off I recommend to set the `BACKEND_HOST` variable to `localhost` and start the stack without a docker network. +After you have started the stack and everything is working, you can add a docker network. + +## Ports + +### Change Exposed Ports + +If you want to change the exposed ports, you can do this in the `docker-compose.yml` file like so: + +```yaml +services: + mysql: + ports: + - "3306:3306" + + backend: + ports: + - "8004:8004" + + usr-frontend: + ports: + - "80:80" +``` + +### Remove Exposed Ports + +If you want to remove the exposed ports, you can do this in the `docker-compose.override.yml` file like so: + +```yaml +services: + mysql: + ports: !override [ ] + + backend: + ports: !override [ ] + + usr-frontend: + ports: !override [ ] +``` diff --git a/README.md b/README.md index de81827..026b686 100644 --- a/README.md +++ b/README.md @@ -19,17 +19,21 @@ A small full‑stack system to log in, view available items, reserve them for a ## Contents - Frontend: [frontend/](frontend) - - Vite/Tailwind config: [frontend/vite.config.ts](frontend/vite.config.ts), [frontend/tailwind.config.js](frontend/tailwind.config.js) - - App entry: [frontend/src/main.tsx](frontend/src/main.tsx), [frontend/src/App.tsx](frontend/src/App.tsx) - - UI: [frontend/src/layout/Layout.tsx](frontend/src/layout/Layout.tsx), [frontend/src/components](frontend/src/components) - - Data/utilities: [frontend/src/utils/fetchData.ts](frontend/src/utils/fetchData.ts), [frontend/src/utils/userHandler.ts](frontend/src/utils/userHandler.ts), [frontend/src/utils/toastify.ts](frontend/src/utils/toastify.ts) + - Vite/Tailwind + config: [frontend/vite.config.ts](frontend/vite.config.ts), [frontend/tailwind.config.js](frontend/tailwind.config.js) + - App entry: [frontend/src/main.tsx](frontend/src/main.tsx), [frontend/src/App.tsx](frontend/src/App.tsx) + - + UI: [frontend/src/layout/Layout.tsx](frontend/src/layout/Layout.tsx), [frontend/src/components](frontend/src/components) + - + Data/utilities: [frontend/src/utils/fetchData.ts](frontend/src/utils/fetchData.ts), [frontend/src/utils/userHandler.ts](frontend/src/utils/userHandler.ts), [frontend/src/utils/toastify.ts](frontend/src/utils/toastify.ts) - Backend: [backend/](backend) - - Server: [backend/server.js](backend/server.js) - - Routes: [backend/routes/api.js](backend/routes/api.js), [backend/routes/apiV2.js](backend/routes/apiV2.js) - - DB + services: [backend/services/database.js](backend/services/database.js), [backend/services/tokenService.js](backend/services/tokenService.js) - - Schema/seed: [backend/scheme.sql](backend/scheme.sql) + - Server: [backend/server.js](backend/server.js) + - Routes: [backend/routes/api.js](backend/routes/api.js), [backend/routes/apiV2.js](backend/routes/apiV2.js) + - DB + + services: [backend/services/database.js](backend/services/database.js), [backend/services/tokenService.js](backend/services/tokenService.js) + - Schema/seed: [backend/scheme.sql](backend/scheme.sql) - Docs: [docs/](docs) - - API docs (see below): [docs/backend_API_docs/README.md](docs/backend_API_docs/README.md) + - API docs (see below): [docs/backend_API_docs/README.md](docs/backend_API_docs/README.md) ## Features (high‑level) @@ -41,7 +45,8 @@ A small full‑stack system to log in, view available items, reserve them for a Key frontend utilities: - [`utils.fetchData.fetchAllData`](frontend/src/utils/fetchData.ts): loads items, loans, and user loans after login. -- [`utils.fetchData.getBorrowableItems`](frontend/src/utils/fetchData.ts): fetches borrowable items for the selected time range. +- [`utils.fetchData.getBorrowableItems`](frontend/src/utils/fetchData.ts): fetches borrowable items for the selected + time range. - [`utils.userHandler.createLoan`](frontend/src/utils/userHandler.ts): creates a new loan for selected items. - [`utils.userHandler.handleDeleteLoan`](frontend/src/utils/userHandler.ts): deletes a loan and syncs local state. - [`utils.toastify.myToast`](frontend/src/utils/toastify.ts): toast notifications. @@ -54,20 +59,18 @@ UI flow (main screens): ## Development -- Scripts: see [frontend/package.json](frontend/package.json) and [backend/package.json](backend/package.json) - - Frontend: `npm run dev`, `npm run build`, `npm run preview`, `npm run lint` - - Backend: `npm start` -- Linting: ESLint configured via [frontend/eslint.config.js](frontend/eslint.config.js) -- TypeScript configs: [frontend/tsconfig.app.json](frontend/tsconfig.app.json), [frontend/tsconfig.node.json](frontend/tsconfig.node.json) +- The NAAS (no-as-a-service) and the mysql database are running in a docker container +- `frontend`, `backend` and `admin` are both in a vite dev server and can be started by `npm run dev` in the root + directory. ## Configuration notes -- Vite/Tailwind integration via [frontend/vite.config.ts](frontend/vite.config.ts) and `@tailwindcss/vite`; CSS entry uses `@import "tailwindcss"` in [frontend/src/index.css](frontend/src/index.css). +- Vite/Tailwind integration via [frontend/vite.config.ts](frontend/vite.config.ts) and `@tailwindcss/vite`; CSS entry + uses `@import "tailwindcss"` in [frontend/src/index.css](frontend/src/index.css). - Toasts wired in [frontend/src/main.tsx](frontend/src/main.tsx) with `react-toastify`. -- Local state is stored in `localStorage` keys: `allItems`, `allLoans`, `userLoans`, `borrowableItems`. Cross‑component updates are signaled via window events from [`utils.fetchData`](frontend/src/utils/fetchData.ts). +- Local state is stored in `localStorage` keys: `allItems`, `allLoans`, `userLoans`, `borrowableItems`. Cross‑component + updates are signaled via window events from [`utils.fetchData`](frontend/src/utils/fetchData.ts). ## API documentation -Refer to the dedicated API docs: - -`docs/backend_API_docs/README.md` +Refer to the dedicated [API-Docs](docs/backend_API_docs/README.md) diff --git a/admin/nginx.conf b/admin/nginx.conf index cbb9122..f8f14bb 100644 --- a/admin/nginx.conf +++ b/admin/nginx.conf @@ -14,7 +14,7 @@ server { } location /backend/ { - proxy_pass http://borrow_system-backend_v2:8004/; + proxy_pass http://borrow-system_backend:8004/; } location ~* \.(?:js|mjs|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 0882940..0000000 --- a/changelog.md +++ /dev/null @@ -1,29 +0,0 @@ -# Changelog for upcoming version: vX.X - -Introduction - -## New features - -- - -## Improvements - -- - -## Fixed bugs - -- - ---- - -## New version numbers - -**Backend:** vX.X - -**Frontend:** vX.X - -**Admin panel:** vX.X - ---- - --[Theis](https://portfolio-theis.de) diff --git a/docker-compose.prod.yml b/docker-compose.yml similarity index 60% rename from docker-compose.prod.yml rename to docker-compose.yml index 6f17e89..0ce66af 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.yml @@ -1,43 +1,42 @@ services: usr-frontend: container_name: borrow-system_usr-frontend - networks: - proxynet: - ipv4_address: 172.20.0.6 build: ./frontend - restart: unless-stopped + environment: + VITE_BACKEND_URL: ${BACKEND_URL} + restart: always admin-frontend: container_name: borrow-system_admin-frontend - networks: - proxynet: - ipv4_address: 172.20.0.35 build: ./admin - restart: unless-stopped + environment: + VITE_BACKEND_URL: ${BACKEND_URL} + restart: always - backend_v2: + backend: container_name: borrow-system_backend - networks: - proxynet: - ipv4_address: 172.20.0.5 build: ./backend environment: NODE_ENV: production - DB_HOST: mysql_v2 + DB_HOST: borrow-system_mysql DB_USER: root - DB_PASSWORD: ${DB_PASSWORD_V2} + DB_PASSWORD: ${DB_PASSWORD} DB_NAME: borrow_system_new + MAIL_HOST: ${MAIL_HOST} + MAIL_PORT: ${MAIL_PORT} + MAIL_USER: ${MAIL_USER} + MAIL_PASSWORD: ${MAIL_PASSWORD} + MAIL_SENDEES_CONTACT: ${MAIL_SENDEES_CONTACT} + MAIL_SENDEES: ${MAIL_SENDEES} + NAAS_URL: ${NAAS_URL} depends_on: - mysql_v2 - restart: unless-stopped + restart: always mysql: container_name: borrow-system_mysql - networks: - proxynet: - ipv4_address: 172.20.0.12 image: mysql:8.0 - restart: unless-stopped + restart: always environment: MYSQL_ROOT_PASSWORD: ${DB_PASSWORD_V2} MYSQL_DATABASE: borrow_system_new @@ -48,9 +47,6 @@ services: no-as-a-service: container_name: borrow-system_naas - networks: - proxynet: - ipv4_address: 172.20.0.36 build: context: ./no-as-a-service dockerfile: Dockerfile @@ -58,8 +54,4 @@ services: volumes: mysql-data: - mysql-v2-data: - -networks: - proxynet: - external: true + mysql-v2-data: \ No newline at end of file diff --git a/frontend/nginx.conf b/frontend/nginx.conf index cbb9122..f8f14bb 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -14,7 +14,7 @@ server { } location /backend/ { - proxy_pass http://borrow_system-backend_v2:8004/; + proxy_pass http://borrow-system_backend:8004/; } location ~* \.(?:js|mjs|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { diff --git a/package-lock.json b/package-lock.json index bdc68ae..6d48584 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,7 @@ "workspaces": [ "backend", "frontend", - "admin", - "shared" + "admin" ], "devDependencies": { "concurrently": "^10.0.6", @@ -481,10 +480,6 @@ "node": ">=6.9.0" } }, - "node_modules/@borrow-system/shared": { - "resolved": "shared", - "link": true - }, "node_modules/@chakra-ui/react": { "version": "3.37.0", "resolved": "https://registry.npmjs.org/@chakra-ui/react/-/react-3.37.0.tgz", @@ -7484,6 +7479,7 @@ "shared": { "name": "@borrow-system/shared", "version": "1.0.0", + "extraneous": true, "license": "ISC" } } diff --git a/package.json b/package.json index 959924d..05fa838 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "workspaces": [ "backend", "frontend", - "admin", - "shared" + "admin" ], "description": "", "main": "index.js", diff --git a/shared/package.json b/shared/package.json deleted file mode 100644 index 82d94b0..0000000 --- a/shared/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "@borrow-system/shared", - "private": "true", - "version": "1.0.0", - "type": "module", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC" -}