2. Project Structure
After creating a new Wasp project, you'll get a file structure that looks like this:
.
βββ .gitignore
βββ main.wasp # Your Wasp code goes here.
βββ src
βΒ Β βββ client # Your client code (JS/CSS/HTML) goes here.
βΒ Β βΒ Β βββ Main.css
βΒ Β βΒ Β βββ MainPage.jsx
βΒ Β βΒ Β βββ tsconfig.json
βΒ Β βΒ Β βββ vite.config.ts
βΒ Β βΒ Β βββ vite-env.d.ts
βΒ Β βΒ Β βββ waspLogo.png
βΒ Β βββ server # Your server code (Node JS) goes here.
βΒ Β βΒ Β βββ tsconfig.json
βΒ Β βββ shared # Your shared (runtime independent) code goes here.
βΒ Β βΒ Β βββ tsconfig.json
βΒ Β βββ .waspignore
βββ .wasproot
By your code, we mean the "the code you write", as opposed to the code generated by Wasp. Wasp expects you to separate all of your codeβwhich we call external codeβinto three folders to make it obvious how each file is executed:
src/client
: Contains the code executed on the client, in the browser.src/server
: Contains the code executed on the server, with Node.src/shared
: Contains code that may be executed on both the client and server.
Many of the other files (tsconfig.json
, vite-env.d.ts
, etc.) are used by your IDE to improve your development experience with tools like autocompletion, intellisense, and error reporting.
The file vite.config.ts
is used to configure Vite, Wasp's build tool of choice.
We won't be configuring Vite in this tutorial, so you can safely ignore the file. Still, if you ever end up wanting more control over Vite, you'll find everything you need to know in custom Vite config docs.
Wasp supports TypeScript out of the box, but you are free to choose between or mix JavaScript and TypeScript as you see fit.
We'll provide you with both JavaScript and TypeScript code in this tutorial. Code blocks will have a toggle to switch between vanilla π¦ JavaScript and TypeScript.
The most important file in the project is main.wasp
. Wasp uses the configuration within it to perform its magic. Based on what you write, it generates a bunch of code for your database, server-client communication, React routing, and more.
Let's look a bit closer at main.wasp.
main.wasp
β
This file, written in our Wasp configuration language, defines your app and lets Wasp take care a ton of features to your app for you. The file contains several declarations which, together, describe all the components of your app.
The default Wasp file generated via wasp new
on the previous page looks like:
- JavaScript
- TypeScript
app TodoApp {
wasp: {
version: "^0.11.6" // Pins the version of Wasp to use.
},
title: "Todo app" // Used as the browser tab title. Note that all strings in Wasp are double quoted!
}
route RootRoute { path: "/", to: MainPage }
page MainPage {
// We specify that the React implementation of the page is the default export
// of `src/client/MainPage.jsx`. This statement uses standard JS import syntax.
// Use `@client` to reference files inside the `src/client` folder.
component: import Main from "@client/MainPage.jsx"
}
app TodoApp {
wasp: {
version: "^0.11.6" // Pins the version of Wasp to use.
},
title: "Todo app" // Used as the browser tab title. Note that all strings in Wasp are double quoted!
}
route RootRoute { path: "/", to: MainPage }
page MainPage {
// We specify that the React implementation of the page is the default export
// of `src/client/MainPage.tsx`. This statement uses standard JS import syntax.
// Use `@client` to reference files inside the `src/client` folder.
component: import Main from "@client/MainPage.tsx"
}
This file uses three declaration types:
app: Top-level configuration information about your app.
route: Describes which path each page should be accessible from.
page: Defines a web page and the React component that will be rendered when the page is loaded.
In the next section, we'll explore how route and page work together to build your web app.