# Sendshake Serverside (Addin/Plugin) - Local Development

## Overview

The Sendshake Serverside service provides the API and functionality for PowerPoint add-ins and plugins. It runs as a PHP service and handles requests from various Sendsteps integrations.

## Prerequisites

- Docker and docker-compose installed
- No local PHP installation required - everything runs in Docker containers

## Getting Started

### Quick Start

1) Clone all repositories
```bash
./scripts/clone-all.sh
```
When prompted, copy from Confluence:
- `api/docker/.env.local`
- `dashboard/docker/.env.local`

2) Build and start all services
```bash
./scripts/start-all.sh
```

3) Import the development database (in API project)
- host: 127.0.0.1, port: 8003, user: root, pass: database_user_password, db: addins

Initialization is automated via Dockerfiles/Docker Compose and shared scripts.

### 1. Start the Service

```bash
# Navigate to sendshake-serverside directory
cd sendshake-serverside

# Start the service
docker-compose up -d

# View logs
docker-compose logs -f
```

Or use the platform-wide script:

```bash
# From project root
./scripts/start-all.sh
```

### 2. Install Dependencies

If you need to install or update PHP dependencies:

```bash
# Install composer dependencies
docker-compose run --rm composer install

# Or manually
docker-compose exec addin composer install
```

## Service URL

- **Service**: http://plugin.sendsteps.localhost
- **Container Name**: `addin`
- **Network**: `sendsteps` (connects to other platform services)

## Container Access

### Execute Commands

```bash
# Run PHP commands
docker-compose exec addin php <command>

# Run composer commands
docker-compose exec addin composer <command>

# View logs
docker-compose logs -f addin
```

### Interactive Shell

```bash
# Enter the container
docker-compose exec addin bash
```

## Configuration

The service configuration is handled through PHP files in the `inc/` directory:

- `inc/settings.php` - Main configuration (may need to be created from `inc/settings.php.default`)
- `inc/payment_settings.php` - Payment configuration (may need to be created from `inc/payment_settings.php.default`)

Ensure these files exist with appropriate values for local development.

## Common Tasks

### Installing PHP Dependencies

```bash
docker-compose run --rm composer install
```

### Checking Service Status

```bash
# Check if container is running
docker ps | grep addin

# Check logs
docker-compose logs addin
```

### Restarting the Service

```bash
# Restart just this service
docker-compose restart addin

# Or restart all platform services
cd ../../
./scripts/restart-all.sh
```

## Troubleshooting

### Service Not Starting

1. Check if Docker is running
2. Verify the `sendsteps` network exists:
   ```bash
   docker network inspect sendsteps
   ```
3. Check container logs:
   ```bash
   docker-compose logs addin
   ```

### Connection Issues

Ensure the service is on the `sendsteps` network and can communicate with other services:
- API: `http://api.sendsteps.localhost`
- Node.js: `http://nodejs:8001`

### Dependencies Not Found

Run composer install:
```bash
docker-compose run --rm composer install
```

### Configuration Files Missing

Copy default configuration files:
```bash
cd sendshake-serverside
cp inc/settings.php.default inc/settings.php
cp inc/payment_settings.php.default inc/payment_settings.php
```

Then edit these files with appropriate local development values.

## Development Notes

### Volume Mounting

Source code is mounted from your local machine:
- Changes to PHP files are immediately visible
- Dependencies installed via composer persist in `vendor/`
- No container rebuild needed for code changes

### Network Communication

The service communicates with other platform services via Docker network:
- API service: `http://api.sendsteps.localhost` (from host) or `http://api` (from container)
- Other services use their Docker service names within the network

## Next Steps

- See `README.md` for more detailed setup instructions
- See other service `LOCAL-DEVELOPMENT.md` files for integration details
- Check configuration files in `inc/` directory for all configurable options

