Skip to content

emrekurum/MovieRecommendationApp

Repository files navigation

🎬 Movie Recommendation App

A modern React Native (Expo) mobile application with Node.js/Express backend for movie taste analysis and recommendation system.

πŸ“‹ Table of Contents

✨ Features

Frontend (React Native + Expo)

  • βœ… User Authentication: Secure registration and login system
  • βœ… Movie Taste Quiz: Interactive quiz to analyze user preferences
  • βœ… Profile Management: Automatically generated movie taste profile
  • βœ… Token-Based Security: JWT-protected API calls
  • βœ… Offline Support: Session persistence with AsyncStorage
  • βœ… Expo Go Support: Quick testing and development via QR code

Backend (Node.js + Express)

  • βœ… RESTful API: Modern and scalable API architecture
  • βœ… JWT Authentication: Secure token-based authentication
  • βœ… PostgreSQL Integration: Robust and reliable database
  • βœ… CORS Support: Cross-origin request configuration
  • βœ… Transaction Management: Transaction support for data integrity
  • βœ… Profile Analysis: Automatic movie taste profile calculation

πŸ›  Tech Stack

Frontend

  • React Native 0.74.3
  • Expo SDK 51
  • TypeScript 5.0.4
  • React Navigation 7.x
  • AsyncStorage - Local storage
  • Expo Constants - Environment variables

Backend

  • Node.js 18+
  • Express 5.1.0
  • PostgreSQL - Database
  • JWT (jsonwebtoken) - Token-based authentication
  • bcryptjs - Password hashing
  • CORS - Cross-origin support

πŸ“¦ Requirements

  • Node.js 18 or higher
  • npm 9+ or yarn
  • PostgreSQL 12+ (local or remote)
  • Expo Go app (for mobile device testing)
  • Git (for version control)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/emrekurum/MovieRecommendationApp.git
cd MovieRecommendationApp

2. Install Frontend Dependencies

npm install

3. Install Backend Dependencies

cd MovieRecommendationApp-Backend
npm install
cd ..

4. Create the Database

Create a new database in PostgreSQL:

CREATE DATABASE movierecommendation;

Apply the schema:

psql -U postgres -d movierecommendation -f MovieRecommendationApp-Backend/database/schema.sql

Or run the schema.sql file using your PostgreSQL client.

βš™οΈ Configuration

Backend Configuration

Create a .env file in the MovieRecommendationApp-Backend directory:

cd MovieRecommendationApp-Backend
cp .env.example .env

Edit the .env file:

# PostgreSQL Database Settings
DB_USER=postgres
DB_PASSWORD=your_password_here
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=movierecommendation

# Server Port
PORT=3001

# JWT Secret Key (Use a strong key!)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production

⚠️ Important: Use a strong and random key for JWT_SECRET in production!

Frontend Configuration

Local Development (Emulator/Simulator)

By default:

  • iOS Simulator: http://localhost:3001
  • Android Emulator: http://10.0.2.2:3001

Physical Device or Over LAN

Find the local IP address of the machine running the backend server:

Windows:

ipconfig

macOS/Linux:

ifconfig
# or
ip addr

Then set the environment variable when starting Expo:

EXPO_PUBLIC_API_URL=http://192.168.1.100:3001 npm start

Or create a .env file (in the root directory):

EXPO_PUBLIC_API_URL=http://192.168.1.100:3001

Note: Mobile device and computer must be on the same Wi-Fi network.

🎯 Usage

Starting the Backend

cd MovieRecommendationApp-Backend
npm run dev  # Development mode (auto-restart with nodemon)
# or
npm start    # Production mode

If the backend is running successfully, you'll see:

Backend server running at http://localhost:3001
Successfully connected to PostgreSQL database.

Starting the Frontend

npm start

When Expo CLI starts:

  1. A QR code will appear in the terminal
  2. Open the Expo Go app on your mobile device
  3. Scan the QR code
  4. The app will load and run

Alternative Methods:

  • npm run android - Open in Android emulator
  • npm run ios - Open in iOS simulator (macOS only)
  • npm run web - Open in web browser

Application Flow

  1. Register: Create a new user account
  2. Login: Sign in with your created account
  3. Take Quiz: Complete the movie taste test
  4. View Profile: See your automatically generated profile

πŸ“‘ API Documentation

Authentication Endpoints

POST /api/auth/register

Register a new user.

Request Body:

{
  "username": "john_doe",
  "email": "[email protected]",
  "password": "password123"
}

Response (201):

{
  "message": "User successfully registered!",
  "user": {
    "user_id": 1,
    "username": "john_doe",
    "email": "[email protected]",
    "created_at": "2024-01-01T00:00:00.000Z"
  }
}

POST /api/auth/login

User login.

Request Body:

{
  "email": "[email protected]",
  "password": "password123"
}

Response (200):

{
  "message": "Login successful!",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "user_id": 1,
    "username": "john_doe",
    "email": "[email protected]"
  }
}

Quiz Endpoints

GET /api/quiz/questions

Get quiz questions. (Token optional)

Headers:

Authorization: Bearer <token>  (Optional)

Response (200):

