|
1 | | -This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app). |
| 1 | +# ChatGPT Clone |
| 2 | + |
| 3 | +A production-grade ChatGPT-like clone built with Next.js, Supabase, Together.ai, Tailwind CSS, and modern best practices. Real-time chat, file attachments, model selection, user settings, and more. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Authentication**: Email/password signup & login, protected routes, session management |
| 10 | +- **Chat Interface**: Real-time streaming, markdown/code, reactions, editing, mobile-responsive |
| 11 | +- **Conversation Management**: Create, rename, delete, search, filter, optimistic UI |
| 12 | +- **File Attachments**: Drag & drop, preview, validation, secure storage |
| 13 | +- **Model Selection**: Switch Together.ai models, per-conversation, token/cost tracking |
| 14 | + |
| 15 | +--- |
| 16 | + |
| 17 | +## Tech Stack |
| 18 | + |
| 19 | +- **Frontend**: Next.js 14 (App Router, RSC), TypeScript, Tailwind CSS, shadcn/ui |
| 20 | +- **Backend**: Next.js API Routes (Edge), Supabase (Postgres, Auth, Storage) |
| 21 | +- **State**: Zustand, TanStack Query, React Hook Form, Zod |
| 22 | +- **LLM**: Together.ai API |
| 23 | +- **Testing**: Vitest |
| 24 | + |
| 25 | +--- |
2 | 26 |
|
3 | 27 | ## Getting Started |
4 | 28 |
|
5 | | -First, run the development server: |
| 29 | +### 1. Clone & Install |
| 30 | + |
| 31 | +```bash |
| 32 | +git clone https://github.com/your-org/chatgpt-clone.git |
| 33 | +cd chatgpt-clone |
| 34 | +npm install # or yarn or pnpm |
| 35 | +``` |
| 36 | + |
| 37 | +### 2. Environment Setup |
| 38 | + |
| 39 | +Copy `.env.example` to `.env.local` and fill in: |
| 40 | + |
| 41 | +```env |
| 42 | +NEXT_PUBLIC_SUPABASE_URL=... |
| 43 | +NEXT_PUBLIC_SUPABASE_ANON_KEY=... |
| 44 | +SUPABASE_SERVICE_ROLE_KEY=... |
| 45 | +TOGETHER_API_KEY=... |
| 46 | +``` |
| 47 | + |
| 48 | +- [Create a Supabase project](https://app.supabase.com/) |
| 49 | +- [Get a Together.ai API key](https://platform.together.ai/) |
| 50 | + |
| 51 | +### 3. Database Setup |
| 52 | + |
| 53 | +- Run the SQL in `knowledge_base/context.md` to create tables: `users`, `conversations`, `messages`, `attachments`. |
| 54 | +- Set up Supabase Storage bucket for file uploads. |
| 55 | + |
| 56 | +### 4. Run Locally |
6 | 57 |
|
7 | 58 | ```bash |
8 | 59 | npm run dev |
9 | | -# or |
10 | | -yarn dev |
11 | | -# or |
12 | | -pnpm dev |
13 | | -# or |
14 | | -bun dev |
15 | 60 | ``` |
| 61 | +Visit [http://localhost:3000](http://localhost:3000) |
| 62 | + |
| 63 | +--- |
| 64 | + |
| 65 | +## Scripts |
| 66 | + |
| 67 | +- `npm run dev` — Start dev server |
| 68 | +- `npm run build` — Build for production |
| 69 | +- `npm start` — Start production server |
| 70 | +- `npm run lint` — Lint code |
| 71 | +- `npm test` — Run all tests (Jest/Vitest) |
| 72 | + |
| 73 | +--- |
| 74 | + |
| 75 | +## Testing |
| 76 | + |
| 77 | +- **Unit/Integration**: `npm test` (Jest/Vitest) |
| 78 | +- **E2E**: See `integration/e2e-chat-auth-flow.test.tsx` |
| 79 | +- Tests cover auth, chat, file upload, and more |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +## Production Environment |
| 84 | + |
| 85 | +- Set `NODE_ENV=production` in your deployment platform (Vercel does this automatically) |
| 86 | +- Use Node.js 18+ runtime |
| 87 | +- Set all required environment variables (see `.env.example`) |
| 88 | +- Enable HTTPS (Vercel/most hosts do this by default) |
| 89 | +- Configure Supabase CORS for your domain |
| 90 | +- Set up Supabase Storage bucket for file uploads |
| 91 | +- Set JWT expiration and security settings in Supabase Auth |
| 92 | +- Review rate limits and security headers in `middleware.ts` and API routes |
| 93 | + |
| 94 | +## Deployment |
| 95 | + |
| 96 | +### Deploy to Vercel (Recommended) |
| 97 | + |
| 98 | +1. Push your code to GitHub |
| 99 | +2. [Import your repo to Vercel](https://vercel.com/import) |
| 100 | +3. Set all environment variables in Vercel dashboard |
| 101 | +4. Click Deploy |
| 102 | + |
| 103 | +### Manual/Other Node Hosts |
16 | 104 |
|
17 | | -Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. |
| 105 | +- Build: `npm run build` |
| 106 | +- Start: `npm start` |
| 107 | +- Set all env vars from `.env.example` |
18 | 108 |
|
19 | | -You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. |
| 109 | +--- |
20 | 110 |
|
21 | | -This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel. |
| 111 | +## Security & Best Practices |
22 | 112 |
|
23 | | -## Learn More |
| 113 | +- Input validation (Zod, server-side checks) |
| 114 | +- XSS/CSRF/CORS protection (Next.js, Supabase) |
| 115 | +- Rate limiting on API routes |
| 116 | +- Use HTTPS in production |
| 117 | +- Store Together.ai API keys securely (never commit to repo) |
24 | 118 |
|
25 | | -To learn more about Next.js, take a look at the following resources: |
| 119 | +--- |
26 | 120 |
|
27 | | -- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. |
28 | | -- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. |
| 121 | +## Contributing |
29 | 122 |
|
30 | | -You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome! |
| 123 | +- PRs welcome! Follow conventional commits and run lint/tests before submitting. |
| 124 | +- See `knowledge_base/tasks.md` for roadmap and features. |
31 | 125 |
|
32 | | -## Deploy on Vercel |
| 126 | +--- |
33 | 127 |
|
34 | | -The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. |
| 128 | +## License |
35 | 129 |
|
36 | | -Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details. |
| 130 | +MIT. Not affiliated with OpenAI or ChatGPT. For educational/research use. |
0 commit comments