Fluentify Backend
AI-powered language learning platform backend built with Node.js, Express, and PostgreSQL.
๐ Quick Start with Docker
Prerequisites
- Docker Desktop installed and running
Setup
-
Clone the repository
git clone <repository-url> cd Backend
-
Start the application
docker-compose up --build
-
Access the application
- Backend API: http://localhost:5000
- Health Check: http://localhost:5000/health
- PostgreSQL: localhost:5432
That's it! The database will be automatically initialized with all tables.
๐ Environment Variables
All configuration is in the .env file:
DATABASE_URL=postgresql://postgres:postgres@postgres:5432/fluentify PORT=5000 NODE_ENV=development JWT_SECRET=<your-secret> GEMINI_API_KEY=<your-api-key>
๐ ๏ธ Development
Hot Reload
Code changes in the src/ directory are automatically detected and the server restarts.
View Logs
Stop Services
Reset Database
docker-compose down -v docker-compose up --build
๐ Database
PostgreSQL 16 is used with the following tables:
learners- User accountsadmins- Administrator accountslearner_preferences- User language preferencescourses- Generated language courses (with JSONB data)unit_progress- Progress tracking for unitslesson_progress- Progress tracking for lessonsexercise_attempts- Exercise completion trackinguser_stats- User XP and statistics
Tables are automatically created on first startup from src/database/01-tables.sql.
๐ API Endpoints
Authentication
POST /api/auth/signup/learner- Learner signupPOST /api/auth/signup/admin- Admin signupPOST /api/auth/login/learner- Learner loginPOST /api/auth/login/admin- Admin loginGET /api/auth/profile- Get user profile
Preferences
POST /api/preferences/learner- Save preferencesGET /api/preferences/learner- Get preferencesPUT /api/preferences/learner- Update preferencesDELETE /api/preferences/learner- Delete preferences
Courses
POST /api/courses/generate- Generate new courseGET /api/courses- Get learner's coursesGET /api/courses/:courseId- Get course detailsGET /api/courses/:courseId/lessons/:lessonId- Get lesson detailsPOST /api/courses/:courseId/lessons/:lessonId/complete- Complete lesson
Progress
GET /api/progress/courses- Get all coursesGET /api/progress/courses/:courseId- Get course progressPOST /api/progress/courses/:courseId/units/:unitId/lessons/:lessonId/complete- Mark lesson complete
User Management (Admin Only)
GET /api/admin/users/learners- Get all learners (with pagination & search)GET /api/admin/users/learners/:learnerId- Get learner details with statsPUT /api/admin/users/learners/:learnerId- Update learner (name, email)PUT /api/admin/users/learners/:learnerId/password- Reset learner passwordDELETE /api/admin/users/learners/:learnerId- Delete learner accountGET /api/admin/users/learners/:learnerId/courses- Get learner's courses
๐งช Testing
Test Gemini AI Integration
docker exec -it fluentify-backend npm run test-geminiAccess Backend Shell
docker exec -it fluentify-backend shAccess Database Shell
docker exec -it fluentify-postgres psql -U postgres -d fluentify # Once inside PostgreSQL shell: \l # List all databases \dt # List all tables \d table_name # Describe a table SELECT * FROM learners; # Query data \q # Exit
๐๏ธ Project Structure
Backend/
โโโ src/
โ โโโ config/ # Database configuration
โ โโโ controllers/ # Request handlers (auth, courses, progress, userManagement)
โ โโโ database/ # SQL schema files
โ โโโ middlewares/ # Express middlewares (auth, error handling)
โ โโโ repositories/ # Data access layer (data queries)
โ โโโ routes/ # API routes (auth, courses, admin)
โ โโโ services/ # Business logic (Gemini AI)
โ โโโ utils/ # Utilities (JWT, errors, responses)
โ โโโ server.js # Main application file
โโโ docker-compose.yml # Docker orchestration
โโโ Dockerfile # Docker image definition
โโโ .env # Environment variables
โโโ package.json # Dependencies
๐ง Tech Stack
- Runtime: Node.js 22
- Framework: Express.js
- Database: PostgreSQL 16
- AI: Google Gemini API
- Authentication: JWT
- Container: Docker & Docker Compose
๐ Features
- ๐ค AI-powered course generation using Google Gemini
- ๐ JWT-based authentication
- ๐ Progress tracking with XP and streaks
- ๐ฏ Unit and lesson management
- ๐ User statistics and achievements
- ๐ฅ Admin user management with CRUD operations
- ๐ Toast notification system for better UX
- ๐ Hot-reload development environment
๐ Troubleshooting
Services won't start?
docker-compose logs docker-compose down docker-compose build --no-cache docker-compose up
Port already in use?
Change ports in docker-compose.yml:
ports: - "3000:5000" # Change left side to different port
Database issues?
# Check database logs docker-compose logs postgres # Reset database docker-compose down -v docker-compose up --build
๐ License
MIT
๐ค Contributing
Pull requests are welcome!