Skip to content

Commit 4411ecd

Browse files
committed
Implement Svelte Starter Kit
1 parent 3cb7458 commit 4411ecd

File tree

217 files changed

+6473
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+6473
-625
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,31 @@ on:
66
branches: [main]
77

88
jobs:
9+
10+
lint_js:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 22
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm install
24+
25+
- name: Check prettier formatting
26+
run: npm run format
27+
28+
- name: Check for linting errors
29+
run: npm run lint
30+
31+
- name: Check type errors
32+
run: npm run check
33+
934
scan_ruby:
1035
runs-on: ubuntu-latest
1136

.github/workflows/deploy.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["CI"]
6+
branches: [main]
7+
types:
8+
- completed
9+
10+
jobs:
11+
deploy:
12+
runs-on: ubuntu-latest
13+
if: false # deploy is disabled by default
14+
# uncomment to enable:
15+
# if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
timeout-minutes: 20
17+
env:
18+
DOCKER_BUILDKIT: 1
19+
BUNDLE_ONLY: deploy
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Setup SSH
28+
uses: webfactory/[email protected]
29+
with:
30+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
31+
32+
- name: Set up Ruby
33+
uses: ruby/setup-ruby@v1
34+
with:
35+
ruby-version: .ruby-version
36+
bundler-cache: true
37+
38+
- name: Deploy
39+
env:
40+
VERSION: ${{ github.sha }}
41+
KAMAL_REGISTRY_PASSWORD: ${{ secrets.KAMAL_REGISTRY_PASSWORD }}
42+
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
43+
run: bundle exec kamal deploy --version=$VERSION

Dockerfile-ssr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# check=error=true
33

44
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
5-
# docker build -t inertia_rails_shadcn_starter .
6-
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name inertia_rails_shadcn_starter inertia_rails_shadcn_starter
5+
# docker build -t svelte_starter_kit .
6+
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name svelte_starter_kit svelte_starter_kit
77

88
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
99

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ end
6969
group :development do
7070
# Use console on exceptions pages [https://github.com/rails/web-console]
7171
gem "web-console"
72+
73+
# Use letter_opener to preview emails in the browser in development [https://github.com/ryanb/letter_opener]
74+
gem "letter_opener"
7275
end
7376

7477
group :test do

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ GEM
9696
rack-test (>= 0.6.3)
9797
regexp_parser (>= 1.5, < 3.0)
9898
xpath (~> 3.2)
99+
childprocess (5.1.0)
100+
logger (~> 1.5)
99101
concurrent-ruby (1.3.5)
100102
connection_pool (2.5.3)
101103
crass (1.0.6)
@@ -150,6 +152,12 @@ GEM
150152
thor (~> 1.3)
151153
zeitwerk (>= 2.6.18, < 3.0)
152154
language_server-protocol (3.17.0.5)
155+
launchy (3.1.1)
156+
addressable (~> 2.8)
157+
childprocess (~> 5.0)
158+
logger (~> 1.6)
159+
letter_opener (1.10.0)
160+
launchy (>= 2.2, < 4)
153161
lint_roller (1.1.0)
154162
logger (1.7.0)
155163
loofah (2.24.1)
@@ -409,6 +417,7 @@ DEPENDENCIES
409417
jbuilder
410418
js-routes
411419
kamal
420+
letter_opener
412421
propshaft
413422
puma (>= 5.0)
414423
rails (~> 8.0.2)

Procfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22
vite: bin/vite dev
3-
web: bin/rails s
3+
web: bin/rails s -p 3000

