This is an example monorepo using Elysia for the backend and SvelteKit for the frontend. It leverages Eden to provide end-to-end type safety.
To get the project up and running, follow these steps:
Make sure you have the following installed:
Then you'll need to clone the repository.
git clone https://github.com/hansaskov/monorepo-elysia-svelte.git
cd monorepo-elysia-svelteThis project uses a monorepo structure, running bun install will install all the dependencies, for both the backend and frontend. Make sure this is run from the root of the project.
bun installYou need to set up environment variables for the project. These values help configure things like which domain to serve the app on.
cp .env.example .envcp .env.example .env: This copies the example.envfile into a new.envfile, which you can then edit to fill in your own values.
If you're working on the project locally and want to see live changes as you work, use the following command:
docker compose up --build --watchLet's break down this command:
-
docker compose up: This starts all the services defined in thedocker-compose.yamlfile (like the backend API, frontend, or database) and keeps them running. -
--build: This flag forces Docker to rebuild the images for your services (both backend and frontend) before starting them. This ensures that you're working with the most up-to-date version of your code. -
--watch: This enables "hot reloading" in development mode. Docker will automatically watch your files for changes and rebuild/restart the services as needed, so you don't have to manually restart the project after each change.
Once the command is running, the project will be available at:
- http://localhost:3000 if no custom domain is set, or
- The domain specified by
APP_FQDNin your.envfile.
When you're ready to deploy the project for real (in a production environment), use this command:
docker compose -f compose.yaml up --build -dLet’s break down each part:
-
docker compose -f compose.yaml: Same as the previous example, but now we exclute the compose.override.yaml file, which was used to define a local development environment. -
up: This starts all the services just like in development mode. -
--build: Similar to the development mode, this flag forces Docker to rebuild all the images. -
-d: The-dstands for "detached mode." This means Docker will run the services in the background. Once the services are up and running, you can safely close your terminal, and the services will continue to run.
Note: Production mode is set to work only on these standard ports (80 and 443). This is typical for web servers, ensuring compatibility with browsers and users’ requests over HTTP/HTTPS.
You might want to run only the backend or frontend separately during development.
Navigate to the backend directory and start the development server.
cd packages/backend
bun devSimilarly, you can start the frontend by navigating to the frontend directory:
cd packages/frontend
bun devWhen you're ready to build the project for deployment, you can use the following commands:
To build both the frontend and backend as Docker images, use:
docker compose -f compose.yaml buildThis command packages your backend and frontend into Docker images, which are ready for deployment.
If you only want to build the backend (e.g., if you're deploying only the API):
cd packages/backend
bun run buildThis creates an executable binary called backend, which can be run on the server.
For the frontend, running this command will generate static files:
cd packages/frontend
bun devThe static files for your website will be available in the /build folder, ready to be deployed to a static hosting provider.
Q: How do I fix the error: "'bundler' can only be used when 'module' is set to 'preserve' or 'es2015' or later.ts"?
A: This error can be resolved by building the frontend. This seems to clear up some internal conflict in the project.
Feel free to reach out for further clarifications or questions!