# SecureChat PHP Server

This is the server-side implementation for the SecureChat application using PHP. The server handles device authentication, message relay, and encrypted call routing while maintaining end-to-end encryption principles.

## Features

- Device-based authentication system
- Secure WebSocket connections for real-time messaging
- Message relay without storing unencrypted content
- Encrypted call routing (P2Server2P)
- Lightweight design for Mini PC/Intel NUC deployment

## Directory Structure

```
server/
├── api/                  # REST API endpoints
│   ├── auth/             # Authentication endpoints
│   ├── chat/             # Chat message endpoints
│   └── calls/            # Call signaling endpoints
├── websocket/            # WebSocket server for real-time communication
├── config/               # Configuration files
├── lib/                  # Shared libraries and utilities
├── database/             # Database scripts and migrations
└── public/               # Public entry points
```

## Requirements

- PHP 8.0 or higher
- MySQL/MariaDB
- Composer for dependency management
- Ratchet for WebSocket support
- SSL certificate for secure connections

## Setup Instructions

1. Install dependencies: `composer install`
2. Configure database connection in `config/database.php`
3. Run database migrations: `php database/migrate.php`
4. Configure server settings in `config/app.php`
5. Start WebSocket server: `php websocket/server.php`
6. Configure web server (Apache/Nginx) to point to the `public` directory

## Security Considerations

- All data is end-to-end encrypted on the client side
- Server only stores encrypted messages and cannot decrypt content
- Device authentication uses secure hashing and verification
- No plaintext passwords or messages are ever stored
- All connections require TLS/SSL