Skip to content

vishkx/nextjs16_realtime_chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Private Chat - Real-time Self-Destructing Chat Rooms

A modern, real-time chat application built with Next.js 16 that creates private, self-destructing chat rooms. Share a room link and chat securely with automatic message deletion after 10 minutes.

Next.js React TypeScript Upstash

✨ Features

  • πŸ” Private Chat Rooms - Create secure, temporary chat rooms with unique IDs
  • ⏱️ Self-Destructing - Rooms automatically expire after 10 minutes
  • πŸ‘₯ User Limits - Configure room capacity (1-20 users)
  • ⚑ Real-time Messaging - Instant message delivery using Upstash Realtime
  • 🎨 Modern UI - Beautiful interface with dark/light theme support
  • 🌈 Theme Colors - Customizable theme colors with smooth transitions
  • πŸ’£ Manual Destruction - Option to destroy rooms immediately
  • πŸ“± Responsive Design - Works seamlessly on desktop and mobile devices

πŸ› οΈ Tech Stack

Frontend

  • Next.js 16 - React framework with App Router
  • React 19 - UI library
  • TypeScript - Type safety
  • Tailwind CSS 4 - Styling
  • shadcn/ui - UI component library
  • TanStack Query - Data fetching and state management
  • React Hook Form - Form handling
  • Zod - Schema validation

Backend

  • Elysia.js - Fast web framework for API routes
  • Upstash Redis - Serverless Redis for data persistence
  • Upstash Realtime - Real-time pub/sub messaging
  • Eden Treaty - Type-safe API client

πŸ“‹ Prerequisites

  • Node.js 18+ or Bun runtime
  • Upstash Account - For Redis and Realtime services

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/vishkx/nextjs16_realtime_chat.git
cd nextjs16_realtime_chat

2. Install Dependencies

Using Bun (recommended):

bun install

Or using npm:

npm install

3. Environment Variables

Create a .env.local file in the root directory:

# Upstash Redis Configuration
UPSTASH_REDIS_REST_URL=your_redis_rest_url
UPSTASH_REDIS_REST_TOKEN=your_redis_rest_token

# Optional: Custom API URL (for production)
NEXT_PUBLIC_API_URL=https://your-domain.com

Get your Upstash credentials:

  1. Go to Upstash Console
  2. Create a new Redis database
  3. Copy the UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN

4. Run Development Server

Using Bun:

bun run dev

Or using npm:

npm run dev

Open http://localhost:3000 in your browser.

πŸ“– Usage

Creating a Chat Room

  1. Enter your username (auto-generated if not set)
  2. Set the maximum number of users (1-20)
  3. Click "CREATE SECURE ROOM"
  4. Share the room link with others

Joining a Chat Room

  1. Open the shared room link
  2. You'll automatically join if the room has available slots
  3. Start chatting in real-time!

Room Features

  • Self-Destruct Timer - Countdown shows remaining time (10 minutes)
  • Copy Link - Easily share the room URL
  • Destroy Now - Manually destroy the room and all messages
  • Theme Toggle - Switch between light and dark modes
  • Color Themes - Customize theme colors

πŸ“ Project Structure

nextjs16_realtime_chat/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app/                    # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ (app)/              # Main app routes
β”‚   β”‚   β”‚   β”œβ”€β”€ page.tsx        # Home page (room creation)
β”‚   β”‚   β”‚   └── layout.tsx      # App layout
β”‚   β”‚   β”œβ”€β”€ room/
β”‚   β”‚   β”‚   └── [roomId]/      # Dynamic room route
β”‚   β”‚   β”‚       └── page.tsx    # Chat room interface
β”‚   β”‚   └── api/                # API routes
β”‚   β”‚       β”œβ”€β”€ [[...slugs]]/   # Elysia API handler
β”‚   β”‚       └── realtime/       # Realtime WebSocket handler
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ custom/             # Custom components
β”‚   β”‚   β”‚   β”œβ”€β”€ theme-color-toggle.tsx
β”‚   β”‚   β”‚   └── animated-theme-toggler.tsx
β”‚   β”‚   └── ui/                 # shadcn/ui components
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ client.ts           # Eden Treaty API client
β”‚   β”‚   β”œβ”€β”€ redis.ts            # Upstash Redis client
β”‚   β”‚   β”œβ”€β”€ realtime.ts         # Realtime server setup
β”‚   β”‚   └── realtime-client.ts  # Realtime client hooks
β”‚   β”œβ”€β”€ hooks/                  # Custom React hooks
β”‚   └── context/                # React context providers
β”œβ”€β”€ public/                     # Static assets
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
└── next.config.ts

πŸ”§ Development

Available Scripts

# Start development server
bun run dev

# Build for production
bun run build

# Start production server
bun run start

# Run linter
bun run lint

Key Implementation Details

  • Room Management: Rooms are stored in Redis with a 10-minute TTL
  • Authentication: Token-based auth using HTTP-only cookies
  • Real-time Updates: Upstash Realtime for instant message delivery
  • Message History: Messages stored in Redis lists, synced with room TTL
  • User Tracking: Connected users tracked per room with max capacity

🌐 Deployment

Vercel (Recommended)

  1. Push your code to GitHub
  2. Import project in Vercel
  3. Add environment variables:
    • UPSTASH_REDIS_REST_URL
    • UPSTASH_REDIS_REST_TOKEN
  4. Deploy!

Other Platforms

The app can be deployed to any platform supporting Next.js:

  • Netlify
  • Railway
  • Render
  • AWS Amplify

Make sure to set the environment variables in your deployment platform.

πŸ”’ Security Features

  • Token-based Authentication - HTTP-only cookies for secure room access
  • Room Capacity Limits - Prevents unauthorized access
  • Automatic Expiration - Rooms and messages auto-delete after TTL
  • No Persistent Storage - All data is temporary and ephemeral

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

πŸ“§ Contact

For questions or suggestions, please open an issue on GitHub.


Made with ❀️ using Next.js 16 and Upstash

About

A modern, real-time chat application built with Next.js 16 that creates private, self-destructing chat rooms. Share a room link and chat securely with automatic message deletion after 10 minutes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors