• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language Svelte
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A full-stack, self-contained demo app with Svelte, Golang and SQLite

A Full-Stack, Self-Contained Shopping Demo App With Svelte, Golang and SQLite

ezgif-5-22d3d39425

This is a simple shopping demo app, based on the same Angular/React/Vue.js examples in Essential Typescript by Adam Freeman:

The project has a Dockerfile that creates a single container with multi-stage builds (image size less than 30 MB) and also supports to be opened in DevContainer/CodeSpace.

The Svelte app has the following routes:

Route Page
/ (Redirect to /products)
/products Browse and add products to shopping cart
/order View and checkout order
/summary/{id} Order result

SvelteKit has a feature to create "backend APIs", and I guess you would be able to call Node-based database packages from there if the production is built by @sveltejs/adapter-node and run in a Node environment. However the Golang server here is enough - and smaller too - so we don't really need to create duplicated APIs.

The backend creates two RESTful-like APIs:

API Function
GET /api/products Query and retur product data
POST /api/orders Write order data and return new order ID

Adam Freeman's original projects use json-server on an Express server as mock API services. I keep the spec of the services for the sake of demonstration. Right now, like all the original examples, the app only reads product lists and write order data. The Axios package used in the original examples is also replaced with fetch.

The purpose of project is an experiment to build a small, modern and self-contained full-stack monolithic application, but it is not meant to be a practical template for any real world applications. Error handlings are ignored in this project.

A similar version using Vue.js, Express, MongoDB and Docker Compose can be found here (no longer maintained).


Setup Local Project

For local development you'll need

  • Git
  • Node.js (for dev or production)
  • Golang (for production)
  • Docker (only required for generating the container)

If you are Windows user the go-sqlite3 package requires GCC to compile, which can be installed with MinGW (choose MinGW32-base, MinGW32-gcc-g++ and MinGW32-gcc-objc package, then add \MinGW\bin to $PATH). On Linux you can installing the package build-essential.

Clone Repository

git clone https://github.com/alankrantas/svelteapp-typescript-go.git
cd svelteapp-typescript-go

Serve in Dev Mode

Run the Svelte app in development mode. The app will not call any backend APIs, instead it returns mock product data and the returned order number is always 42.

npm run setup
npm run dev

The app will be open at http://localhost:3000.

Build and Serve Production

Install dependencies, build both front-end and back-end apps and run the local server:

npm run setup-all
npm run build-all
npm run serve

The app would open at http://localhost:8080.

On Windows use npm run serve-win instead since NPM uses CMD to run bash scripts.

Upgrade All Dependencies

npm run upgrade-all

Use npm run upgrade to upgrade only the front-end dependencies.


Build and Run as a Docker Container

npm run docker
npm run docker-run

The app would open at http://localhost:8080.


SQLite DB Schemes and Test Data

