Skip to content

Autumnlight02/t3ChatClone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

83 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published