README.md

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,72 @@
1-
# README
1+
# Inertia Rails Svelte Starter Kit
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
A modern full-stack starter application with Rails backend and Svelte frontend using Inertia.js based on the [Laravel Starter Kit](https://github.com/laravel/svelte-starter-kit).
54

6-
Things you may want to cover:
5+
## Features
76

8-
* Ruby version
7+
- [Inertia Rails](https://inertia-rails.dev) & [Vite Rails](https://vite-ruby.netlify.app) setup
8+
- [Svelte 5](https://sveltejs.org) frontend with TypeScript & [shadcn-svelte](https://shadcn-svelte.com) component library
9+
- User authentication system (based on [Authentication Zero](https://github.com/lazaronixon/authentication-zero))
10+
- [Kamal](https://kamal-deploy.org/) for deployment
11+
- Optional SSR support
912

10-
* System dependencies
13+
See also:
14+
- [React Starter Kit](https://github.com/inertia-rails/react-starter-kit) for Inertia Rails with React
15+
- [Vue Starter Kit](https://github.com/inertia-rails/vue-starter-kit) for Inertia Rails with Vue
1116

12-
* Configuration
17+
<a href="https://evilmartians.com/?utm_source=inertia-rails-svelte-starter-kit&utm_campaign=project_page">
18+
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Built by Evil Martians" width="236" height="54">
19+
</a>
1320

14-
* Database creation
21+
## Setup
1522

16-
* Database initialization
23+
1. Clone this repository
24+
2. Setup dependencies & run the server:
25+
```bash
26+
bin/setup
27+
```
28+
3. Open http://localhost:3000
1729

18-
* How to run the test suite
30+
## Enabling SSR
1931

20-
* Services (job queues, cache servers, search engines, etc.)
32+
This starter kit comes with optional SSR support. To enable it, follow these steps:
2133

22-
* Deployment instructions
34+
1. Open `app/frontend/entrypoints/inertia.ts` and uncomment part of the `setup` function:
35+
```ts
36+
// Uncomment the following to enable SSR hydration:
37+
// if (el.dataset.serverRendered === 'true') {
38+
// hydrate(App, {target: el, props})
39+
// return
40+
// }
41+
```
42+
2. Open `config/deploy.yml` and uncomment several lines:
43+
```yml
44+
servers:
45+
# Uncomment to enable SSR:
46+
# vite_ssr:
47+
# hosts:
48+
# - 192.168.0.1
49+
# cmd: bundle exec vite ssr
50+
# options:
51+
# network-alias: vite_ssr
52+
53+
# ...
54+
55+
env:
56+
clear:
57+
# Uncomment to enable SSR:
58+
# INERTIA_SSR_ENABLED: true
59+
# INERTIA_SSR_URL: "http://vite_ssr:13714"
60+
61+
# ...
62+
63+
builder:
64+
# Uncomment to enable SSR:
65+
# dockerfile: Dockerfile-ssr
66+
```
2367

24-
* ...
68+
That's it! Now you can deploy your app with SSR support.
69+
70+
## License
71+
72+
The project is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class ApplicationController < ActionController::Base
24
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
35
allow_browser versions: :modern
@@ -6,16 +8,24 @@ class ApplicationController < ActionController::Base
68
before_action :authenticate
79

810
private
9-
def authenticate
10-
if session_record = Session.find_by_id(cookies.signed[:session_token])
11-
Current.session = session_record
12-
else
13-
redirect_to sign_in_path
14-
end
15-
end
16-
17-
def set_current_request_details
18-
Current.user_agent = request.user_agent
19-
Current.ip_address = request.ip
20-
end
11+
12+
def authenticate
13+
redirect_to sign_in_path unless perform_authentication
14+
end
15+
16+
def require_no_authentication
17+
return unless perform_authentication
18+
19+
flash[:notice] = "You are already signed in"
20+
redirect_to root_path
21+
end
22+
23+
def perform_authentication
24+
Current.session ||= Session.find_by_id(cookies.signed[:session_token])
25+
end
26+
27+
def set_current_request_details
28+
Current.user_agent = request.user_agent
29+
Current.ip_address = request.ip
30+
end
2131
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
class DashboardController < InertiaController
4+
def index
5+
end
6+
end

app/controllers/home_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
class HomeController < ApplicationController
1+
# frozen_string_literal: true
2+
3+
class HomeController < InertiaController
4+
skip_before_action :authenticate
5+
before_action :perform_authentication
6+
27
def index
38
end
49
end

0 commit comments

Comments
 (0)