Skip to content

bretheskevin/template-rails-next

Repository files navigation

Template Next.js / Ruby on Rails

Your application will be served to http://localhost/

Prerequisites

  • bash (The setup script use .bashrc for aliases)
  • Docker
  • Docker Compose
    • /!\ It won't work with the old version that uses docker-compose, you need to install the latest one that use docker compose, or add an alias in your .bash_aliases file.
  • Yarn

Get started

Rename the .env.example file to .env and fill it with your own values

Set up the project

Linux

The following script will :

  • Install the pre-commit hooks (rubocop and rspec)
  • Add an alias named kb to the .dev/kb.sh file
  • Add auto-completion for the kb alias
./setup.sh

MacOS

Add the permissions to the .git folder and execute the setup script

chmod -R 777 .git
./setup-macos.sh

Then, go to the frontend folder, and install the dependencies

cd frontend
yarn install

The app will be accessible at http://localhost/, don't specify the port, or you will get a CORS error during API calls.

Make sure to restart your terminal or source the .bashrc file

Execute kb to see the available commands

Commands

  • kb build : Build the docker container
  • kb start : Start / Restart the project
  • kb console : Open a bash console in the backend container
  • kb test : Run the tests
  • kb rubocop : Run rubocop
  • kb logs : Show the docker containers logs

Ports

If you have any conflicts with the porte 3000, 4200 or 5432, you can change them in the .env file. It will change the ports served by the docker container (it's normal that the ports don't change in the logs)

Features

Backend

  • Rubocop (with rspec and factory-bot plugins)
  • Rspec
  • Crud concern
  • Pagination for the index action
  • Serializer
  • Authentication with devise
  • Pundit gem for authorization (roles)
  • Scope to get deleted models

Frontend

  • ESLint
  • Prettier
  • Tailwind
  • ApiService
    • CRUD methods
    • Send authorization token
    • Manage search params
  • AuthService
  • EntityManager (automatically fetch data from the API)
  • Model
  • Example page with some entity manager actions
  • Shadcn library for the UI
  • Zod lib added for form validation
  • Vitest lib added for testing

TODO

  • Migrate Rails.application.secrets to Rails.application.credentials