|
1 | 1 | # 🤖 AI Code Explainer |
2 | 2 |
|
3 | | -[](https://nextjs.org/) [](https://www.typescriptlang.org/) [](https://tailwindcss.com/) [](https://www.deepseek.com/) |
| 3 | +[](https://nextjs.org/) [](https://www.typescriptlang.org/) [](https://tailwindcss.com/) [](https://www.groq.com/) |
4 | 4 |
|
5 | | -A simple web application that translates complex code into plain, easy-to-understand English. Paste any code snippet and get an instant explanation, powered by the DeepSeek Coder API. |
| 5 | +AI Code Explainer is a bilingual coding buddy that turns confusing code into friendly explanations. Paste any snippet, pick the tone you prefer, and get practical insights in English or Bengali—all powered by Groq’s `llama-3.1-8b-instant` model. |
6 | 6 |
|
7 | 7 | --- |
8 | 8 |
|
9 | | -## ✨ Features |
| 9 | +## ✨ Highlights |
10 | 10 |
|
11 | | -- **Simple Interface:** A clean, minimal UI with a single text area for pasting code. |
12 | | -- **Instant Explanations:** Get real-time, human-like explanations for any code snippet. |
13 | | -- **Multi-Language Support:** Understands JavaScript, Python, React, SQL, Regex, and more. |
14 | | -- **Modern Tech:** Built with the latest Next.js 14 (App Router) and Server Actions. |
| 11 | +- **Bilingual output** – Switch between English and Bengali explanations without leaving the page. |
| 12 | +- **Custom teaching styles** – Choose explanation depth, style (detailed, concise, beginner), target audience, and whether to include examples. |
| 13 | +- **Quick start snippets** – One-click sample snippets help you test the flow instantly. |
| 14 | +- **Dark/light aware** – Theme toggle with persisted preference plus responsive layout built on shadcn/ui components. |
| 15 | +- **Helpful feedback** – Friendly loading states, validation, and actionable error messages keep the UX smooth. |
15 | 16 |
|
16 | 17 | --- |
17 | 18 |
|
18 | | -## 🚀 Tech Stack |
| 19 | +## 🧰 Tech Stack |
19 | 20 |
|
20 | | -- **Framework:** [Next.js](https://nextjs.org/) 14 (App Router) |
| 21 | +- **Framework:** [Next.js](https://nextjs.org/) 16 (App Router, Route Handlers) |
| 22 | +- **UI:** [React](https://react.dev/) 19 + [shadcn/ui](https://ui.shadcn.com/) + [Radix UI](https://www.radix-ui.com/) |
21 | 23 | - **Language:** [TypeScript](https://www.typescriptlang.org/) |
22 | | -- **Styling:** [Tailwind CSS](https://tailwindcss.com/) |
23 | | -- **Platform:** [Vercel](https://vercel.com/) |
24 | | -- **AI:** [DeepSeek API](https://www.deepseek.com/) (deepseek-coder model) |
| 24 | +- **Styling:** [Tailwind CSS](https://tailwindcss.com/) 4 + `tailwind-merge` |
| 25 | +- **Icons:** [lucide-react](https://lucide.dev/) |
| 26 | +- **AI runtime:** [Groq API](https://console.groq.com/) (`llama-3.1-8b-instant`) |
25 | 27 |
|
26 | 28 | --- |
27 | 29 |
|
28 | | -## 🛠️ Getting Started |
| 30 | +## 🚀 Getting Started |
29 | 31 |
|
30 | | -Follow these instructions to get a copy of the project running on your local machine for development and testing. |
| 32 | +Follow the steps below to set up the project locally. |
31 | 33 |
|
32 | 34 | ### Prerequisites |
33 | 35 |
|
34 | | -- [Node.js](https://nodejs.org/en/) (Version 18.x or newer) |
35 | | -- A DeepSeek API Key (Get yours from the [DeepSeek Platform](https://platform.deepseek.com/)) |
| 36 | +- [Node.js](https://nodejs.org/en/) 18 or newer |
| 37 | +- [pnpm](https://pnpm.io/) 9+ (or npm/yarn if you prefer) |
| 38 | +- A Groq API key with access to `llama-3.1-8b-instant` |
36 | 39 |
|
37 | | -### 1. Clone the Repository |
| 40 | +### Installation |
38 | 41 |
|
39 | 42 | ```bash |
40 | | -git clone [https://github.com/your-username/ai-code-explainer.git](https://github.com/your-username/ai-code-explainer.git) |
| 43 | +git clone https://github.com/maker-shihab/ai-code-explainer.git |
41 | 44 | cd ai-code-explainer |
| 45 | +pnpm install # or npm install / yarn install |
42 | 46 | ``` |
43 | 47 |
|
44 | | -### 2. Install Dependencies |
| 48 | +### Environment Variables |
| 49 | + |
| 50 | +Create a `.env.local` file in the project root: |
45 | 51 |
|
46 | 52 | ```bash |
47 | | -npm install |
48 | | -# or |
49 | | -yarn install |
| 53 | +GROQ_API_KEY=your_groq_api_key |
50 | 54 | ``` |
51 | 55 |
|
52 | | -### 3. Setup Environment Variables |
| 56 | +Optional integrations already scaffolded in `lib/` can use: |
53 | 57 |
|
54 | | -Create a new file named `.env.local` in the root of your project and add your DeepSeek API key. |
| 58 | +```bash |
| 59 | +DEEPSEEK_API_KEY=optional_if_you_enable_deepseek |
| 60 | +GOOGLE_GEMINI_API_KEY=optional_if_you_enable_gemini |
| 61 | +HUGGING_FACE_API_KEY=optional_if_you_enable_huggingface |
| 62 | +``` |
| 63 | + |
| 64 | +### Start the Dev Server |
55 | 65 |
|
56 | 66 | ```bash |
57 | | -DEEPSEEK_API_KEY="YOUR_SECRET_DEEPSEEK_API_KEY_HERE" |
| 67 | +pnpm dev |
| 68 | +# or: npm run dev / yarn dev |
58 | 69 | ``` |
59 | 70 |
|
60 | | -### 4. Run the Development Server |
| 71 | +Then visit [http://localhost:3000](http://localhost:3000). |
| 72 | + |
| 73 | +### Useful Scripts |
| 74 | + |
| 75 | +- `pnpm build` – create a production build |
| 76 | +- `pnpm start` – run the production server |
| 77 | +- `pnpm lint` – check code quality with ESLint |
| 78 | + |
| 79 | +--- |
| 80 | + |
| 81 | +## 🧑💻 How to Use It |
| 82 | + |
| 83 | +1. Paste or type your code into the **Your Code** editor. |
| 84 | +2. Adjust filters to match your learning needs (language, depth, style, target audience, examples). |
| 85 | +3. Hit **Explain Code** and wait a moment while Groq generates the response. |
| 86 | +4. Review the explanation in the **AI Explanation** panel and tweak settings if you’d like a different tone. |
| 87 | + |
| 88 | +Tip: Use the Quick Start buttons to prefill common React/Python/JavaScript snippets for demos. |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## 🏗️ Architecture Overview |
| 93 | + |
| 94 | +- `app/page.tsx` – Client-side UI with state, validation, and user interactions. |
| 95 | +- `components/filters/advanced-filters.tsx` – Reusable filter and preference controls. |
| 96 | +- `app/api/explain/route.ts` – Next.js route handler that sanitizes input and proxies Groq. |
| 97 | +- `lib/groq.ts` – GroqService wrapper that crafts bilingual prompts and calls the API. |
| 98 | +- `types/index.ts` – Shared TypeScript contracts for requests/responses. |
| 99 | +- `app/providers/theme-provider.tsx` & `components/ui/theme-toggle.tsx` – Theming logic with persisted preferences. |
| 100 | + |
| 101 | +### API Contract |
| 102 | + |
| 103 | +`POST /api/explain` |
61 | 104 |
|
62 | 105 | ```bash |
63 | | -npm run dev |
64 | | -# or |
65 | | -yarn dev |
| 106 | +curl -X POST http://localhost:3000/api/explain \ |
| 107 | + -H "Content-Type: application/json" \ |
| 108 | + -d '{ |
| 109 | + "code": "const greet = (name) => `Hello, ${name}!`;", |
| 110 | + "language": "english", |
| 111 | + "explanationStyle": "beginner", |
| 112 | + "includeExamples": true, |
| 113 | + "programmingLanguage": "auto", |
| 114 | + "explanationDepth": "basic", |
| 115 | + "targetAudience": "student" |
| 116 | + }' |
66 | 117 | ``` |
67 | 118 |
|
68 | | -Open [Local Host](http://localhost:3000) with your browser to see the application. |
| 119 | +--- |
| 120 | + |
| 121 | +## 🚢 Deployment |
69 | 122 |
|
70 | | -## ⚙️ How It Works |
| 123 | +The project is optimized for [Vercel](https://vercel.com/) (default Next.js hosting), but any platform that supports Next.js 16 will work: |
71 | 124 |
|
72 | | -1. The user enters their code into the `<textarea>` on the client-side page (`app/page.tsx`). |
73 | | -2. Clicking the "Explain" button triggers a **Next.js Server Action** (`explainCode`) defined in `app/actions.ts`. |
74 | | -3. This Server Action (running securely on the server) fetches the `DEEPSEEK_API_KEY` from environment variables. |
75 | | -4. It makes a `POST` request to the DeepSeek API, sending the user's code and a system prompt. |
76 | | -5. The AI's response is parsed and returned directly to the client component. |
77 | | -6. The client component updates its state with the explanation, displaying it to the user. |
| 125 | +1. Set environment variables in your hosting dashboard (`GROQ_API_KEY` at minimum). |
| 126 | +2. Run the production build: `pnpm build`. |
| 127 | +3. Serve with `pnpm start` or let Vercel handle the build & deploy pipeline automatically. |
78 | 128 |
|
79 | 129 | --- |
80 | 130 |
|
|
0 commit comments