Demo has the following structure:
demo/
|-- api/
| |-- shared/src/main/scala/
| |-- demo/api/
| |-- ...
|-- app/
| |-- src/main/scala/
| | |-- demo/app/
| | |-- Main.scala
| | |-- ...
| |-- index.html
| |-- main.js
| |-- package.json
| |-- vite.config.js
|-- project/
| |-- build.properties
| |-- plugins.sbt
| |-- Versions.scala
|-- service/
| |-- src/main/
| |-- resources
| |-- logback.xml
| |-- scala/
| |-- demo/service
| |-- Main.scala
| |-- ...
|-- .scalafmt.conf
|-- build.sbt
build.sbt
: Contains the build definition.project/build.properties
: Specifies the SBT version.project/plugins.sbt
: Defines SBT plugins to use in the project.project/Version.scala
: Contains a list of versions of 3rd party dependencies.api/
: Contains service endpoint definitions and payload models. This module is used by both theapp
andservice
modules.app/
: Contains the frontend application and Vite configuration.service/
: Contains the backend sources.
If you haven't already installed Homebrew, you can do so by running the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Scala runs on the Java Virtual Machine (JVM), so you'll need to have Java installed. You can install the latest version of OpenJDK using Homebrew:
brew install openjdk
After installation, you can check the Java version by running:
java -version
SBT (Scala Build Tool) is the de facto build tool for Scala projects. You can install both Scala and SBT using Homebrew:
brew install scala sbt
After installation, you can check the Scala and SBT versions by running:
scala -version
sbt -version
-
Navigate to the Project Directory
Open a terminal and navigate to the root directory of your SBT project:
cd path/to/demo
-
Start the backend
sbt service/run
After starting the service, you can check if the backend is running:
curl http://localhost:8080/api/motd
This should return a random message of the day.
-
Start the frontend
Open a new terminal and start the SBT interactive shell:
sbt
Continually compile Scala.js sources. This will re-compile the app every time a source file changes:
~fastLinkJS
Open a new terminal and navigate to the
app
folder:cd app
Start Vite development server:
npm run dev
After Vite starts, you can open the app in your default web browser by pressing the o key in the terminal.