---
id: build-from-scratch
title: Build a Project from Scratch
---
> [!NOTE]
> If you chose to quick start with an example or cloned project, you can skip this guide and move on to the [Routing](./guide/routing) guide.
_So you want to build a TanStack Start project from scratch?_
This guide will help you build a **very** basic TanStack Start web application. Together, we will use TanStack Start to:
- Serve an index page
- Display a counter
- Increment the counter on the server and client
[Here is what that will look like](https://stackblitz.com/github/tanstack/router/tree/main/examples/react/start-counter)
Let's create a new project directory and initialize it.
```shell
mkdir myApp
cd myApp
npm init -y
```
> [!NOTE]
> We use `npm` in all of these examples, but you can use your package manager of choice instead.
## TypeScript Configuration
We highly recommend using TypeScript with TanStack Start. Create a `tsconfig.json` file with at least the following settings:
```json
{
"compilerOptions": {
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"module": "ESNext",
"target": "ES2022",
"skipLibCheck": true,
"strictNullChecks": true
}
}
```
> [!NOTE]
> Enabling `verbatimModuleSyntax` can result in server bundles leaking into client bundles. It is recommended to keep this option disabled.
## Install Dependencies
TanStack Start is powered by [Vite](https://vite.dev/) and [TanStack Router](https://tanstack.com/router) and requires them as dependencies.
To install them, run:
```shell
npm i @tanstack/react-start @tanstack/react-router
```
We also need vite as a devDependency:
```shell
npm i -D vite
```
You'll also need React:
```shell
npm i react react-dom
```
As well as React's Vite plugin:
```shell
npm i -D @vitejs/plugin-react
```
Alternatively, you can also use `@vitejs/plugin-react-oxc` or `@vitejs/plugin-react-swc`.
and some TypeScript:
```shell
npm i -D typescript @types/react @types/react-dom @types/node vite-tsconfig-paths
```
## Update Configuration Files
We'll then update our `package.json` to use Vite's CLI and set `"type": "module"`:
```json
{
// ...
"type": "module",
"scripts": {
"dev": "vite dev",
"build": "vite build"
}
}
```
Then configure TanStack Start's Vite plugin in `vite.config.ts`:
```ts
// vite.config.ts
import { defineConfig } from 'vite'
import tsConfigPaths from 'vite-tsconfig-paths'
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
import viteReact from '@vitejs/plugin-react'
export default defineConfig({
server: {
port: 3000,
},
plugins: [
tsConfigPaths(),
tanstackStart(),
// react's vite plugin must come after start's vite plugin
viteReact(),
],
})
```
## Add the Basic Templating
There are 2 required files for TanStack Start usage:
1. The router configuration
2. The root of your application
Once configuration is done, we'll have a file tree that looks like the following:
```
.
├── src/
│ ├── routes/
│ │ └── `__root.tsx`
│ ├── `router.tsx`
│ ├── `routeTree.gen.ts`
├── `vite.config.ts`
├── `package.json`
└── `tsconfig.json`
```
## The Router Configuration
This is the file that will dictate the behavior of TanStack Router used within Start. Here, you can configure everything
from the default [preloading functionality](/router/latest/docs/framework/react/guide/preloading) to [caching staleness](/router/latest/docs/framework/react/guide/data-loading).
> [!NOTE]
> You won't have a `routeTree.gen.ts` file yet. This file will be generated when you run TanStack Start for the first time.
```tsx
// src/router.tsx
import { createRouter } from '@tanstack/react-router'
import { routeTree } from './routeTree.gen'
export function getRouter() {
const router = createRouter({
routeTree,
scrollRestoration: true,
})
return router
}
```
## The Root of Your Application
Finally, we need to create the root of our application. This is the entry point for all other routes. The code in this file will wrap all other routes in the application.
```tsx
// src/routes/__root.tsx
///