# Flutter Backend API

This is a Node.js backend API for a Flutter application with user management and OTP authentication.

## Setup Instructions

1. Install Node.js (v14 or later) from https://nodejs.org/

2. Clone this repository to your local machine

3. Install dependencies:
   ```bash
   npm install
   ```

4. Create an 'uploads' directory:
   ```bash
   mkdir uploads
   ```

5. Start the server:
   ```bash
   npm run dev
   ```

The server will start at http://localhost:3000

## API Endpoints

### Users

- GET `/api/users` - Get all users
- GET `/api/users/:phone` - Get user by phone number
- POST `/api/users` - Create new user
- PUT `/api/users/:phone` - Update user

### Request Examples

#### Create User
```curl
curl -X POST -H "Content-Type: multipart/form-data" \
  -F "phone_number=+1234567890" \
  -F "username=John Doe" \
  -F "email=john@example.com" \
  -F "address=123 Main St" \
  -F "profile_picture=@/path/to/image.jpg" \
  http://localhost:3000/api/users
```

#### Get User
```curl
curl http://localhost:3000/api/users/+1234567890
```

## Flutter Integration

Add this code to your Flutter app to interact with the API:

```dart
import 'package:http/http.dart' as http;
import 'dart:convert';

class ApiService {
  static const String baseUrl = 'http://10.0.2.2:3000'; // Use this for Android emulator
  // static const String baseUrl = 'http://localhost:3000'; // Use this for iOS simulator

  Future<Map<String, dynamic>> getUser(String phone) async {
    final response = await http.get(Uri.parse('$baseUrl/api/users/$phone'));
    return json.decode(response.body);
  }

  Future<void> createUser({
    required String phone,
    required String username,
    required String email,
    required String address,
    File? profilePicture,
  }) async {
    var request = http.MultipartRequest('POST', Uri.parse('$baseUrl/api/users'));
    
    request.fields['phone_number'] = phone;
    request.fields['username'] = username;
    request.fields['email'] = email;
    request.fields['address'] = address;
    
    if (profilePicture != null) {
      request.files.add(await http.MultipartFile.fromPath(
        'profile_picture',
        profilePicture.path,
      ));
    }
    
    await request.send();
  }
}
```