A RESTful API backend for a language learning platform built with Node.js, Express, TypeScript, and MongoDB.
- User Authentication: Registration, login, token refresh, and JWT-based authentication
- Password Management: Forgot password and password reset functionality with email notifications
- AI-Powered Chat: Integration with OpenRouter API for AI-assisted language learning conversations
- Course Progress Tracking: Save and retrieve user progress across different courses and lessons
- Secure: bcrypt password hashing, JWT tokens, and CORS configuration
- Runtime: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: MongoDB with Mongoose ODM
- Authentication: JWT (jsonwebtoken) + bcryptjs
- Email: Nodemailer
- AI Integration: OpenRouter API via Axios
- Development: ts-node-dev for hot reload
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- npm or yarn package manager
Make sure to also check out the frontend repository for this project: Language Hub Frontend
Backend Deployed on: Language Hub Backend API
- Clone the repository:
git clone https://github.com/hasinduudara/RAD_Final_Project_Backend.git
cd backend- Install dependencies:
npm install- Create a
.envfile in the root directory with the following variables:
# Server Configuration
PORT=5000
# Database
MONGO_URI=your_mongodb_connection_string
# JWT Secrets
JWT_SECRET=your_jwt_secret_key
JWT_REFRESH_SECRET=your_jwt_refresh_secret_key
# Email Configuration (for password reset)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USER=your_email@gmail.com
EMAIL_PASS=your_email_password
# OpenRouter API (for AI chat)
OPENROUTER_API_KEY=your_openrouter_api_key
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173Run the development server with hot reload:
npm run devThe server will start on http://localhost:5000 (or the PORT specified in your .env file).
- Build the TypeScript code:
npm run build- Start the production server:
npm startbackend/
├── src/
│ ├── controllers/ # Request handlers
│ │ ├── chatController.ts
│ │ ├── course.controller.ts
│ │ ├── password.controller.ts
│ │ └── user.controller.ts
│ ├── middleware/ # Custom middleware
│ │ └── user.ts # Authentication middleware
│ ├── models/ # MongoDB schemas
│ │ ├── Chat.model.ts
│ │ ├── CourseProgress.model.ts
│ │ ├── resetToken.model.ts
│ │ └── user.model.ts
│ ├── routes/ # API routes
│ │ ├── chatRoutes.ts
│ │ ├── courseRoutes.ts
│ │ ├── password.routes.ts
│ │ └── user.ts
│ ├── utils/ # Utility functions
│ │ ├── mail.ts
│ │ ├── openrouterClient.ts
│ │ └── tokens.ts
│ └── index.ts # Application entry point
├── package.json
├── tsconfig.json
└── .env
POST /register- Register a new userPOST /login- User loginPOST /refresh- Refresh access tokenGET /welcome- Protected route example
POST /forgot- Request password reset emailPOST /reset- Reset password with token
POST /- Create new chat sessionPOST /message- Send message to AIGET /:chatId- Get chat historyGET /user/:userId- Get all user chatsDELETE /:chatId- Delete chat
POST /save-progress- Save user course progressGET /progress/:userId/:course- Get user progress for a course
The API uses JWT (JSON Web Tokens) for authentication. Protected routes require a valid JWT token in the Authorization header:
Authorization: Bearer <your_jwt_token>
CORS is configured to accept requests from:
http://localhost:5173(default Vite frontend)
Update the CORS origin in src/index.ts to match your frontend URL.
express- Web frameworkmongoose- MongoDB ODMjsonwebtoken- JWT authenticationbcryptjs- Password hashingnodemailer- Email sendingaxios- HTTP client for OpenRouter APIcors- CORS middlewaredotenv- Environment variables
typescript- TypeScript compilerts-node-dev- Development server with hot reload@types/*- TypeScript type definitions
The API returns appropriate HTTP status codes:
200- Success201- Created400- Bad Request401- Unauthorized404- Not Found500- Internal Server Error
ISC
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
For support, email hasiduudara@gmail.com or open an issue in the repository.
Made with ❤️ for language learners worldwide