A modern full-stack, type-safe monorepo template with real-time capabilities and cross-platform support.
Demo Β· Report Bug Β· Request Feature
- π¦ 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
- Node.js (v18+)
- PostgreSQL
- pnpm (
npm install -g pnpm
)
# 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
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
- 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
- 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
- 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
- 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
Each package and application contains its own detailed documentation:
- Backend Documentation
- Mobile Documentation
- Analytics Package
- Database Package
- Services Package
- tRPC Package
- UI Package
- WebSockets Package
// 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>
);
}
// 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);
});
This project includes several helpful scripts for development and maintenance, located in the scripts/
directory.
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.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/amazing-feature
) - Commit your Changes (
git commit -m 'Add some amazing feature'
) - Push to the Branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
BlaΕΎ Aristovnik - @barisgit - aristovnik.me