Files
2026-11-25 12:07:55 +05:30

116 lines
4.2 KiB
Markdown

# AI India Innovations — Web Platform
Full-stack TypeScript web application for **AI India Innovations (AIII)** featuring a React SPA frontend, interactive UI animations, and an Express backend with multi-turn Gemini API chat integration.
## Tech Stack
### Frontend
- **React 19** (`react`, `react-dom`) — Component-based UI
- **TypeScript 5.8** — Static typing (`ES2022`, `react-jsx`)
- **Vite 6** (`vite`, `@vitejs/plugin-react`) — Dev server, HMR, and production bundling
- **Tailwind CSS v4** (`@tailwindcss/vite`, `tailwindcss`, `autoprefixer`) — Utility-first styling
- **Motion** (`motion`) — UI animations and transitions
- **Lucide React** (`lucide-react`) — Iconography
### Backend & AI
- **Node.js & Express 4** (`express`) — HTTP server, API routes, and static/SPA serving
- **Google GenAI SDK** (`@google/genai`) — Multi-turn chat completions (`/api/chat`) with model fallback handling
- **dotenv** (`dotenv`) — Environment variable loading
### Build & Tooling
- **tsx** — TypeScript execution for development (`server.ts`)
- **esbuild** — Server bundling to CommonJS (`dist/server.cjs`)
- **TypeScript Compiler** (`tsc --noEmit`) — Type checking
---
## Project Structure
```text
├── public/ # Static assets served at /
├── src/
│ ├── components/ # UI views, modals, navbar, chatbot, and section components
│ ├── context/ # React context providers (ThemeContext)
│ ├── data/ # Static domain data (solutions, industries, GCC, blogs, site data)
│ ├── imports/ # Bundled image assets
│ ├── App.tsx # Root application component and view routing
│ ├── index.css # Global styles and Tailwind CSS entry
│ ├── main.tsx # React DOM entry point
│ └── types.ts # Shared TypeScript interfaces and types
├── index.html # HTML entry point
├── server.ts # Express server, API endpoints, and Vite middleware/static serving
├── vite.config.ts # Vite configuration and path alias (@ -> project root)
├── tsconfig.json # TypeScript compiler configuration
└── package.json # Dependencies and npm scripts
```
---
## Prerequisites
- **Node.js** (v20+ recommended)
- **npm**
---
## Environment Variables
Create a `.env` file in the project root (see `.env.example`):
| Variable | Required | Description |
| --- | --- | --- |
| `GEMINI_API_KEY` | Optional (required for live `/api/chat` responses) | API key used by `@google/genai` on the backend. Without it, `/api/chat` returns a fallback message. |
| `NODE_ENV` | Optional | Set to `production` to serve built static assets from `dist/` instead of Vite dev middleware. |
| `DISABLE_HMR` | Optional | Set to `true` to disable Vite HMR and file watching. |
---
## Getting Started
1. **Install dependencies:**
```bash
npm install
```
2. **Run in development mode** (starts Express + Vite middleware on port `3000`):
```bash
npm run dev
```
3. **Type-check:**
```bash
npm run lint
```
4. **Build for production** (builds client to `dist/` and bundles `server.ts` to `dist/server.cjs`):
```bash
npm run build
```
5. **Run production server:**
```bash
NODE_ENV=production npm start
```
---
## Available Scripts
| Script | Command | Description |
| --- | --- | --- |
| `dev` | `tsx server.ts` | Starts the Express + Vite development server on `http://0.0.0.0:3000` |
| `build` | `vite build && esbuild server.ts --bundle --platform=node --format=cjs --packages=external --sourcemap --outfile=dist/server.cjs` | Builds frontend assets and bundles the Node server |
| `start` | `node dist/server.cjs` | Runs the compiled production server |
| `preview` | `vite preview` | Previews the built Vite frontend |
| `lint` | `tsc --noEmit` | Runs TypeScript type checking |
| `clean` | `rm -rf dist server.js` | Removes build artifacts |
---
## API Endpoints
- **`GET /api/health`**
Returns server status, whether `GEMINI_API_KEY` is configured, and an ISO timestamp.
- **`POST /api/chat`**
Accepts `{ message, history?, model?, rolePreset? }` and returns `{ text, model }` using `@google/genai` with a model fallback chain.