[
  {
    "questionId": 1,
    "questionText": "What type of movies do you prefer?",
    "questionOrder": 1,
    "answers": [
      {
        "answerId": 1,
        "answerText": "Action"
      },
      {
        "answerId": 2,
        "answerText": "Drama"
      }
    ]
  }
]

POST /api/quiz/submit

Submit quiz answers and update user profile. (Token required)

Headers:

Authorization: Bearer <token>

Request Body:

{
  "answers": [
    {
      "questionId": 1,
      "chosenAnswerId": 1
    },
    {
      "questionId": 2,
      "chosenAnswerId": 3
    }
  ]
}

Response (200):

{
  "message": "Quiz answers successfully submitted and your profile has been updated!",
  "profile": {
    "summary": "Your movie taste generally includes: action, thriller, adventure.",
    "tags": ["action", "thriller", "adventure", "drama", "emotional"]
  },
  "user": {
    "user_id": 1,
    "username": "john_doe",
    "email": "[email protected]"
  }
}

πŸ—„οΈ Database Schema

Tables

Users

  • user_id (SERIAL PRIMARY KEY)
  • username (VARCHAR, UNIQUE)
  • email (VARCHAR, UNIQUE)
  • password_hash (VARCHAR)
  • taste_profile_summary (TEXT)
  • taste_profile_tags (TEXT[])
  • created_at (TIMESTAMP)

QuizQuestions

  • question_id (SERIAL PRIMARY KEY)
  • question_text (TEXT)
  • question_order (INTEGER)
  • created_at (TIMESTAMP)

QuizAnswers

  • answer_id (SERIAL PRIMARY KEY)
  • question_id (INTEGER, FOREIGN KEY)
  • answer_text (TEXT)
  • answer_tags (TEXT[])
  • created_at (TIMESTAMP)

UserQuizResponses

  • user_id (INTEGER, FOREIGN KEY)
  • question_id (INTEGER, FOREIGN KEY)
  • chosen_answer_id (INTEGER, FOREIGN KEY)
  • submitted_at (TIMESTAMP)
  • PRIMARY KEY (user_id, question_id)

See MovieRecommendationApp-Backend/database/schema.sql for detailed schema.

πŸ”§ Development

Project Structure

MovieRecommendationApp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # Reusable components
β”‚   β”œβ”€β”€ config/              # Configuration files
β”‚   β”‚   └── apiConfig.ts     # API URL configuration
β”‚   β”œβ”€β”€ context/             # React Contexts
β”‚   β”‚   └── AuthContext.tsx  # Authentication context
β”‚   β”œβ”€β”€ navigation/          # Navigation configuration
β”‚   β”‚   β”œβ”€β”€ AuthNavigator.tsx
β”‚   β”‚   └── MainAppNavigator.tsx
β”‚   β”œβ”€β”€ screens/             # Screen components
β”‚   β”‚   β”œβ”€β”€ Auth/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginScreen.tsx
β”‚   β”‚   β”‚   └── RegisterScreen.tsx
β”‚   β”‚   └── Main/
β”‚   β”‚       β”œβ”€β”€ HomeScreen.tsx
β”‚   β”‚       └── QuizScreen.tsx
β”‚   └── services/            # API services
β”‚       β”œβ”€β”€ authService.ts
β”‚       β”œβ”€β”€ quizService.ts
β”‚       └── httpClient.ts
β”œβ”€β”€ MovieRecommendationApp-Backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── db.js        # Database connection
β”‚   β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   β”‚   └── authMiddleware.js  # JWT verification
β”‚   β”‚   └── routes/
β”‚   β”‚       β”œβ”€β”€ authRoutes.js
β”‚   β”‚       └── quizRoutes.js
β”‚   β”œβ”€β”€ database/
β”‚   β”‚   └── schema.sql       # Database schema
β”‚   └── server.js            # Express server
β”œβ”€β”€ App.tsx                  # Main application component
β”œβ”€β”€ app.json                 # Expo configuration
└── package.json

Code Standards

  • TypeScript: All frontend code is written in TypeScript
  • ESLint: ESLint is used for code quality
  • Async/Await: async/await is preferred for promises
  • Error Handling: All API calls are protected with try-catch

Adding New Features

  1. New Screen: Create a new folder under src/screens/
  2. Navigation: Add route in src/navigation/
  3. API Endpoint: Create new route in backend
  4. Service: Add new service function in frontend

πŸ› Troubleshooting

Backend Connection Issues

Problem: PostgreSQL connection error

Solution: Check database credentials in .env file. Ensure PostgreSQL service is running.

Problem: Port already in use

Solution: Change PORT value in .env file or terminate the process using the port.

Frontend Connection Issues

Problem: API requests failing

Solution: 
1. Ensure backend is running
2. Check EXPO_PUBLIC_API_URL environment variable
3. Mobile device and computer must be on same Wi-Fi network
4. Check firewall settings

Problem: App not opening in Expo Go

Solution:
1. Ensure Expo Go app is up to date
2. Run npm start again
3. Rescan QR code
4. Ensure Metro bundler is running

Database Issues

Problem: Table not found error

Solution: Run schema.sql file to create database schema.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Contributors

  • Emre Kurum - Project owner and developer

πŸ™ Acknowledgments

  • React Native and Expo community
  • All open-source library developers

Note: This project is for educational and development purposes. Additional security measures should be taken for production use.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published