npm package: @larussoft/backend
Description: Larussoft NestJS backend iskelet paketi — hazır admin, CMS ve e-ticaret API endpoint'leri
Latest version: 0.5.0

# @larussoft/backend

NestJS tabanli backend iskelet paketi. Hazir admin paneli, CMS ve e-ticaret API endpoint'leri ile birlikte gelir. Tum is mantigi `@larussoft/core` paketinden saglanir; bu paket yalnizca API katmanini icerir.

## Kurulum

```bash
npm install @larussoft/core @larussoft/backend
```

## Hizli Baslangic

### main.ts

```typescript
import { bootstrap } from '@larussoft/backend'
import { AppModule } from './app.module'

bootstrap(AppModule, {
  port: parseInt(process.env.PORT || '4000'),
  cors: { origin: ['http://localhost:3000'] },
  swagger: { title: 'My API', version: '1.0' },
})
```

### app.module.ts

```typescript
import { Module } from '@nestjs/common'
import { BackendModule } from '@larussoft/backend'
import { AdminModule } from '@larussoft/backend/admin'
import { CmsModule } from '@larussoft/backend/cms'
import { CommerceModule } from '@larussoft/backend/commerce'

@Module({
  imports: [
    BackendModule.forRoot({
      database: {
        host: process.env.DB_HOST || 'localhost',
        port: parseInt(process.env.DB_PORT || '5432'),
        database: process.env.DB_NAME!,
        username: process.env.DB_USERNAME || 'postgres',
        password: process.env.DB_PASSWORD || '',
      },
      auth: {
        jwt: { secret: process.env.JWT_SECRET! },
        loginWith: 'email',
      },
      logger: { appName: 'myapp' },
    }),
    AdminModule.forRoot({ userEntity: User }),
    CmsModule,
    CommerceModule,
  ],
})
export class AppModule {}
```

## Konfiguration

### IBackendConfig

`BackendModule.forRoot()` asagidaki ayarlari kabul eder:

| Alan | Aciklama | Zorunlu |
|---|---|---|
| `database` | PostgreSQL baglanti bilgileri (`host`, `port`, `database`, `username`, `password`) | Evet |
| `database.entities` | Proje ozel entity'ler (orn. `[Salon, Appointment]`) | Hayir |
| `auth` | Kimlik dogrulama ayarlari | Evet |
| `auth.jwt.secret` | JWT imzalama anahtari | Evet |
| `auth.loginWith` | Giris yontemi: `'email'` veya `'phone'` | Evet |
| `logger` | Log ayarlari | Hayir |
| `logger.appName` | Uygulama adi (loglarda kullanilir) | Hayir |
| `storage` | Dosya depolama ayarlari (S3, local vb.) | Hayir |
| `notification` | Bildirim ayarlari (email, SMS) | Hayir |

### Bootstrap Secenekleri

`bootstrap()` fonksiyonunun ikinci parametresi:

| Secenek | Varsayilan | Aciklama |
|---|---|---|
| `port` | `4000` | Sunucu portu |
| `cors` | — | CORS ayarlari (`origin`, `methods` vb.) |
| `swagger` | — | Swagger/OpenAPI ayarlari (`title`, `version`) |
| `helmet` | Aktif | Helmet guvenlik basliklarini yapilandirir |
| `globalPrefix` | — | Tum endpoint'lere ortak prefix ekler (orn. `/api`) |

## Moduller

### AdminModule

Admin paneli endpoint'leri. `AdminModule.forRoot({ userEntity: User })` ile aktif edilir.

```
POST   /auth/login
POST   /auth/register
POST   /auth/refresh
POST   /auth/logout

GET    /admin/users
GET    /admin/users/:id
POST   /admin/users
PATCH  /admin/users/:id
DELETE /admin/users/:id

GET    /admin/roles
POST   /admin/roles
PATCH  /admin/roles/:id

GET    /admin/logs/system
GET    /admin/logs/audit
GET    /admin/logs/export

GET    /admin/files
POST   /admin/files/upload
DELETE /admin/files/:id

GET    /admin/settings
PATCH  /admin/settings

GET    /admin/dashboard
```

### CmsModule

Icerik yonetim sistemi endpoint'leri. `CmsModule` import edilerek aktif edilir.

```
GET|POST|PATCH|DELETE  /admin/pages
GET|POST|PATCH|DELETE  /admin/menus
GET|POST|PATCH|DELETE  /admin/categories
GET|POST|PATCH|DELETE  /admin/tags
GET|POST|DELETE        /admin/media
```

