Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Project Structure #4829

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
aa7a4a0
Project Structure
Mlocik97 May 5, 2022
a9b6062
formating
Mlocik97 May 5, 2022
cf9e836
spaces
Mlocik97 May 5, 2022
00dde94
Update 01-project-structure.md
Mlocik97 May 5, 2022
49f3077
Update 01-project-structure.md
Mlocik97 May 5, 2022
e4b6164
Update 01-project-structure.md
Mlocik97 May 5, 2022
d7990e7
Update 01-project-structure.md
Mlocik97 May 5, 2022
25a0110
Update 01-project-structure.md
Mlocik97 May 5, 2022
076f7ea
Update 01-project-structure.md
Mlocik97 May 5, 2022
4410cfd
Update 01-project-structure.md
Mlocik97 May 5, 2022
59abe08
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
66ed00f
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
f8f1b8a
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
157fd70
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
e4a0a39
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
e427ca7
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
83bda89
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
94fffe0
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
cef6fe9
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
b970fc5
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
5495d42
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
4a82124
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
2980cff
Update 01-project-structure.md
Mlocik97 May 5, 2022
ec8d85a
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
7cdab00
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
1867c23
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
4c52fcf
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
b009781
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
44e06d5
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
8c3241b
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
f341d2f
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
abd6cb4
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
fade1a8
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
11bdce2
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
2d16173
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
1a528d9
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
117e8e4
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
e949c87
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
f74577a
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
e207ef3
Update 01-project-structure.md
Mlocik97 May 5, 2022
a823857
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
73c2efb
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
7a81291
Update 01-project-structure.md
Mlocik97 May 5, 2022
df426b4
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
92e662c
Update 01-project-structure.md
Mlocik97 May 5, 2022
26e3ebc
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
8763164
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
c84ce33
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
a8f4797
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
112fa3e
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
1028b62
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
75a3a80
Update documentation/docs/01-project-structure.md
Mlocik97 May 5, 2022
74d4730
[chore] upgrade eslint-plugin-svelte3
benmccann May 5, 2022
58f56b7
Merge branch 'eslint-plugin-svelte3'
Mlocik97 May 5, 2022
32e4f49
Update documentation/docs/01-project-structure.md
Mlocik97 May 6, 2022
c748641
Merge branch 'master' into master
Mlocik97 May 11, 2022
75a10c5
Merge branch 'master' into master
Mlocik97 May 12, 2022
fae169d
Merge branch 'master' into master
Mlocik97 May 13, 2022
7ada1ee
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 14, 2022
0e5dd49
Merge branch 'master' into master
Mlocik97 May 14, 2022
3954f72
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 17, 2022
8c19d8b
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 18, 2022
2771e2d
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 18, 2022
49094d7
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 19, 2022
74bf221
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 19, 2022
fb84136
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 20, 2022
b17aecf
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 20, 2022
918c9a3
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 23, 2022
885d0f8
Merge remote-tracking branch 'upstream/master'
Mlocik97 May 24, 2022
fb86350
Update 01-project-structure.md
Mlocik97 Jun 5, 2022
ba7a70a
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jun 22, 2022
251bc59
Update 01-project-structure.md
Mlocik97 Jun 24, 2022
25e18d8
Update documentation/docs/01-project-structure.md
Mlocik97 Jun 24, 2022
2dd0396
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jun 29, 2022
cbbebe0
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jul 1, 2022
64a029b
Update 01-project-structure.md
Mlocik97 Jul 7, 2022
ceed586
Update 01-project-structure.md
Mlocik97 Jul 7, 2022
fe32426
Update 01-project-structure.md
Mlocik97 Jul 7, 2022
cf80af1
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jul 7, 2022
9576ed2
Update documentation/docs/01-project-structure.md
Mlocik97 Jul 7, 2022
235d158
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jul 8, 2022
a6ddad9
Merge remote-tracking branch 'upstream/master'
Mlocik97 Jul 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions documentation/docs/01-project-structure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Project Structure
---

The basic structure of a SvelteKit project is:

