# Go Backend API

## Framework

- **Fiber v3** (Go web framework)
- **MongoDB** (Official driver v1.17.1)
- **Socket.io** (zishang520/socket.io v2.3.5)
- **Port:** 9000

## Ana Endpoint'ler

### Auth API
```
POST /fapiv1/fikoyt.com.FikoYT.sistem.uye.ol          # Kayıt
POST /fapiv1/fikoyt.com.FikoYT.sistem.giris.yap       # Giriş
POST /fapiv1/fikoyt.com.FikoYT.sistem.cikis.yap       # Çıkış
POST /fapiv1/fikoyt.com.FikoYT.sistem.aktif-kullanici.bilgi  # User info
```

### Generic CRUD API
```
POST /fapiv1/fikoyt.com.FikoYT.sistem.DB.:db.aggregate  # Aggregation
POST /fapiv1/fikoyt.com.FikoYT.sistem.DB.:db.ekle       # Insert/Upsert
POST /fapiv1/fikoyt.com.FikoYT.sistem.DB.:db.sil        # Delete
POST /fapiv1/fikoyt.com.FikoYT.sistem.DB.:db.guncelle   # Update
```

**Kullanım:**
```typescript
POST /fapiv1/fikoyt.com.FikoYT.sistem.DB.goUyeler.ekle
{
  "isim": "Ahmet",
  "email": "ahmet@example.com"
}
```

### File Management
```
GET  /fapiv1/fikoyt.com.FikoYT.sistem.dosyalar.:id.resim       # Image + transformations
GET  /fapiv1/fikoyt.com.FikoYT.sistem.dosyalar.:id.dosya       # Download (byte-range)
POST /fapiv1/fikoyt.com.FikoYT.sistem.dosyalar.:id.dosya.sil   # Delete
```

**Image Transformations:**
```
?boyut=800x600&grayscale=true&quality=85
```

### FreeCAD API
```
POST /uyar/api/freecad/analyze              # STEP analizi
GET  /uyar/api/freecad/materials            # Malzeme listesi
POST /uyar/api-raw/freecad/render           # STEP → GIF
POST /uyar/api-raw/freecad/convert-to-gltf  # STEP → glTF
```

## Custom Context System

```go
type FikoYTCtx struct {
    Istek            *FikoYTIstek
    Cevap            *FikoYTCevap
    Sezon            *session.Session
    Koleksiyon       func(string) *mongo.Collection
    EkleYadaGuncelle func(...) ([]*mongo.UpdateResult, error)
    IoClient         func() *socket.RemoteSocket
    AktifKullanici   *FikoYTKullanici
}

// Kullanım
FikoYT := c.Locals("FikoYTCtx").(*FikoYTCtx.FikoYTCtx)
```

## Response Format

```json
{
  "durum": {
    "kodu": 200,
    "tamamlandi": true,
    "hata": false,
    "mesaj": "İşlem başarılı",
    "hatalar": []
  },
  "sonuc": { ... }
}
```

## MongoDB Collections

- `goUyeler` - Kullanıcılar
- `goSessions` - Session storage
- `go_files.files` - GridFS metadata
- `goSoketler` - Socket connections
- `goCihazlar` - Device registry
- `goFirmalar` - Firmalar

## Socket.io Events

**Server → Client:**
```
FikoYT.sistem.cihaz.bağlandı.toplamlar  # Device counts
```

**Client → Server:**
```
FikoYT.sistem.io.cihaz.baglandi  # Device info
```

## Authentication

**Password Hashing:**
- HMAC-SHA256
- Secret: `FikoYT+1299`

**Session:**
```go
FikoYT.Sezon.Set("aktifKullaniciID", userID)
FikoYT.Sezon.Save()
```

## Middleware Chain

1. Recovery (panic recovery)
2. JSON Parser (custom)
3. File Handler (multipart)
4. Response Wrapper
5. Request ID
6. MongoDB Session
7. Context Builder
8. CORS

## Best Practices

✅ Custom context system
✅ Generic CRUD API
✅ GridFS file storage
✅ Socket.io tracking
⚠️ Error logging sistemi eklenmeli
⚠️ Rate limiting gerekli