### CommerceModule

E-ticaret endpoint'leri. `CommerceModule` import edilerek aktif edilir.

```
GET|POST|PATCH|DELETE  /admin/products
GET|POST|PATCH|DELETE  /admin/orders
GET|POST|PATCH|DELETE  /admin/customers
GET|POST|PATCH|DELETE  /admin/discounts
```

## Proje Ozel Modul Ekleme

Proje ozel moduller standart NestJS modulleri olarak yazilir ve `AppModule`'e eklenir:

```typescript
// src/salons/salon.module.ts
import { Module } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { Salon } from './salon.entity'
import { SalonsController } from './salons.controller'
import { SalonsService } from './salons.service'

@Module({
  imports: [TypeOrmModule.forFeature([Salon])],
  controllers: [SalonsController],
  providers: [SalonsService],
})
export class SalonModule {}
```

```typescript
// app.module.ts
@Module({
  imports: [
    BackendModule.forRoot({
      database: {
        host: process.env.DB_HOST || 'localhost',
        port: parseInt(process.env.DB_PORT || '5432'),
        database: process.env.DB_NAME!,
        username: process.env.DB_USERNAME || 'postgres',
        password: process.env.DB_PASSWORD || '',
        entities: [Salon], // proje ozel entity'ler buraya eklenir
      },
      auth: {
        jwt: { secret: process.env.JWT_SECRET! },
        loginWith: 'email',
      },
    }),
    AdminModule.forRoot({ userEntity: User }),
    SalonModule,
  ],
})
export class AppModule {}
```

Proje ozel servisler `@larussoft/core` servislerini inject edebilir:

```typescript
import { StorageService } from '@larussoft/core/storage'
import { LoggerService } from '@larussoft/core/logger'
```

## Veritabani

- Uygulama basladiginda tablolar otomatik olusturulur (TypeORM `synchronize`).
- Tum ID alanlari `bigint` tipindedir.
- Metin alanlari icin kisa degerler `varchar`, uzun degerler `text` kullanilir.

### Entity Listesi

#### Setting

| Kolon | Tip |
|---|---|
| id | bigint |
| key | varchar(100) |
| value | text |

#### Page

| Kolon | Tip |
|---|---|
| id | bigint |
| title | varchar(255) |
| slug | varchar(255) |
| content | text |
| status | varchar(20) |

#### Menu

| Kolon | Tip |
|---|---|
| id | bigint |
| name | varchar(100) |
| slug | varchar(100) |
| position | int |

#### MenuItem

| Kolon | Tip |
|---|---|
| id | bigint |
| menuId | bigint |
| title | varchar(255) |
| url | varchar(500) |
| target | varchar(20) |

#### Category

| Kolon | Tip |
|---|---|
| id | bigint |
| name | varchar(100) |
| slug | varchar(100) |
| description | text |
| parentId | bigint |

#### Tag

| Kolon | Tip |
|---|---|
| id | bigint |
| name | varchar(50) |
| slug | varchar(50) |

#### Product

| Kolon | Tip |
|---|---|
| id | bigint |
| name | varchar(255) |
| slug | varchar(255) |
| description | text |
| price | bigint |
| stock | int |

#### Order

| Kolon | Tip |
|---|---|
| id | bigint |
| customerId | bigint |
| status | varchar(20) |
| total | bigint |
| note | text |

#### OrderItem

| Kolon | Tip |
|---|---|
| id | bigint |
| orderId | bigint |
| productId | bigint |
| name | varchar(255) |
| quantity | int |
| unitPrice | bigint |
| total | bigint |

#### Customer

| Kolon | Tip |
|---|---|
| id | bigint |
| name | varchar(100) |
| email | varchar(255) |
| phone | varchar(20) |
| address | text |

#### Discount

| Kolon | Tip |
|---|---|
| id | bigint |
| code | varchar(50) |
| type | varchar(20) |
| value | int |
| minOrderAmount | bigint |
| maxUses | int |

## Teknoloji

| | Secim |
|---|---|
| Framework | NestJS |
| Dil | TypeScript (strict mode) |
| ORM | TypeORM |
| Veritabani | PostgreSQL 16 |
| Validation | class-validator + class-transformer |
| Guvenlik | Helmet, throttler |

## Versiyon Geçmişi

Tüm değişiklikler [CHANGELOG.md](./CHANGELOG.md) dosyasında belgelenmiştir.

## Lisans

MIT