Polyglot is a lightweight AI-powered translation web app built with React, TypeScript, Express, and OpenAI.
- Welcome screen with Polyglot branding, tagline, and โGet Startedโ entry point
- Route-based flow between
/(welcome) and/app(translator) - Translate text into English, Spanish, French, or Japanese
- Chat-style translation history with per-message rendering
- Inline loading animation while translations are in progress
- Press Enter to submit and Shift + Enter for multiline input
- Animated language greeting elements (โHello,โ โยกHola!,โ โBonjour,โ and โใใใซใกใฏโ)
- Auto-scroll to the newest message
- Client-side validation for empty input
- User-friendly error handling for failed translation requests
- Home button to return to the welcome screen
The frontend manages translation state through a custom hook and sends the user text and target language to the backend. The backend sanitizes input, applies rate limiting, forwards the request to OpenAI, and returns a normalized translation response for UI rendering.
- React
- TypeScript
- Vite
- React Router
- Motion
- CSS
- Vitest + Testing Library + MSW
- Node.js
- Express
- TypeScript
- OpenAI API
- CORS
- Express Rate Limit
GET /healthPOST /translate
{
"userPrompt": "Hello, how are you today?",
"targetLanguage": "Japanese"
}{
"message": {
"input": "Hello, how are you today?",
"output": "ใใใซใกใฏใใๅ
ๆฐใงใใ๏ผ"
}
}- Node.js 18+
- npm
git clone <your-repository-url>
cd polyglotcd frontend
npm installcd ../backend
npm installCreate .env files in both backend and frontend directories.
OPENAI_API_KEY=your_openai_api_key
PORT=5000
ALLOWED_ORIGINS=http://localhost:5173,https://polyglot-static.onrender.comVITE_API_BASE_URL=http://localhost:5000cd backend
npm run devcd frontend
npm run devcd frontend
npm testcd frontend
npm run test:coveragepolyglot/
โโโ frontend/
โ โโโ src/
โ โ โโโ pages/
โ โ โ โโโ App.tsx # Translator page container
โ โ โ โโโ WelcomeScreen.tsx # Landing page with branding and app entry
โ โ โ โโโ components/
โ โ โ โ โโโ TranslationForm.tsx
โ โ โ โ โโโ TranslationMessages.tsx
โ โ โ โโโ hooks/
โ โ โ โโโ useTranslationChat.ts # Translation chat state, submit flow, and UI handlers
โ โ โโโ config/
โ โ โ โโโ deploy.config.ts # Frontend deploy/runtime settings
โ โ โ โโโ endpoints.config.ts # API endpoint definitions used by the client
โ โ โโโ test/ # UI and routing-focused component tests
โ โ โโโ utils/
โ โ โ โโโ requests.ts # HTTP request helpers for backend communication
โ โ โโโ index.css # Global styles and Polyglot UI theme
โ โโโ public/ # Static assets served as-is
โ โโโ dist/ # Production build output
โโโ backend/
โ โโโ src/
โ โ โโโ app.ts # Express app setup, middleware, and route registration
โ โ โโโ controllers/
โ โ โ โโโ translate.controllers.ts # Translation endpoint logic and OpenAI integration
โ โ โโโ routes/
โ โ โ โโโ translate.routes.ts # Route registration for translate API
โ โ โโโ middleware/
โ โ โโโ sanitize.middleware.ts # Request input sanitization and validation hardening
โ โ โโโ rateLimiter.middleware.ts # API rate limiting to protect backend resources
โ โโโ dist/ # Compiled backend output
โโโ README.md
- Request sanitization middleware
- Rate limiting
- CORS configuration
- Error handling for missing input, unknown endpoints, and server failures
- Add support for more languages
- Add copy-to-clipboard functionality
- Save translation history
- Add user authentication
- Improve accessibility
- Add backend integration tests