# Modül Yönetim Sistemi - Implementation Plan

## Overview
Create a dynamic module management system that allows administrators to enable/disable modules and control their visibility on the homepage and navigation.

## System Architecture

```mermaid
flowchart TD
    A[Admin Panel] --> B[ModuleController]
    B --> C[modules Table]
    C --> D[Module Model]
    D --> E[Welcome Page]
    D --> F[Public Navbar]
    D --> G[Footer Links]
    
    subgraph "Module States"
        H[is_active]
        I[display_on_home]
        J[is_maintenance]
    end
    
    C --> H
    C --> I
    C --> J
```

## Database Schema

### modules Table
| Field | Type | Description |
|-------|------|-------------|
| id | bigint | Primary Key |
| name | string(100) | Unique module identifier (blog, forum, etc.) |
| label | string(100) | Display name for admin panel |
| icon | string(50) | Emoji or icon class |
| description | text | Module description |
| route_name | string(100) | Laravel route name |
| url_path | string(200) | Direct URL path |
| is_active | boolean | Module enabled/disabled |
| display_on_home | boolean | Show on homepage feature grid |
| is_maintenance | boolean | Show maintenance mode message |
| sort_order | int | Display order |
| created_at | timestamp | |
| updated_at | timestamp | |

## Default Modules to Seed

| name | label | icon | route_name | url_path |
|------|-------|------|------------|----------|
| blog | Blog Yazıları | 📰 | blog.index | /blog |
| forum | Forum | 💬 | forum.index | /forum |
| library | Kütüphane | 📚 | library.index | /library |
| interview | Mülakat Hazırlığı | 🎯 | interview.index | /interview |
| ai | AI Asistan | 🤖 | ai.index | /ai |
| chat | Canlı Sohbet | 💭 | chat.index | /sohbet |
| calculators | Hesaplamalar | 🧮 | calculators.index | /hesaplamalar |
| leaderboard | Lider Tablosu | 🏆 | interview.leaderboard | /interview/leaderboard |

## Implementation Steps

### Step 1: Create Migration
**File:** `database/migrations/2024_01_01_000021_create_modules_table.php`

- Create modules table with all required fields
- Seed default modules with is_active=true, display_on_home=true

### Step 2: Create Module Model
**File:** `app/Models/Module.php`

- Fillable fields for mass assignment
- Scope: `active()` - where is_active = true
- Scope: `displayOnHome()` - where display_on_home = true AND is_active = true
- Scope: `inMaintenance()` - where is_maintenance = true
- Method: `isAccessible()` - checks if module is active and not in maintenance

### Step 3: Create Admin Controller
**File:** `app/Http/Controllers/Admin/ModuleController.php`

Methods:
- `index()` - List all modules with current states
- `update(Request, Module)` - Update module details
- `toggleActive(Module)` - Toggle is_active status
- `toggleDisplayOnHome(Module)` - Toggle display_on_home status
- `toggleMaintenance(Module)` - Toggle is_maintenance status

### Step 4: Create Admin View
**File:** `resources/views/admin/modules/index.blade.php`

Features:
- Table listing all modules
- Toggle switches for each boolean field
- AJAX-based toggling without page reload
- Visual indicators for maintenance mode
- Sort order editing capability

### Step 5: Update Admin Sidebar
**File:** `resources/views/layouts/admin.blade.php`

Add "Modüller" link under "Sistem Yönetimi" section

### Step 6: Update Welcome Page
**File:** `resources/views/welcome.blade.php`

Changes:
- Replace hardcoded feature grid with dynamic module query
- Only show modules where is_active=true AND display_on_home=true
- Show maintenance badge if is_maintenance=true

### Step 7: Update Public Navbar
**File:** `resources/views/layouts/welcome.blade.php`

Changes:
- Replace hardcoded nav links with dynamic module query
- Only show modules where is_active=true
- Handle maintenance mode with visual indicator

### Step 8: Update Footer
**File:** `resources/views/layouts/welcome.blade.php`

Changes:
- Make footer links dynamic based on active modules

### Step 9: Add Routes
**File:** `routes/web.php`

Add under admin routes group:
```php
Route::prefix('modules')->name('modules.')->group(function () {
    Route::get('/', [ModuleController::class, 'index'])->name('index');
    Route::put('/{module}', [ModuleController::class, 'update'])->name('update');
    Route::post('/{module}/toggle-active', [ModuleController::class, 'toggleActive'])->name('toggle_active');
    Route::post('/{module}/toggle-display', [ModuleController::class, 'toggleDisplayOnHome'])->name('toggle_display');
    Route::post('/{module}/toggle-maintenance', [ModuleController::class, 'toggleMaintenance'])->name('toggle_maintenance');
});
```

### Step 10: Cache Clearing
Run commands:
```bash
php artisan migrate
php artisan config:clear
php artisan cache:clear
php artisan view:clear
php artisan route:clear
```

## File Changes Summary

### New Files
1. `database/migrations/2024_01_01_000021_create_modules_table.php`
2. `app/Models/Module.php`
3. `app/Http/Controllers/Admin/ModuleController.php`
4. `resources/views/admin/modules/index.blade.php`

### Modified Files
1. `routes/web.php` - Add module routes
2. `resources/views/layouts/admin.blade.php` - Add sidebar link
3. `resources/views/welcome.blade.php` - Dynamic module display
4. `resources/views/layouts/welcome.blade.php` - Dynamic navbar and footer

## Admin UI Design

The module management page will include:
- Card-based layout for each module
- Toggle switches with smooth animations
- Color-coded status indicators:
  - Green: Active
  - Gray: Inactive
  - Yellow: Maintenance Mode
- Drag-and-drop for sort order (optional enhancement)
- Quick actions menu

## Public Behavior

When a module is:
- **Inactive**: Hidden from all public areas
- **Active + Display on Home**: Shown in homepage feature grid
- **Active + Maintenance**: Shown but with "Bakım Modu" badge
- **Active + Not Maintenance**: Normal display

## Security Considerations

- All admin routes protected by 'auth' and 'admin' middleware
- CSRF protection on all toggle actions
- Cache invalidation after any module state change
