# User Management System - Architecture & Design

## Overview
Complete admin panel user management system for viewing, editing, and managing platform users.

## Database Schema

### Users Table (existing)
| Column | Type | Description |
|--------|------|-------------|
| id | bigint | Primary key |
| name | string | Full name |
| email | string | Unique email |
| email_verified_at | timestamp | Verification timestamp |
| password | string | Hashed password |
| role | string | admin, moderator, editor, user |
| points | bigint | Gamification points |
| bio | text | User biography |
| avatar | string | Avatar image path |
| phone | string | Phone number |
| status | enum | active, inactive, banned, suspended |
| last_login_at | timestamp | Last login time |
| remember_token | string | Remember me token |
| created_at | timestamp | Registration date |
| updated_at | timestamp | Last update |

## Routes Structure

```php
Route::prefix('users')->name('users.')->group(function () {
    Route::get('/', [UserController::class, 'index'])->name('index');
    Route::get('/{user}', [UserController::class, 'show'])->name('show');
    Route::get('/{user}/edit', [UserController::class, 'edit'])->name('edit');
    Route::put('/{user}', [UserController::class, 'update'])->name('update');
    Route::delete('/{user}', [UserController::class, 'destroy'])->name('destroy');
    
    // Actions
    Route::post('/{user}/ban', [UserController::class, 'ban'])->name('ban');
    Route::post('/{user}/unban', [UserController::class, 'unban'])->name('unban');
    Route::post('/{user}/role', [UserController::class, 'changeRole'])->name('change_role');
    Route::post('/bulk', [UserController::class, 'bulkAction'])->name('bulk');
});
```

## Controller Methods

### UserController
| Method | Purpose | Returns |
|--------|---------|---------|
| index | List users with filters/search | View with paginated users |
| show | Display user profile | View with user details + stats |
| edit | Show edit form | View with user data |
| update | Update user record | Redirect to index |
| destroy | Delete user | Redirect to index |
| ban | Ban user | JSON response |
| unban | Unban user | JSON response |
| changeRole | Change user role | JSON response |
| bulkAction | Bulk operations | JSON response |

## View Structure

### 1. index.blade.php
**Layout:** Full-width table with sidebar filters

**Features:**
- Search by name/email
- Filter by role (admin/moderator/editor/user)
- Filter by status (active/inactive/banned/suspended)
- Sort by: name, email, points, last_login, created_at
- Pagination (20 per page)
- Bulk actions: ban, unban, change role, delete

**Table Columns:**
- Avatar (32x32)
- Name + Email
- Role badge (color-coded)
- Status badge (color-coded)
- Points
- Last login
- Registration date
- Actions (edit, delete, ban/unban)

**Role Badge Colors:**
- admin: red (#ef4444)
- moderator: orange (#f59e0b)
- editor: blue (#3b82f6)
- user: gray (#6b7280)

**Status Badge Colors:**
- active: green (#10b981)
- inactive: gray (#9ca3af)
- banned: red (#dc2626)
- suspended: orange (#ea580c)

### 2. show.blade.php
**Layout:** Profile header + stats grid + activity tabs

**Sections:**
- Profile header: avatar, name, email, role, status
- Stats grid: points, posts count, comments count, login count
- Activity tabs: Overview, Posts, Comments, Login History
- Quick actions: Edit, Ban/Unban, Change Role

### 3. edit.blade.php
**Layout:** Two-column form (main info + sidebar actions)

**Form Fields:**
- Name (required)
- Email (required, unique)
- Role (select: admin/moderator/editor/user)
- Status (select: active/inactive/banned/suspended)
- Points (number)
- Bio (textarea)
- Phone (text)
- Avatar upload (file input with preview)

**Password Reset Section:**
- Toggle: "Reset password"
- New password input
- Confirm password input

## Admin Layout Integration

Add to sidebar navigation (after Mülakat Yönetimi, before Ayarlar):

```html
<a href="{{ route('admin.users.index') }}" class="nav-item">
    <svg fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" 
              d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"/>
    </svg>
    <span>Kullanıcı Yönetimi</span>
</a>
```

## Security Considerations

1. Only admins can access user management
2. Cannot delete own account
3. Cannot change own role to lower privilege
4. Password reset requires confirmation
5. Bulk actions require confirmation
6. Soft delete consideration (add deleted_at if needed)

## Implementation Order

1. Routes in web.php
2. Expand UserController
3. Create users views folder
4. Build index.blade.php
5. Build show.blade.php
6. Build edit.blade.php
7. Add nav item to layout
8. Test all functionality
