Skip to content

Latest commit

 

History

History
193 lines (135 loc) · 5 KB

File metadata and controls

193 lines (135 loc) · 5 KB

T3 Chat Clone

A modern chat application built with TypeScript, tRPC, SQLite, and SvelteKit. This project demonstrates real-time messaging, user authentication, and AI integration.

🚀 Features

  • Real-time Chat: Server-sent events (SSE) for instant messaging
  • User Authentication: GitHub OAuth integration
  • AI Integration: Support for various LLM providers
  • Modern Stack: TypeScript, tRPC, SQLite, SvelteKit
  • Type Safety: End-to-end type safety with shared types
  • Responsive UI: Modern, clean interface

📋 Prerequisites

  • Bun (v1.2.15 or later)
  • Node.js (for compatibility)
  • Git

⚡ Quick Start

1. Clone and Install Dependencies

git clone it
cd t3ChatClone
bun install

2. Environment Setup

Copy the example environment file and configure it:

cp .env.example .env

Edit .env with your actual values:

ENVIRONMENT="DEV"
PUBLIC_BACKEND_HOST="localhost"
PUBLIC_BACKEND_PORT=3000
PUBLIC_BACKEND_HTTP_PROTOCOL="http"
PUBLIC_FRONTEND_HOST="localhost"
PUBLIC_FRONTEND_PORT=5173
PUBLIC_FRONTEND_HTTP_PROTOCOL="http"
SQLITE_PATH=".db"
GITHUB_CLIENT_ID="your_github_client_id_here"
GITHUB_CLIENT_SECRET="your_github_client_secret_here"
API_KEY_ENCRYPTION_SECRET="your_secret_key_here"

3. Start the Backend

Open a terminal and navigate to the backend:

cd apps/backend
bun dev

4. Run Database Migrations

Open a second terminal and run the database migrations:

cd apps/backend
bun run db:migrate

5. Start the Frontend

Open a third terminal and start the frontend:

cd apps/frontend
bun run dev

6. Access the Application

Visit http://localhost:5173 in your browser.

🏗️ Project Structure

t3ChatClone/
├── apps/
│   ├── backend/          # tRPC API server
│   │   ├── src/
│   │   │   ├── auth/     # Authentication logic
│   │   │   ├── chat/     # Chat functionality
│   │   │   ├── llm/      # LLM integration
│   │   │   ├── sse/      # Server-sent events
│   │   │   └── ...
│   │   └── drizzle/      # Database migrations
│   ├── common/           # Shared types and utilities
│   └── frontend/         # SvelteKit frontend
│       ├── src/
│       │   ├── lib/      # Shared components and utilities
│       │   └── routes/   # Page routes
│       └── ...
└── data/                 # Local data storage

🔧 Development

Available Scripts

Backend (apps/backend)

  • bun dev - Start development server
  • bun run db:migrate - Run database migrations
  • bun run db:studio - Open Drizzle Studio (if available)

Frontend (apps/frontend)

  • bun run dev - Start development server
  • bun run build - Build for production
  • bun run preview - Preview production build
  • bun run test - Run tests

Root

  • bun install - Install all dependencies
  • bun run build - Build all packages

🔐 Authentication Setup

This project uses GitHub OAuth for authentication. To set it up:

  1. Go to GitHub Developer Settings
  2. Create a new OAuth App
  3. Set the authorization callback URL to: http://localhost:3000/auth/oauth/github/callback
  4. Copy the Client ID and Client Secret to your .env file

🗄️ Database

The project uses SQLite with Drizzle ORM for database management. The database file is stored locally based on the SQLITE_PATH environment variable.

Running Migrations

When you make changes to the database schema:

cd apps/backend
bun run db:generate  # Generate migration files
bun run db:migrate   # Apply migrations

🤖 AI Integration

The application supports various LLM providers. Configure your API keys in the settings page after authentication.

🛠️ Troubleshooting

Port Already in Use

If you get a "port already in use" error:

  • Backend (port 3000): lsof -ti:3000 | xargs kill -9
  • Frontend (port 5173): lsof -ti:5173 | xargs kill -9

Database Issues

  • Delete the .db file and run migrations again
  • Check that SQLITE_PATH is correctly set in .env

Environment Variables

  • Ensure all required environment variables are set
  • Check that .env file is in the project root
  • Restart the development servers after changing environment variables

📝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with Bun - A fast all-in-one JavaScript runtime
  • tRPC - End-to-end typesafe APIs
  • SvelteKit - The fastest way to build svelte apps
  • Drizzle ORM - TypeScript ORM