The database (./db/data.sqlite3) in this repo already contains the table products with 9 product records (which can be found in many Adam Freeman's books) and an empty table orders. You can use DB Browser for SQLite to read the database.

Here's the SQL statements to recreate them:

CREATE TABLE "products" (
	"id"	INTEGER NOT NULL UNIQUE,
	"name"	TEXT NOT NULL,
	"category"	TEXT NOT NULL,
	"description"	TEXT,
	"price"	REAL NOT NULL,
	PRIMARY KEY("id" AUTOINCREMENT)
);

CREATE TABLE "orders" (
	"id"	INTEGER NOT NULL,
	"product_id"	INTEGER NOT NULL,
	"quantity"	INTEGER NOT NULL
);

INSERT INTO "main"."products" (
	"id",
	"name",
	"category",
	"description",
	"price"
)
VALUES
	('1', 'Kayak', 'Watersports', 'A boat for one person', '275.0'),
	('2', 'Lifejacket', 'Watersports', 'Protective and fashionable', '48.95'),
	('3', 'Soccer Ball', 'Soccer', 'FIFA-approved size and weight', '19.5'),
	('4', 'Corner Flags', 'Soccer', 'Give your playing field a professional touch', '34.95'),
	('5', 'Stadium', 'Soccer', 'Flat-packed 35,000-seat stadium', '79500.0'),
	('6', 'Thinking Cap', 'Chess', 'Improve brain efficiency by 75%', '16.0'),
	('7', 'Unsteady Chair', 'Chess', 'Secretly give your opponent a disadvantage', '29.95'),
	('8', 'Human Chess Board', 'Chess', 'A fun game for the family', '75.0'),
	('9', 'Bling Bling King', 'Chess', 'Gold-plated, diamond-studded King', '1200.0');

More Repositories

1

edge-impulse-esp32-cam-image-classification

Live Image Classification on ESP32-CAM and TFT with MobileNet v1 from Edge Impulse (TinyML)
C
40
star
2

micropython-TEA5767

MicroPython driver for TEA5767 FM radio module on ESP8266/ESP32/Pico
Python
35
star
3

sefr_multiclass_classifier

Implementations of multiclass version of SEFR linear-time fast classifier (TinyML)
Python
22
star
4

esp8266-micropython-cookbook

Simple and useful MicroPython examples on ESP8266/ESP32/Pico W
Python
15
star
5

micropython-TTP229-BSF

MicroPython ESP8266/ESP32 driver for TTP229-BSF 16-key capacitive keypad in serial interface mode
Python
14
star
6

pxt-MAX7219_8x8

BBC micro:bit MakeCode extension for MAX7219 8x8 matrix LED modules
TypeScript
13
star
7

microbit-micropython-cookbook

Tricks and experiments using MicroPython on BBC micro:bit
Python
10
star
8

pxt-DHT11_DHT22

BBC micro:bit MakeCode extension for DHT11/DHT22 humidity and temperature sensors
TypeScript
9
star
9

raspberrypi-pico-micropython-cookbook

MicroPython drivers and experiments on Raspberry Pi Pico
Python
9
star
10

pxt-ESP8266_ThingSpeak

MakeCode extension for ESP8266 and ThingSpeak
TypeScript
7
star
11

micropython-BPIBIT

micro:bit-like MicroPython Interface Module for BPI:bit/Web:bit (ESP32)
Python
6
star
12

EloquentTinyML_Nano33BLE_Voice_Classifier

Voice Classifier using EloquentTinyML and Nano 33 BLE Sense
C
5
star
13

cuda-cudnn-gpu-devcontainer

NVIDIA CUDA + cuDNN DevContainer Template with GPU Support
Jupyter Notebook
5
star
14

circuitpython-TEA5767

CircuitPython driver for TEA5767 FM radio module
Python
4
star
15

TeachableMachine-p5js-serialport

Run local Teachable Machine image recognition and control micro-controllers
JavaScript
4
star
16

MNIST-Live-Detection-TFLite

MNIST Live Detection using OpenCV, Tensorflow Lite and AutoKeras
Python
3
star
17

TF-Lite-Python-Object-Objection

Object detection examples using pre-trained models on Tensorflow Lite and OpenCV
Python
3
star
18

hello-world-rest-apis

"Hello World" Simple REST APIs in several languages
Dockerfile
2
star
19

colab-python-cookbooks

Experiments of AutoML/data science packages and solving Kaggle competition in Google Colaboratory
Jupyter Notebook
2
star
20

TinyBasicPlus-Mega-VGA-Keyboard

Tiny BASIC 8-bit Home Computer on Arduino MEGA 2560 and Uno with VGA and PS/2 Support
C++
2
star
21

wasm_experiments

WebAssembly (WASM and WASI) experiments
WebAssembly
1
star
22

micropython_GT30L24T3Y_big5_font

從 GT30L24T3Y/ER3303-1 字庫芯片讀取 BIG-5 漢字的簡易 MicroPython 驅動程式
Python
1
star
23

tinygo_experiments

Experiments of TinyGo
Go
1
star
24

knative-quickstart-cloudevents-example

A slightly improved example for sending and receiving events from the Knative example-broker
Go
1
star
25

JACDAC-experiments

micro:bit-based JACDAC STEM Experiment Projects on Node.js and React
TypeScript
1
star
26

vueapp-typescript-express

The Essential TypeScript Demo in Vue.js using Composition API with Express Backend and MongoDB
Vue
1
star
27

OV7670-ESP32-TFT

Live image from a non-FIFO OV7670 camera module to a ILI9341 TFT display
C++
1
star
28

circuitpython_experiments

Python
1
star
29

alankrantas.github.io

Alan Wang's Github Pages homepage
Svelte
1
star
30

pxt-nexusbit

Wrote this extension for some BBC micro:bit accessories developed by my former company. Due to TCEA's management issue, two of my coworkers and me decided to leave in summer 2019. This repo is archived for now.
TypeScript
1
star