Laravel - React - Docker - Boilerplate
This repo is built with the following:
- Laravel 9
- React 17
- Vite 3
- ESLint 8
- TypeScript 4.7
- Husky/Commit lint
- PHP CS Fixer v3
- Redis 7
- Postgres 14.4
- Nginx 1.23
I put together this repo in an effort to have a solid starting place to begin a React/Docker/Laravel project from. While I understand monolithic repos may not be everyone's bread and butter, it makes sense for a good number of my projects. If you find any bugs or see anything that needs to be changed/updated feel free to put up a PR!
Get started
- Install Docker Desktop
- Clone this repo
git clone [email protected]:lockhinator/laravel-react-docker-boilerplate.git
- CD into the directory
cd laravel-react-docker-boilerplate
- Copy the
.env.example
to.env
cp .env.example .env
- Update your
.env
to reflect the database you want to connect to. If using the defaultdocker-compose.yml
then you can copy the blow and paste it over the initial values.-
DB_CONNECTION=pgsql DB_HOST=pgsql DB_PORT=5432 DB_DATABASE=laravel DB_USERNAME=localuser DB_PASSWORD=supersecretpassword
-
- Run the following commands to run the repo in docker
docker-compose build fpm node web
docker-compose run --rm fpm php artisan key generate
docker-compose run --rm fpm php artisan migrate
docker-compose run --rm fpm composer install
docker-compose run --rm node yarn
docker-compose up -d
- Start making changes to the boiler plate
Usage
Linters and test suites are available for the boilerplate. You are free to change the configs how you want.
Running tests/linters
You can run tests/linters for both React and Laravel/PHP independently. These are the commands to do so:
- React
- Jest tests
docker-compose run --rm node yarn test
- Prettier
docker-compose run node yarn prettier:check
docker-compose run node yarn prettier:fix
- Jest tests
- Laravel
docker-compose run --rm fpm php artisan test --coverage --min=85
- PHP CS Fixer
docker-compose run --rm fpm composer fix-cs-check
docker-compose run --rm fpm composer fix-cs
The Jest configuration is defined in the package.json
file under the jest
key. The reason for this is that using jest.config.ts
results in coverage not correctly running and no files will be found. If you want to make changes to the Jest configuration then do it in the package.json
or risk not having coverage run correctly.
Committing changes
In order to keep commits looking good this repository uses commitlint in conjunction with husky.
Because of this the commit process ends up being:
- Create your branch
- Make changes to the code base
- Add your changes via
git add
- Commit your changes using
yarn commit
- Fill out the interactive prompts
- Push your changes to your branch
git push
Todo
- Configure Jest code coverage to run correctly (currently not working)
- Fill out the jest tests more to cover the different default Laravel Auth pages
License
This boilerplate is open-sourced software licensed under the MIT license.