> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usesend.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Development

> A guide on how to run useSend’s codebase locally

## Introduction

useSend's codebase is fully [open-source on github](https://github.com/usesend/usesend)

Here is the codebase structure

```
apps
├── docs
├── marketing
├── web
packages
├── eslint-config
├── sdk
├── tailwind-config
├── typescript-config
├── ui
```

The `apps` directory contains the code for:

* `web`: Code for our dashboard and email infra

* `marketing`: The code for the landing page of useSend

* `docs`: The documentation that you are currently reading.

The `packages` directory contains the code for:

* `eslint-config` package contains shared ESLint configuration settings

* `sdk` package contains TypeScript SDK for useSend REST API

* `tailwind-config` This package contains a shared Tailwind CSS configuration.

* `typescript-config` This package contains a shared typescript configuration

* `ui` This package is a collection of reusable UI components like buttons, badges, etc

## Running useSend locally

To run useSend locally, you will need to setup the following:

* [AWS](https://aws.amazon.com/) Free tier account will work.

* [Cloudflare](https://www.cloudflare.com/) Free tier account will work.

* [Docker](https://docs.docker.com/engine/install/) Recommended but not mandatory

## Fork and Clone the repo

**1. Fork the repo**

Click on the fork button on [GitHub](https://github.com/usesend/usesend) to fork the repo

**2. Clone the repo**

Once the repo is forked you can clone it on your local machine using:

```bash theme={null}
git clone https://github.com/your-username/usesend.git
```

## Install Dependencies

**Step 1**

```bash theme={null}
corepack enable
```

**Step 2**

```bash theme={null}
pnpm install
```

## Setup environment variables:

**1. Copy the env.example file into .env**

```bash theme={null}
 cp .env.example .env
```

**2. Nextauth secret**

Use the following command to generate a key and add it under `NEXTAUTH_SECRET`

```bash theme={null}
openssl rand -base64 32
```

**3. Create symlink for Next.js**

Create a symlink so that Next.js can access the root `.env` file:

```bash theme={null}
ln -s ../../.env apps/web/.env
```

**4. Setup GitHub Oauth (optional)**

> [!NOTE]
>
> You don't need this setup if you have `FROM_EMAIL` set in your environment
> variables. for development email link will logged in the console.

Next, [create a new GitHub App](https://github.com/settings/applications/new). This will allow you to sign in to useSend with your GitHub account.

Add the homepage as:

```
http://localhost:3000/login
```

and callback URL as:

```
http://localhost:3000/api/auth/callback/github
```

Once the app is added you can add the Client ID under `GITHUB_ID`and CLIENT SECRET under `GITHUB_SECRET`

**5. Setup AWS credentials (Optional)**

> [!NOTE]
>
> You don't need this setup if you are using the local-sen-sns image. But email
> will not be sent out.

Next, we need to add in the [AWS credentials](https://docs.usesend.com/get-started/create-aws-credentials). Follow the detailed guide to get the AWS credentials with accurate permissions and add them in:

```
AWS_ACCESS_KEY_ID=<access-key-id>
AWS_SECRET_ACCESS_KEY=<secret-access-key>
```

## Running useSend locally

We are using a local Postgresql server and a local Redis server. But if you don't have docker you can also manually set these up.

### Option 1: Using Docker Recommended

**1. Start the dashboard**

```bash theme={null}
pnpm d
```

**2. Dashboard and Landing page will start running**

Dashboard will be started on

```bash theme={null}
http://localhost:3000
```

Landing page will be started on

```bash theme={null}
http://localhost:3001
```

**3. Once you login with GitHub you will be prompted with SES settings. You will need to run cloudflare tunnel to add the callback URL**

Run the following command to get the URL. Here is the more detailed guide by [cloudflare](https://developers.cloudflare.com/pages/how-to/preview-with-cloudflare-tunnel/)

```bash theme={null}
cloudflared tunnel --url http://localhost:3000
```

You can paste the URL provided by cloudflare in the Callback URL section

### Option 2: Using your own database or hosted database

**1. Set up your PostgreSQL and Redis database in Environment Variables**

```bash theme={null}
DATABASE_URL=""
REDIS_URL=""
```

**2. Migrate the database**

```bash theme={null}
pnpm db:migrate-dev
```

**3. Start the development server**

```bash theme={null}
pnpm dev
```

**4. Once you login with GitHub you will be prompted with SES settings. You will need to run cloudflare tunnel to add the callback URL**

Run the following command to get the URL. Here is the more detailed guide by [cloudflare](https://developers.cloudflare.com/pages/how-to/preview-with-cloudflare-tunnel/)

```bash theme={null}
cloudflared tunnel --url http://localhost:3000
```

You can paste the URL provided by cloudflare in the Callback URL section

## Run documentation

To run the documentation run the following command:

```bash theme={null}
pnpm dev:docs
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.