# Sojorn Backend Engine (Golang)

Production-grade Golang backend migrated from Supabase Edge Functions.

## Tech Stack
- **Language**: Go 1.21+
- **Framework**: Gin Gonic
- **Database**: PostgreSQL with PostGIS
- **Auth**: JWT (compatible with Supabase)
- **Logging**: Zerolog
- **Deployment**: Docker / Systemd

## Getting Started

### Prerequisites
- Go 1.21 or higher
- PostgreSQL 15+ with PostGIS extension
- `golang-migrate` CLI (for migrations)

### Setup
1. Clone the repository
2. Copy `.env.example` to `.env` and fill in your details:
   ```bash
   cp .env.example .env
   ```
3. Install dependencies:
   ```bash
   go mod download
   ```
4. Run migrations:
   ```bash
   make migrate-up
   ```

### Running Locally
```bash
go run cmd/api/main.go
```
The server will start on `http://localhost:8080`.

## API Documentation

### Auth & Profiles
- `POST /api/v1/signup`: Complete profile creation after auth
- `GET /api/v1/profiles/:id`: Get user profile
- `GET /api/v1/profile`: Get current user profile

### Posts & Feed
- `POST /api/v1/posts`: Create a new post or beacon
- `GET /api/v1/feed`: Get personal feed

## Deployment

### Using Systemd (Ubuntu/Debian)
1. Edit `scripts/deploy.sh` with your VPS details.
2. Run the deployment script:
   ```bash
   ./scripts/deploy.sh
   ```

### Using Docker
```bash
docker build -t sojorn-api .
docker run -p 8080:8080 --env-file .env sojorn-api
```

## Migration Notes
- RLS policies have been moved to application-level middleware.
- Supabase-specific triggers for metrics are maintained in SQL migrations.
- E2EE session management is ported to handlers/services.