```sh
Copy link
Contributor Author

@Mlocik97 Mlocik97 May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what to use so comments are shown as comments but everything else as standard text.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the skeleton app structure, and speaking about option folders like params or generated folders like .svelte-kit/ and build/ when speaking about them in their parents' descriptions?

This is the output I've got using tree (tree -aC --dirsfirst --gitignore added / manually):

├── src/
│   ├── routes/
│   │   └── index.svelte
│   ├── app.d.ts
│   └── app.html
├── static/
│   └── favicon.png
├── tests/
│   └── test.js
├── .eslintrc.cjs
├── .gitignore
├── .npmrc
├── .prettierrc
├── README.md
├── jsconfig.json
├── package.json
├── playwright.config.js
└── svelte.config.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better if all of important files are included, so it's really fast visible to where put for example params/ folder, that doesn't exist yet without need to search it deeper in docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's a very important folder of which, BTW, I didn't know about. ☺️
But I would keep it super simple to avoid to overwhelm the reader with "advanced" information, still mentioning them in their related section in the documentation page.
In this case, the section where we explain what the src/ folder is about.
Makes sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to have it all at one place together visible,... it doesn't really add that much mess and it's quite visible which files are where.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, that's true. For sure, I've already learned something new looking at it. ☺️ 👍

my-app/
|
+---- .svelte-kit/ # (generated by SvelteKit)
+---- build/ # (generated at build)
+---- src/
| |
| +---- lib/ # (optional)
| +---- params/ # (optional)
| +---- routes/
| +---- app.css # (optional)
| +---- app.d.ts # (optional)
| +---- app.html
| +---- hooks.js # or 'hooks/' (optional)
| +---- service-worker.js # (optional)
+---- static/
+---- tests/ # (optional)
+---- .eslintrtc.cjs # (optional)
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved
+---- .gitignore # (optional)
+---- .npmrc
+---- .prettierrc # (optional)
+---- jsconfig.json # or 'tsconfig.json' (optional)
+---- package.json
+---- playwright.config.js # (optional)
+---- svelte.config.js
+---- vite.config.js
```

If using TypeScript, the scripts files in the `src/` directory will have a `.ts` file extension.

### package.json

The `package.json` file is a standard file where you can configure your `dependencies` and `devDependencies`. [Read more in the npm docs](https://docs.npmjs.com/cli/v7/configuring-npm/package-json).

SvelteKit is [ESM-first](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules) so we set `"type": "module"`. In the `"scripts"` property, you can see scripts used for building the project, running the dev server, packaging a library (optional), and running other tools for linting, formatting, type checking, testing etc.

### svelte.config.js

Contains [configuration](configuration) for the SvelteKit project.

### vite.config.js

Contains [configuration](https://vitejs.dev/config/) for the [Vite](https://vitejs.dev/). It use [SvelteKit Vite plugins](modules#sveltejs-kit-vite).
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

### static/

Holds your static assets. These are files that are not processed by Vite but are just copied to the build folder by the adapter when building the application.

### src/

Holds the Svelte, JS/TS, and other source files for your app.

#### app.html

This is the entry point to your application. It contains placeholders like `%sveltekit.head%`, `%sveltekit.body%`, and `%sveltekit.assets%`. These placeholders will be removed and replaced by actual content at build or SSR.

`%sveltekit.head%` is replaced with `<link>` and `<script>` tags that power the application as well as content from the [`<svelte:head>`](https://svelte.dev/docs#template-syntax-svelte-head) tags defined in your layouts and pages.

`%sveltekit.body%` is where the HTML for your application is rendered.

`%sveltekit.assets%` is replaced by the [assets base path](configuration#paths).

#### routes/
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

Contains your [pages](routing#pages), [endpoints](routing#endpoints), [standalone endpoints](routing#endpoints-standalone-endpoints), [layouts](layouts) and can also hold [private module](routing#private-modules) files. SvelteKit uses file-based routing, so the file path of the pages and endpoints in this folder maps to the URL which renders them.

#### lib/
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

A folder that contains source for non-routing related files used by your application. They can be imported via the `$lib` alias. If you are creating a library, the contents of the `lib/` folder are used by default to generate the package when you run [`svelte-kit package`](packaging).

#### hooks.js or hooks/
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

A folder or file that contain [hooks](hooks) functions executed at every request. The top scope of this file can be used for initialization code like a database connection.

#### params/
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

Contains [param matchers](routing#advanced-routing-matching) that can be used for dynamic pages or endpoints.

#### service-worker.js or service-worker/
Mlocik97 marked this conversation as resolved.
Show resolved Hide resolved

Optionally contains code for your [service-worker](service-worker).

#### other files in src/ folder

The `src/` folder can also contain an `app.css` file with global styles or an `app.d.ts` file with type definitions.

### build/

The output location for your project will depend on which adapter you use. Many adapters will use the `build/` folder as the output location for your compiled app prepared for deploying to production.

### .svelte-kit/

Holds Vite output used directly when you run `npm run dev` or as intermediate output of `npm run build`.

### tests/

If PlayWright is set, this folder is place for testing your app.

### Other

Based on options you selected when initializing the project, there other files will be generated for tools like Git, ESLint, Prettier, TypeScript, and PlayWright.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.