Skip to content

Commit bf808ac

Browse files
Add project structure guide (#3432)
1 parent 01ad371 commit bf808ac

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

astro.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default defineConfig({
100100
'start',
101101
'start/prerequisites',
102102
'start/create-project',
103+
'start/project-structure',
103104
// {
104105
// label: 'What is Tauri?',
105106
// // translations: {

src/content/docs/security/capabilities.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Inline capabilities can be mixed with pre-defined capabilities.
102102

103103
By default, all commands that you registered in your app
104104
(using the
105-
[`tauri::Builder::.invoke_handler`](https://docs.rs/tauri/2.0.0/tauri/struct.Builder.html#method.invoke_handler)
105+
[`tauri::Builder::invoke_handler`](https://docs.rs/tauri/2.0.0/tauri/struct.Builder.html#method.invoke_handler)
106106
function)
107107
are allowed to be used by all the windows and webviews of the app.
108108
To change that, consider using
@@ -216,7 +216,7 @@ to higher privileged windows.
216216
## Schema Files
217217

218218
Tauri generates JSON schemas with all the permissions available to
219-
your application, allowing autocompletion in your IDE.
219+
your application through `tauri-build`, allowing autocompletion in your IDE.
220220
To use a schema, set the `$schema` property in your configuration file
221221
(either .json or .toml) to one of the platform-specific schemas
222222
located in the `gen/schemas` directory. Usually
@@ -232,12 +232,12 @@ Simplified example of an example Tauri application directory structure:
232232
tauri-app
233233
├── index.html
234234
├── package.json
235-
├── src
236-
├── src-tauri
235+
├── src/
236+
├── src-tauri/
237237
│ ├── Cargo.toml
238-
│ ├── capabilities
239-
└── <identifier>.json/toml
240-
│ ├── src
238+
│ ├── capabilities/
239+
└── <identifier>.json/toml
240+
│ ├── src/
241241
│ ├── tauri.conf.json
242242
```
243243

src/content/docs/start/create-project.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar:
55
i18nReady: true
66
---
77

8-
import { Card, Steps } from '@astrojs/starlight/components';
8+
import { Steps } from '@astrojs/starlight/components';
99

1010
import Cta from '@fragments/cta.mdx';
1111

@@ -222,7 +222,8 @@ The following example assumes you are creating a new project. If you've already
222222

223223
## Next Steps
224224

225+
- [Learn about the project layout and what each file does](/start/project-structure/)
225226
- [Add and Configure a Frontend Framework](/start/frontend/)
226227
- [Tauri Command Line Interface (CLI) Reference](/reference/cli/)
227-
- [Learn how to build your Tauri app](/develop/)
228+
- [Learn how to develop your Tauri app](/develop/)
228229
- [Discover additional features to extend Tauri](/plugin/)

src/content/docs/start/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ sidebar:
77

88
Tauri is a framework for building tiny, fast binaries for all major desktop and mobile platforms. Developers can integrate any frontend framework that compiles to HTML, JavaScript, and CSS for building their user experience while leveraging languages such as Rust, Swift, and Kotlin for backend logic when needed.
99

10-
Get started building with [`create-tauri-app`](https://github.com/tauri-apps/create-tauri-app) by using one of the below commands. Be sure to follow the [prerequisites guide](/start/prerequisites/) to install all of the dependencies required by Tauri and then view the [Frontend Configuration guides](/start/frontend/) for recommended frontend configurations.
10+
Get started building with [`create-tauri-app`](https://github.com/tauri-apps/create-tauri-app) by using one of the below commands. Be sure to follow the [prerequisites guide](/start/prerequisites/) to install all of the dependencies required by Tauri. For a more detailed walk through, see [Create a Project](/start/create-project/#using-create-tauri-app)
1111

1212
import Cta from '../_fragments/cta.mdx';
1313

1414
<Cta />
1515

16-
After you've created your first app you can explore the different features and recipes of Tauri in the [List of Features & Recipes](/plugin/).
16+
After you've created your first app, take a look at [Project Structure](/start/project-structure/) to understand what each file does.
1717

1818
Or explore the project setups and features from the examples ([tauri](https://github.com/tauri-apps/tauri/tree/dev/examples) | [plugins-workspace](https://github.com/tauri-apps/plugins-workspace/tree/v2/examples/api))
1919

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: Project Structure
3+
i18nReady: true
4+
---
5+
6+
A Tauri project is usually made of 2 parts, a Rust project and a JavaScript project (optional),
7+
and typically the setup looks something like this:
8+
9+
```
10+
.
11+
├── package.json
12+
├── index.html
13+
├── src/
14+
│ ├── main.js
15+
├── src-tauri/
16+
│ ├── Cargo.toml
17+
│ ├── Cargo.lock
18+
│ ├── build.rs
19+
│ ├── tauri.conf.json
20+
│ ├── src/
21+
│ │ ├── main.rs
22+
│ │ └── lib.rs
23+
│ ├── icons/
24+
│ │ ├── icon.png
25+
│ │ ├── icon.icns
26+
│ │ └── icon.ico
27+
│ └── capabilities/
28+
│ └── default.json
29+
```
30+
31+
In this case, the JavaScript project is at the top level, and the Rust project is inside `src-tauri/`,
32+
the Rust project is a normal [Cargo project](https://doc.rust-lang.org/cargo/guide/project-layout.html) with some extra files:
33+
34+
- `tauri.conf.json` is the main configuration file for Tauri, it contains everything from the application identifier to dev server url,
35+
this file is also a marker for the [Tauri CLI](/reference/cli/) to find the Rust project,
36+
to learn more about it, see [Tauri Config](/develop/configuration-files/#tauri-config)
37+
- `capabilities/` directory is the default folder Tauri reads [capability files](/security/capabilities/) from (in short, you need to allow commands here to use them in your JavaScript code),
38+
to learn more about it, see [Security](/security/)
39+
- `icons/` directory is the default output directory of the [`tauri icon`](/reference/cli/#icon) command, it's usually referenced in `tauri.conf.json > bundle > icon` and used for the app's icons
40+
- `build.rs` contains `tauri_build::build()` which is used for tauri's build system
41+
- `src/lib.rs` contains the Rust code and the mobile entry point (the function marked with `#[cfg_attr(mobile, tauri::mobile_entry_point)]`),
42+
the reason we don't write directly in `main.rs` is because we compile your app to a library in mobile builds and load them through the platform frameworks
43+
- `src/main.rs` is the main entry point for the desktop, and we run `tauri_app_lib::run()` in `main` to use the same entry point as mobile,
44+
so to keep it simple, don't modify this file, modify `lib.rs` instead
45+
46+
Tauri works similar to a static web host, and the way it builds is that you would compile your JavaScript project to static files first,
47+
and then compile the Rust project that will bundle those static files in,
48+
so the JavaScript project setup is basically the same as if you were to build a static website,
49+
to learn more, see [Frontend Configuration](/start/frontend/)
50+
51+
If you want to work with Rust code only, simply remove everything else and use the `src-tauri/` folder as your top level project or as a member of your Rust workspace
52+
53+
## Next Steps
54+
55+
- [Add and Configure a Frontend Framework](/start/frontend/)
56+
- [Tauri Command Line Interface (CLI) Reference](/reference/cli/)
57+
- [Learn how to develop your Tauri app](/develop/)
58+
- [Discover additional features to extend Tauri](/plugin/)

0 commit comments

Comments
 (0)