Skip to content

Full Stack Typesafe Turborepo Boilerplate | Start quick with backend, web and mobile in NestJS, NextJS and Expo

License

Notifications You must be signed in to change notification settings

barisgit/nextjs-nestjs-expo-template

Repository files navigation

Next.js + NestJS + Expo Monorepo Template

NestJS Next.js Expo TypeScript TailwindCSS Socket.io TypeORM tRPC Tamagui Clerk TanStack Query PostHog PostgreSQL Turborepo

License: MIT Stargazers PRs Welcome

A modern full-stack, type-safe monorepo template with real-time capabilities and cross-platform support.

Demo Β· Report Bug Β· Request Feature

✨ Features

  • πŸ“¦ Monorepo Setup: Turborepo with pnpm for efficient workspace management
  • πŸ”„ Full Type Safety: End-to-end type safety from backend to frontend with tRPC and typed WebSockets
  • πŸš€ Modern Stack: Next.js, NestJS, and Expo with TypeScript
  • πŸ”Œ Real-time Communication: Type-safe WebSockets integration with Socket.IO
  • πŸ‘€ Authentication: Clerk integration for secure user management
  • πŸ“Š Analytics: PostHog integration for tracking user behavior
  • 🎨 UI Components: TailwindCSS with ShadCN UI for web and Tamagui for mobile
  • 🧩 Modular Architecture: Well-organized packages for code sharing

πŸš€ Quick Start

Prerequisites

  • Node.js (v18+)
  • PostgreSQL
  • pnpm (npm install -g pnpm)

One-click Setup

# Clone the repository
git clone https://github.com/barisgit/nextjs-nestjs-expo-template.git
cd nextjs-nestjs-expo-template

# Install dependencies
pnpm i # or pnpm install

# Run the development setup script 
# This command handles:
#  - Copying .env files
#  - Setting up database (Docker or manual)
#  - Setting up Redis (Docker)
#  - Running database migrations
#  - Seeding the database
pnpm dev:setup

# NOTE: Ensure Docker is running if you rely on the default Docker setup for PostgreSQL and Redis.
# The script will prompt you for necessary details or use .env files if they exist.

# Start all development servers (Backend, Web, Mobile)
pnpm dev

# Or run individual servers:
# pnpm dev:backend # NestJS
# pnpm dev:web     # Next.js
# pnpm dev:mobile  # Expo

πŸ“‚ Project Structure

nextjs-nestjs-expo-template/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/     # NestJS API server
β”‚   β”œβ”€β”€ web/         # Next.js web application
β”‚   └── mobile/      # Expo React Native application
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ analytics/   # PostHog analytics integration
β”‚   β”œβ”€β”€ db/          # Database models and TypeORM configuration
β”‚   β”œβ”€β”€ services/    # Shared services (auth, redis, webhooks)
β”‚   β”œβ”€β”€ trpc/        # tRPC API router definitions and context
β”‚   β”œβ”€β”€ ui/          # Shared UI components (ShadCN UI for web)
β”‚   β”œβ”€β”€ websockets/  # Type-safe WebSocket implementation
β”‚   β”œβ”€β”€ eslint-config/ # Shared ESLint configuration
β”‚   └── typescript-config/ # Shared TypeScript configuration

πŸ–₯️ Tech Stack

NestJS   Next.js   Expo   tRPC   TypeScript   TailwindCSS   Socket.io   TypeORM   Tamagui   shadcn/ui   Clerk   TanStack Query   PostHog   Turborepo

Backend

  • NestJS: A progressive Node.js framework for scalable server-side applications
  • TypeORM: ORM for TypeScript and JavaScript with PostgreSQL
  • Socket.IO: Real-time bidirectional event-based communication with type safety
  • PostgreSQL: Open-source relational database

Frontend

  • Next.js: React framework for production-grade applications
  • TailwindCSS: Utility-first CSS framework
  • ShadCN UI: Beautifully designed components built with Radix UI and Tailwind CSS
  • TanStack Query: Data fetching and caching library

Mobile

  • Expo: Platform for making universal React applications
  • React Native: Framework for building native apps using React
  • Tamagui: UI library for React Native with performance and developer experience in mind

Common

  • TypeScript: Typed superset of JavaScript
  • tRPC: End-to-end typesafe APIs
  • Turborepo: High-performance build system for JavaScript/TypeScript monorepos
  • Clerk: Authentication and user management
  • PostHog: Open-source product analytics platform

πŸ“– Documentation

Each package and application contains its own detailed documentation:

πŸ’‘ Usage Examples

Type-safe API with tRPC

// Client component
function UserProfile() {
  const { data, isLoading } = trpc.users.getProfile.useQuery();
  
  if (isLoading) return <div>Loading...</div>;
  
  return (
    <div>
      <h1>Welcome, {data.name}!</h1>
    </div>
  );
}

Type-safe Real-time Communication

// WebSocket setup with type safety
import { createTypedSocketClient, ClientEvents, ServerEvents } from '@repo/websockets';

const socket = createTypedSocketClient('http://your-api-url');
socket.emit(ClientEvents.JOIN_ROOM, roomId);

// Listen for messages with full type safety
socket.on(ServerEvents.MESSAGE, (message) => {
  console.log('New message:', message);
});

πŸ› οΈ Development Scripts

This project includes several helpful scripts for development and maintenance, located in the scripts/ directory.

Environment Variable Inspection

pnpm inspect:envs

This command scans the apps/ and packages/ directories for all .env* files (e.g., .env, .env.local, .env.example). It then prints the key-value pairs found in each file, grouped by project (app or package).

This is useful for:

  • Verifying that all necessary environment variables are present in example files.
  • Quickly checking the configured values across different environments.
  • Debugging environment-related issues.

The script is powered by the EnvManager utility (scripts/utilities/env-manager.ts), which is designed to parse .env files while preserving comments and whitespace, making it useful for both reading and programmatically modifying environment configurations.

🀝 Contributing

Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -m 'Add some amazing feature')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.

πŸ“§ Contact

BlaΕΎ Aristovnik - @barisgit - aristovnik.me

πŸ™ Acknowledgments

About

Full Stack Typesafe Turborepo Boilerplate | Start quick with backend, web and mobile in NestJS, NextJS and Expo

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published