From 5fcca61211f64e99aad4dee774b8a423561772cb Mon Sep 17 00:00:00 2001 From: Andres Rovira Date: Thu, 31 Jul 2025 18:56:43 -0600 Subject: [PATCH 1/2] Add local dev support --- LOCAL_DEV.md | 60 +++++++++++++++++++++++++++++++++++++++++ Makefile | 12 +++++++++ README.md | 16 +++++------ docker-compose.yml | 2 ++ frontend/vite.config.ts | 9 +++++++ 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 LOCAL_DEV.md diff --git a/LOCAL_DEV.md b/LOCAL_DEV.md new file mode 100644 index 0000000..d59147e --- /dev/null +++ b/LOCAL_DEV.md @@ -0,0 +1,60 @@ +# Local Development (No Docker) + +## Quick Start with Makefile + +You can use the provided Makefile for common local development tasks: + +``` +# Start the backend PHP service (http://localhost:9000) +make local-backend + +# Start the frontend Vite dev server (http://localhost:5173) +make local-frontend + +# Run PHP database migrations +make local-migrate +``` + +See below for manual steps if you prefer not to use Makefile. + +You can run the backend and frontend directly on your machine, assuming you have MySQL running locally. + +## Prerequisites +- Node.js and yarn (or npm) +- PHP 8+ +- Composer +- MySQL running on 127.0.0.1 (default user: root, no password, database: app) + +## 1. Backend Setup + +``` +cd backend +composer install +./yii migrate +php -S localhost:9000 -t web +``` +- The backend API will be available at http://localhost:9000/api + +## 2. Frontend Setup + +``` +cd frontend +yarn install +yarn dev +``` +- The frontend will be available at http://localhost:5173 (default Vite port) +- API requests to /api/* will be proxied to the backend at http://localhost:9000 + +## 3. Accessing the Site +- Open http://localhost:5173 or http://ebal.lan:5173 in your browser. +- If you want to use http://ebal.lan, add this to your /etc/hosts: + ``` + 127.0.0.1 ebal.lan + ``` + +## 4. Configuration +- The backend uses environment variables `DB_DSN`, `DB_USER`, and `DB_PASS` if you want to override the default MySQL connection. +- By default, it connects to `mysql:host=127.0.0.1;dbname=app` as `root` with no password. + +## 5. Running Tests +See the main README for backend and frontend test instructions. diff --git a/Makefile b/Makefile index c2dece8..40bc6d1 100644 --- a/Makefile +++ b/Makefile @@ -19,3 +19,15 @@ migrate: docker exec -it $$(docker compose ps -q app) php yii migrate --interactive=0 rebuild: down build up logs + +# Run backend PHP service locally +local-backend: + php -S 0.0.0.0:9000 -t backend/web backend/web/index.php + +# Run frontend Vite web locally +local-frontend: + cd frontend && npm run dev + +# Run PHP database migrations locally +local-migrate: + DB_DSN="mysql:host=127.0.0.1;port=3306;dbname=app" DB_USER="root" DB_PASS="example" php backend/yii migrate --interactive=0 diff --git a/README.md b/README.md index 99fdd23..6882122 100644 --- a/README.md +++ b/README.md @@ -33,19 +33,15 @@ This will create the required tables such as the `user`, `member`, and `group` tables as well as the join table for member assignments. It also seeds a default **admin** user with password **admin123**. -## Frontend - -A lightweight React frontend lives in the `frontend` directory. It is a small -Node project managed with **yarn** and built with **Vite**. Install the dependencies and start the dev server with live reload using: +## Local Development (No Docker) -```bash -cd frontend -yarn install -yarn dev -``` +You can run the backend and frontend directly on your machine. See `LOCAL_DEV.md` for step-by-step instructions. + +## Frontend -Run `yarn build` to create a production bundle under `dist/`. +A lightweight React frontend lives in the `frontend` directory. It is a small +Node project managed with **yarn** and built with **Vite**. See above or `LOCAL_DEV.md` for local dev instructions. Run `yarn build` to create a production bundle under `dist/`. ## Docker Development diff --git a/docker-compose.yml b/docker-compose.yml index 8aea666..7b8d490 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,6 +15,8 @@ services: restart: unless-stopped db: + ports: + - "3306:3306" image: mariadb:10.6 environment: MYSQL_ROOT_PASSWORD: example diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 0466183..891c061 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -3,4 +3,13 @@ import react from '@vitejs/plugin-react'; export default defineConfig({ plugins: [react()], + server: { + proxy: { + '/api/': { + target: 'http://localhost:9000/', + changeOrigin: true, + rewrite: (path) => path.replace(/^\/api/, '/'), + }, + }, + }, }); From 02a61582c2618e7045b61a0aa92a1b1408a7a719 Mon Sep 17 00:00:00 2001 From: Andres Rovira Date: Fri, 1 Aug 2025 10:25:24 -0600 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: windsurf-bot[bot] <189301087+windsurf-bot[bot]@users.noreply.github.com> --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 40bc6d1..0a932aa 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ rebuild: down build up logs # Run backend PHP service locally local-backend: - php -S 0.0.0.0:9000 -t backend/web backend/web/index.php + php -S 127.0.0.1:9000 -t backend/web backend/web/index.php # Run frontend Vite web locally local-frontend: