Skip to content

KaikSelhorst/monorepo-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

214 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Monorepo Template

Monorepo Template

Monorepo template for full-stack development with TypeScript, React, Bun, and Elysia.

πŸš€ Main Technologies

Name Description Docs
Runtime & Build Tools
Bun High-performance JavaScript/TypeScript runtime Link
Turbo Build system for monorepos Link
Frontend
React Library for user interfaces Link
TanStack Router Type-safe routing Link
TanStack Query Server state management Link
Vite Build tool and dev server Link
Tailwind CSS Utility-first CSS framework Link
Backend
Elysia Fast TypeScript web framework Link
Better Auth Authentication system Link
Database
Drizzle ORM TypeScript ORM for PostgreSQL Link
PostgreSQL Relational database Link
Redis Cache and in-memory storage Link
DevOps & Deploy
Vercel Frontend deployment Link
Fly.io Backend deployment Link
GitHub Actions CI/CD Link
Code Quality
Biome Linter and formatter Link
TypeScript JavaScript superset with types Link

πŸ“¦ Project Structure

monorepo-template/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/          # Backend API (Elysia + Bun)
β”‚   └── web/          # Frontend (React + Vite)
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ auth/         # Authentication (Better Auth)
β”‚   β”œβ”€β”€ cache/         # Cache (Redis)
β”‚   β”œβ”€β”€ database/      # Database (Drizzle + PostgreSQL)
β”‚   β”œβ”€β”€ design-system/ # Shared UI components
β”‚   β”œβ”€β”€ linter/        # Linting configuration
β”‚   β”œβ”€β”€ tsconfig/      # TypeScript configurations
β”‚   └── validation/    # Validation schemas (Zod)
└── scripts/           # Utility scripts

πŸ› οΈ How to Use

This project is a template. To create a new repository from this template:

  1. Click the "Use this template" button on GitHub
  2. Follow the instructions to create your repository
  3. Clone the created repository
  4. Configure environment variables (see sections below)

πŸ” Environment Variables

Local Configuration

For local development, you can automatically create .env files from .env.example files by running:

bun run build:envs

This command will copy all .env.example files to .env in the respective apps/packages. After that, you can configure the values in each .env file. Check the documentation for each app/package:

🚒 Deploy and CI/CD

The project uses GitHub Actions for automatic CI/CD. Deployment is triggered when a release is published on GitHub.

How It Works

  1. Trigger: Publishing a release on GitHub
  2. Change Detection: The workflow detects changes in apps/web or apps/api
  3. Automatic Deploy:
    • Web: Deploy to Vercel
    • API: Deploy to Fly.io
  4. Health Check: Automatic API health verification
  5. Rollback: Automatic rollback on failure

GitHub Secrets Configuration

For CI/CD to work, you need to add the following secrets on GitHub:

1. Access Secrets Configuration

  1. Go to the repository on GitHub
  2. Click Settings
  3. In the sidebar, click Secrets and variables β†’ Actions
  4. Click New repository secret

2. Required Secrets

VERCEL_TOKEN

Vercel access token for frontend deployment.

How to get:

  1. Go to Vercel Dashboard
  2. Go to Settings β†’ Tokens
  3. Click Create Token
  4. Give the token a name (e.g., "GitHub Actions")
  5. Copy the generated token
  6. Documentation: Vercel - Authentication

Add to GitHub:

  • Name: VERCEL_TOKEN
  • Value: Paste the copied token
  • Click Add secret
FLY_API_TOKEN

Fly.io access token for backend deployment.

How to get:

  1. Go to Fly.io Dashboard
  2. Run in terminal: fly auth token
  3. Copy the displayed token
  4. Documentation: Fly.io - Access Tokens

Add to GitHub:

  • Name: FLY_API_TOKEN
  • Value: Paste the copied token
  • Click Add secret

Environment Variables Configuration on Platforms

Fly.io (Backend)

After creating the app on Fly.io, add environment variables:

Via Dashboard:

  1. Go to Fly.io Dashboard
  2. Select your app (monorepo-template-api)
  3. Go to Secrets
  4. Add each environment variable
  5. Documentation: Fly.io - Secrets

Reference Links:

Vercel (Frontend)

Via Dashboard:

  1. Go to Vercel Dashboard
  2. Select your project (monorepo-template-web)
  3. Go to Settings β†’ Environment Variables
  4. Add the variable:
    • Key: VITE_API_URL
    • Value: Your API URL (e.g., https://monorepo-template-api.fly.dev)
    • Environment: Production, Preview, Development (select as needed)
  5. Click Save
  6. Documentation: Vercel - Environment Variables

Reference Links:

How to Create a Release

To trigger deployment:

  1. Go to the Releases tab on GitHub
  2. Click Create a new release
  3. Choose the tag (or create a new one)
  4. Fill in the title and description
  5. Click Publish release
  6. CI/CD will be triggered automatically

Documentation: GitHub - Creating Releases

πŸ“š Apps and Packages Documentation

Apps

  • πŸ“– API - Backend API with Elysia
  • πŸ“– Web - Frontend with React

Packages

  • πŸ“– Auth - Authentication with Better Auth
  • πŸ“– Database - Database with Drizzle ORM
  • πŸ“– Cache - Cache with Redis

πŸ§‘β€πŸ’» Development

Prerequisites

  • Bun installed (version 1.3.3 or higher)
  • Docker and Docker Compose (for local database)

⚠️ TypeScript Configuration Warning

Important: It's recommended to use the minimum of TypeScript aliases (paths in tsconfig.json) in packages, as it can cause conflicts with apps during type checking. Prefer using relative imports or direct package imports when possible.

Main Commands

# Install dependencies
bun install

# Development (all apps)
bun dev

# Build (all apps)
bun build

# Linting
bun lint

# Formatting
bun format

Available Scripts

  • bun dev - Starts all apps in development mode
  • bun build - Builds all apps
  • bun preview - Preview of builds
  • bun lint - Runs the linter
  • bun format - Formats the code
  • bun check - Checks code and formatting
  • bun check:write - Automatically fixes found issues

πŸ“ Notes

Bun Warning on Windows

When running bun run dev on Windows, you may see a message about files "outside the project directory" not being watched. This is a Windows limitation related to the limited number of file watchers. It's just a safety measure from Bun and doesn't affect functionality. For more details, see the API README.

πŸ”— Useful Links

About

Monorepo template for full-stack development with TypeScript, React, Bun, and Elysia

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors