An open API service indexing awesome lists of open source software.

https://github.com/barisgit/nextjs-nestjs-expo-template

Full Stack Typesafe Turborepo Boilerplate | Start quick with backend, web and mobile in NestJS, NextJS and Expo
https://github.com/barisgit/nextjs-nestjs-expo-template

expo nestjs nextjs template turborepo

Last synced: about 1 year ago
JSON representation

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

Awesome Lists containing this project

README

          

# 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](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Stargazers](https://img.shields.io/github/stars/barisgit/nextjs-nestjs-expo-template.svg?style=flat-square)](https://github.com/barisgit/nextjs-nestjs-expo-template/stargazers)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

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

[Demo](https://demo-link.com) Β· [Report Bug](https://github.com/barisgit/nextjs-nestjs-expo-template/issues) Β· [Request Feature](https://github.com/barisgit/nextjs-nestjs-expo-template/issues)

## ✨ 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

```bash
# 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

```text
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:

- [Backend Documentation](apps/backend/README.md)
- [Mobile Documentation](apps/mobile/README.md)
- [Analytics Package](packages/analytics/README.md)
- [Database Package](packages/db/README.md)
- [Services Package](packages/services/README.md)
- [tRPC Package](packages/trpc/README.md)
- [UI Package](packages/ui/README.md)
- [WebSockets Package](packages/websockets/README.md)

## πŸ’‘ Usage Examples

### Type-safe API with tRPC

```tsx
// Client component
function UserProfile() {
const { data, isLoading } = trpc.users.getProfile.useQuery();

if (isLoading) return

Loading...
;

return (

Welcome, {data.name}!



);
}
```

### Type-safe Real-time Communication

```tsx
// 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

```bash
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](https://github.com/barisgit) - [aristovnik.me](https://aristovnik.me)

## πŸ™ Acknowledgments

- [Turborepo](https://turbo.build/)
- [NestJS](https://nestjs.com/)
- [Next.js](https://nextjs.org/)
- [Expo](https://expo.dev/)
- [tRPC](https://trpc.io/)
- [TypeORM](https://typeorm.io/)
- [Socket.IO](https://socket.io/)
- [ShadCN UI](https://ui.shadcn.com/)
- [Tamagui](https://tamagui.dev/)
- [Clerk](https://clerk.dev/)
- [PostHog](https://posthog.com/)