{"id":19601624,"url":"https://github.com/alankrantas/svelteapp-typescript-go","last_synced_at":"2025-04-27T17:32:01.535Z","repository":{"id":41399889,"uuid":"444279115","full_name":"alankrantas/svelteapp-typescript-go","owner":"alankrantas","description":"A full-stack, self-contained demo app with Svelte, Golang and SQLite","archived":false,"fork":false,"pushed_at":"2024-04-12T06:42:11.000Z","size":1943,"stargazers_count":115,"open_issues_count":6,"forks_count":7,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-04-12T14:39:37.066Z","etag":null,"topics":["docker","frontend","full-stack","fullstack","go","go-gin","golang","sqlite3","svelte","sveltekit","typescript","website"],"latest_commit_sha":null,"homepage":"","language":"Svelte","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alankrantas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-01-04T03:56:51.000Z","updated_at":"2024-04-15T03:23:08.547Z","dependencies_parsed_at":"2024-01-07T14:23:46.079Z","dependency_job_id":"c6f7db5c-3739-48f2-bf1a-a85db7f160a5","html_url":"https://github.com/alankrantas/svelteapp-typescript-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fsvelteapp-typescript-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fsvelteapp-typescript-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fsvelteapp-typescript-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alankrantas%2Fsvelteapp-typescript-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alankrantas","download_url":"https://codeload.github.com/alankrantas/svelteapp-typescript-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224076431,"owners_count":17251754,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","frontend","full-stack","fullstack","go","go-gin","golang","sqlite3","svelte","sveltekit","typescript","website"],"created_at":"2024-11-11T09:19:14.092Z","updated_at":"2025-04-27T17:32:01.527Z","avatar_url":"https://github.com/alankrantas.png","language":"Svelte","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A Full-Stack, Self-Contained Shopping Demo App With Svelte, Golang and SQLite\n\n![ezgif-5-22d3d39425](https://user-images.githubusercontent.com/44191076/148008744-14f89c9d-5343-483a-8bdc-c05618a84acc.gif)\n\nThis is a simple shopping demo app, based on the same Angular/React/Vue.js examples in \u003ci\u003e[Essential Typescript](https://github.com/Apress/essential-typescript-4)\u003c/i\u003e by Adam Freeman:\n\n- Front-end: (`/src`)\n  - [TypeScript](https://www.typescriptlang.org/)\n  - Component framework: [Svelte 5](https://svelte.dev/) (upgraded to Svelte 5 syntax)\n  - Application framework: [SvelteKit 2](https://kit.svelte.dev/)\n  - Static site generation: [@sveltejs/adapter-static](https://www.npmjs.com/package/@sveltejs/adapter-static)\n  - CSS styles: [Bootstrap 5](https://getbootstrap.com/)\n- Back-end: (`/backend`)\n  - [Golang](https://go.dev/)\n  - Static web server/RESTful web services: [gin](https://github.com/gin-gonic/gin)\n  - SQLite driver: [go-sqlite3](https://github.com/mattn/go-sqlite3)\n- Database: (`/db`)\n  - [SQLite](https://www.sqlite.org/index.html)\n\nThe project comes with a [Dockerfile](https://github.com/alankrantas/svelteapp-typescript-go/blob/main/Dockerfile) that can create a single small container with multi-stage builds (image size ~25 MB) and also support to be opened in [DevContainer](https://code.visualstudio.com/docs/devcontainers/containers)/[CodeSpace](https://github.com/features/codespaces).\n\nA [Github Action workflow](https://github.com/alankrantas/svelteapp-typescript-go/blob/main/.github/workflows/dependabot-test.yml) is created to run build test for dependabot's pull-requests for dependency updates.\n\nThe purpose of project is a demonstration to build a small and self-contained full-stack monolithic application with modern frameworks, but not meant to be a practical template for any real world applications. For example, error handlings between front-end and authentication are mostly ignored.\n\n\u003e A similar version using Vue.js, Express, MongoDB and Docker Compose [can be found here](https://github.com/alankrantas/vueapp-typescript-express) (no longer maintained).\n\n## Routes\n\nThe Svelte app has the following routes:\n\n| Route           | Page                                     |\n| --------------- | ---------------------------------------- |\n| `/`             | Index (will redirect to `/products`)     |\n| `/products`     | Browse and add products to shopping cart |\n| `/order`        | View and checkout order                  |\n| `/summary/{id}` | Order result                             |\n\n### The Application Flow\n\n1. When the app is opened at `/`, it will immediately redirect to `/products`.\n2. `/products` loads the list of products from an API service and display the categories and items.\n3. The user can filter items using the category buttons.\n4. When the user clicks `Add To Cart` on any items, it will be added to the cart (global state array `orderLines`).\n5. When the user clicks `Submit Order` on `/products`, the app will redirect to `/order`, whcih will show the detail of the order.\n6. When the user clicks `Submit Order` on `/order`, the app will send the order to an API service and get the order ID.\n7. After the order is \"sent\", the app will redirect to `/summary/[id]` as the result.\n\n## Backend APIs\n\nThe backend creates two RESTful-like APIs:\n\n| API                 | Function                                         |\n| ------------------- | ------------------------------------------------ |\n| GET `/api/products` | Query DB and return product data                 |\n| POST `/api/orders`  | Write order data into DB and return new order ID |\n\nAdam Freeman's original projects use [`json-server`](https://github.com/typicode/json-server) on an Express server as mock API services. I keep the input/output 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`.\n\n\u003e SvelteKit also has a feature to create [\"backend APIs\"](https://kit.svelte.dev/docs/routing#server). However the Golang server here is enough, so we don't really need to create duplicated APIs.\n\n### `/api/products`\n\nReturn a list of products from the database. The `category` will be used to create category filter buttons on the app.\n\nExample request body:\n\n(none)\n\nExample response body:\n\n```json\n[\n\t{\n\t\t\"id\": 1,\n\t\t\"name\": \"Kayak\",\n\t\t\"category\": \"Watersports\",\n\t\t\"description\": \"A boat for one person\",\n\t\t\"price\": 275.0\n\t},\n\t{\n\t\t\"id\": 2,\n\t\t\"name\": \"Lifejacket\",\n\t\t\"category\": \"Watersports\",\n\t\t\"description\": \"Protective and fashionable\",\n\t\t\"price\": 48.95\n\t}\n]\n```\n\n### `/api/orders`\n\nWrite ordered item and quantities. The service will create a new order ID and associate it with the ordered products.\n\nExample request body:\n\n```json\n{\n\t\"lines\": [\n\t\t{\n\t\t\t\"productId\": 1,\n\t\t\t\"productName\": \"Kayak\",\n\t\t\t\"quantity\": 2\n\t\t},\n\t\t{\n\t\t\t\"productId\": 2,\n\t\t\t\"productName\": \"Lifejacket\",\n\t\t\t\"quantity\": 4\n\t\t}\n\t]\n}\n```\n\nExample response body:\n\n```json\n{\n\t\"id\": 42\n}\n```\n\n---\n\n## Database Schemes and Example Data\n\nThe SQLite 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](https://sqlitebrowser.org/) to read the database. There is also a backup file in case you need to restore the database.\n\nHere's the SQL statements to recreate them:\n\n```sql\nCREATE TABLE \"products\" (\n    \"id\"    INTEGER NOT NULL UNIQUE, -- product ID\n    \"name\"    TEXT NOT NULL,\n    \"category\"    TEXT NOT NULL,\n    \"description\"    TEXT,\n    \"price\"    REAL NOT NULL,\n    PRIMARY KEY(\"id\" AUTOINCREMENT)\n);\n\nCREATE TABLE \"orders\" (\n    \"id\"    INTEGER NOT NULL, -- order ID\n    \"product_id\"    INTEGER NOT NULL, -- product ID\n    \"quantity\"    INTEGER NOT NULL\n);\n\nINSERT INTO \"main\".\"products\" (\n    \"id\",\n    \"name\",\n    \"category\",\n    \"description\",\n    \"price\"\n)\nVALUES\n    ('1', 'Kayak', 'Watersports', 'A boat for one person', '275.0'),\n    ('2', 'Lifejacket', 'Watersports', 'Protective and fashionable', '48.95'),\n    ('3', 'Soccer Ball', 'Soccer', 'FIFA-approved size and weight', '19.5'),\n    ('4', 'Corner Flags', 'Soccer', 'Give your playing field a professional touch', '34.95'),\n    ('5', 'Stadium', 'Soccer', 'Flat-packed 35,000-seat stadium', '79500.0'),\n    ('6', 'Thinking Cap', 'Chess', 'Improve brain efficiency by 75%', '16.0'),\n    ('7', 'Unsteady Chair', 'Chess', 'Secretly give your opponent a disadvantage', '29.95'),\n    ('8', 'Human Chess Board', 'Chess', 'A fun game for the family', '75.0'),\n    ('9', 'Bling Bling King', 'Chess', 'Gold-plated, diamond-studded King', '1200.0');\n```\n\n---\n\n## Setup Local Project\n\nFor local development you'll need\n\n- [Git](https://git-scm.com/download/)\n- [Node.js](https://nodejs.org/en/download/) (for dev or production)\n- [Golang](https://go.dev/dl/) (for production)\n- [Docker](https://docs.docker.com/get-docker/) (only required for generating the container)\n\n\u003e Note: the `go-sqlite3` package requires GCC to compile with the environment variable `CGO_ENABLED=1`.\n\u003e\n\u003e For Windows users, it can be installed with [MinGW](https://winlibs.com/#download-release) (unzip and add `\\mingw64\\bin` to `$PATH`, then restart VS Code). On Linux it can be installed with the package `build-essential`.\n\n### Clone Repository\n\n```bash\ngit clone https://github.com/alankrantas/svelteapp-typescript-go.git\ncd svelteapp-typescript-go\nnpm i -g yarn@latest\nyarn setup-full\n```\n\nAnd install/upgrade yarn:\n\n```bash\nnpm i -g yarn@latest\n```\n\n### Serve Frontend in Dev Mode\n\nRun 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`.\n\n```bash\nyarn dev\n```\n\nThe app will be open at `http://localhost:3000`.\n\n### Download Dependencies\n\n```bash\n# download frontend dependencies\nyarn\n\n# download backend dependencies\nyarn setup-server\n\n# download both dependencies\nyarn setup-full\n# or\n# yarn setup-all\n```\n\n### Upgrade Dependencies\n\n```bash\n# upgrade frontend dependencies\nyarn upgrade-app\n\n# upgrade backend dependencies\nyarn upgrade-server\n\n# upgrade both dependencies\nyarn upgrade-full\n# or\n# yarn upgrade-all\n```\n\n### Build Production\n\nInstall dependencies, build both front-end and back-end apps and run the local server:\n\n```bash\n# build frontend app\nyarn build-app\n\n# build backend server (which will set CGO_ENABLED=1)\nyarn build-server\n\n# build both\nyarn build-full\n# or\n# yarn build\n# yarn build-all\n```\n\n### Serve Production\n\n```bash\n# serve in macOS or Linux\nyarn serve\n\n# serve in Windows\nyarn serve-win\n```\n\nThe app would open at `http://localhost:8080`.\n\n---\n\n### Build and Run as a Docker Container\n\n```bash\n# build container\nyarn docker\n\n# run container\nyarn docker-run\n```\n\nThe app would open at `http://localhost:8080`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fsvelteapp-typescript-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falankrantas%2Fsvelteapp-typescript-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falankrantas%2Fsvelteapp-typescript-go/lists"}