Configuration - luckydeva03/barbershop_app GitHub Wiki
⚙️ Configuration
Panduan lengkap konfigurasi sistem barbershop management untuk berbagai environment.
📋 Environment Configuration
Development Environment (.env)
APP_NAME="Barbershop Management System"
APP_ENV=local
APP_KEY=base64:your_app_key_here
APP_DEBUG=true
APP_URL=http://localhost:8000
LOG_CHANNEL=stack
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=barbershop_dev
DB_USERNAME=root
DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DISK=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"
MAIL_FROM_NAME="${APP_NAME}"
# Google OAuth
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_REDIRECT_URL=http://localhost:8000/auth/google/callback
# WhatsApp Integration
WHATSAPP_API_TOKEN=your_whatsapp_token
WHATSAPP_PHONE_NUMBER=your_whatsapp_number
# Point System Settings
POINTS_EXPIRY_DAYS=365
MAX_POINTS_PER_CODE=1000
MIN_POINTS_PER_CODE=10
# Code Settings
DEFAULT_CODE_LENGTH=8
CODE_PREFIX="BB"
MAX_CODE_USES=1000
Production Environment (.env)
APP_NAME="Barbershop Management System"
APP_ENV=production
APP_KEY=base64:your_production_app_key_here
APP_DEBUG=false
APP_URL=https://yourdomain.com
LOG_CHANNEL=daily
LOG_DEPRECATIONS_CHANNEL=null
LOG_LEVEL=error
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=barbershop_production
DB_USERNAME=barbershop_user
DB_PASSWORD=strong_production_password
BROADCAST_DRIVER=redis
CACHE_DRIVER=redis
FILESYSTEM_DISK=public
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis
SESSION_LIFETIME=60
SESSION_ENCRYPT=true
SESSION_EXPIRE_ON_CLOSE=true
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=your_redis_password
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=587
MAIL_USERNAME=your_mail_username
MAIL_PASSWORD=your_mail_password
MAIL_ENCRYPTION=tls
[email protected]
MAIL_FROM_NAME="${APP_NAME}"
# Google OAuth Production
GOOGLE_CLIENT_ID=your_production_google_client_id
GOOGLE_CLIENT_SECRET=your_production_google_client_secret
GOOGLE_REDIRECT_URL=https://yourdomain.com/auth/google/callback
# WhatsApp Production
WHATSAPP_API_TOKEN=your_production_whatsapp_token
WHATSAPP_PHONE_NUMBER=your_production_whatsapp_number
🔧 Laravel Configuration Files
config/database.php
)
1. Database Configuration (<?php
return [
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
],
];
config/auth.php
)
2. Authentication Configuration (<?php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'sanctum',
'provider' => 'users',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],
'admins' => [
'provider' => 'admins',
'table' => 'password_reset_tokens',
'expire' => 60,
'throttle' => 60,
],
],
'password_timeout' => 10800,
];
config/services.php
)
3. Services Configuration (<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
'scheme' => 'https',
],
'postmark' => [
'token' => env('POSTMARK_TOKEN'),
],
'ses' => [
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],
'google' => [
'client_id' => env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => env('GOOGLE_REDIRECT_URL'),
],
'whatsapp' => [
'api_token' => env('WHATSAPP_API_TOKEN'),
'phone_number' => env('WHATSAPP_PHONE_NUMBER'),
'base_url' => env('WHATSAPP_BASE_URL', 'https://api.whatsapp.com'),
],
];
config/session.php
)
4. Session Configuration (<?php
return [
'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false),
'encrypt' => env('SESSION_ENCRYPT', false),
'files' => storage_path('framework/sessions'),
'connection' => env('SESSION_CONNECTION'),
'table' => 'sessions',
'store' => env('SESSION_STORE'),
'lottery' => [2, 100],
'cookie' => env('SESSION_COOKIE', Str::slug(env('APP_NAME', 'laravel'), '_').'_session'),
'path' => '/',
'domain' => env('SESSION_DOMAIN'),
'secure' => env('SESSION_SECURE_COOKIE', env('APP_ENV') === 'production'),
'http_only' => true,
'same_site' => 'lax',
'partitioned' => false,
];
🛡️ Security Configuration
app/Http/Kernel.php
)
1. Rate Limiting (<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'admin' => [
'throttle:admin',
],
];
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'admin' => \App\Http\Middleware\AdminAuthenticate::class,
'redeem.throttle' => \App\Http\Middleware\RedeemThrottle::class,
];
protected $routeMiddleware = [
// Custom rate limits
'admin' => [
'throttle:120,1', // 120 requests per minute for admin
],
'redeem' => [
'throttle:3,10', // 3 redeem attempts per 10 minutes
],
'login' => [
'throttle:5,1', // 5 login attempts per minute
],
];
}
config/cors.php
)
2. CORS Configuration (<?php
return [
'paths' => ['api/*', 'sanctum/csrf-cookie'],
'allowed_methods' => ['*'],
'allowed_origins' => ['*'],
'allowed_origins_patterns' => [],
'allowed_headers' => ['*'],
'exposed_headers' => [],
'max_age' => 0,
'supports_credentials' => false,
];
🎨 Frontend Configuration
vite.config.js
)
1. Vite Configuration (import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js'
],
refresh: true,
}),
],
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['bootstrap', 'jquery'],
charts: ['chart.js'],
}
}
}
},
server: {
host: '0.0.0.0',
port: 5173,
hmr: {
host: 'localhost',
},
},
});
tailwind.config.js
)
2. Tailwind Configuration (/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./resources/**/*.blade.php",
"./resources/**/*.js",
"./resources/**/*.vue",
],
theme: {
extend: {
colors: {
primary: {
50: '#eff6ff',
500: '#3b82f6',
600: '#2563eb',
700: '#1d4ed8',
},
secondary: {
50: '#f8fafc',
500: '#64748b',
600: '#475569',
}
},
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
},
},
plugins: [
require('@tailwindcss/forms'),
require('@tailwindcss/typography'),
],
}
postcss.config.js
)
3. PostCSS Configuration (module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
📱 Application Specific Configuration
1. Point System Configuration
Create config file config/points.php
:
<?php
return [
'expiry_days' => env('POINTS_EXPIRY_DAYS', 365),
'max_points_per_code' => env('MAX_POINTS_PER_CODE', 1000),
'min_points_per_code' => env('MIN_POINTS_PER_CODE', 10),
'welcome_bonus' => env('WELCOME_BONUS_POINTS', 50),
'referral_bonus' => env('REFERRAL_BONUS_POINTS', 25),
'redemption_rules' => [
'min_redeem_amount' => 100,
'max_redeem_per_day' => 5,
'cooldown_minutes' => 60,
],
'earning_rules' => [
'review_points' => 10,
'referral_points' => 25,
'birthday_bonus' => 100,
],
];
2. Code System Configuration
Create config file config/codes.php
:
<?php
return [
'default_length' => env('DEFAULT_CODE_LENGTH', 8),
'prefix' => env('CODE_PREFIX', 'BB'),
'max_uses' => env('MAX_CODE_USES', 1000),
'default_expiry_days' => 30,
'generation' => [
'characters' => 'ABCDEFGHJKLMNPQRSTUVWXYZ123456789',
'exclude_similar' => true, // Exclude O, 0, I, 1
'ensure_uniqueness' => true,
],
'validation' => [
'case_sensitive' => false,
'trim_whitespace' => true,
'check_expiry' => true,
'check_usage_limit' => true,
],
];
3. WhatsApp Configuration
Create config file config/whatsapp.php
:
<?php
return [
'api_token' => env('WHATSAPP_API_TOKEN'),
'phone_number' => env('WHATSAPP_PHONE_NUMBER'),
'base_url' => env('WHATSAPP_BASE_URL', 'https://api.whatsapp.com'),
'messages' => [
'booking_template' => 'Halo! Saya ingin booking di {store_name}. Alamat: {store_address}. Terima kasih!',
'welcome_message' => 'Selamat datang di {app_name}! Terima kasih telah bergabung.',
'point_notification' => 'Selamat! Anda mendapat {points} poin. Total poin Anda sekarang: {total_points}',
],
'settings' => [
'enable_notifications' => env('WHATSAPP_NOTIFICATIONS', true),
'enable_booking' => env('WHATSAPP_BOOKING', true),
'rate_limit' => 10, // messages per minute
],
];
🔧 Environment-Specific Settings
Development Settings
// config/app.php
'debug' => env('APP_DEBUG', false),
// Additional development configurations
if (app()->environment('local')) {
// Enable query logging
DB::enableQueryLog();
// Disable email sending
config(['mail.driver' => 'log']);
// Enable detailed error pages
config(['app.debug' => true]);
}
Testing Configuration
Create config/testing.php
:
<?php
return [
'database' => [
'default' => 'sqlite_testing',
],
'cache' => [
'default' => 'array',
],
'session' => [
'driver' => 'array',
],
'queue' => [
'default' => 'sync',
],
'mail' => [
'driver' => 'array',
],
];
Production Optimizations
// config/app.php for production
'debug' => false,
'log_level' => 'error',
// Cache configurations
'cache' => [
'default' => 'redis',
],
'session' => [
'driver' => 'redis',
'encrypt' => true,
],
// Queue configuration
'queue' => [
'default' => 'redis',
],
🚀 Performance Configuration
1. Caching Strategy
// config/cache.php
'stores' => [
'redis' => [
'driver' => 'redis',
'connection' => 'cache',
'lock_connection' => 'default',
],
'file' => [
'driver' => 'file',
'path' => storage_path('framework/cache/data'),
],
'array' => [
'driver' => 'array',
'serialize' => false,
],
],
// Custom cache tags
'tags' => [
'users' => 86400, // 24 hours
'stores' => 3600, // 1 hour
'codes' => 1800, // 30 minutes
'reviews' => 7200, // 2 hours
],
2. Queue Configuration
// config/queue.php
'connections' => [
'redis' => [
'driver' => 'redis',
'connection' => 'default',
'queue' => env('REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
'after_commit' => false,
],
],
// Job batching
'batching' => [
'database' => env('DB_CONNECTION', 'mysql'),
'table' => 'job_batches',
],
📊 Logging Configuration
Custom Log Channels
// config/logging.php
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'slack'],
'ignore_exceptions' => false,
],
'single' => [
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
],
'admin_activities' => [
'driver' => 'daily',
'path' => storage_path('logs/admin.log'),
'level' => 'info',
'days' => 30,
],
'point_transactions' => [
'driver' => 'daily',
'path' => storage_path('logs/points.log'),
'level' => 'info',
'days' => 90,
],
'security' => [
'driver' => 'daily',
'path' => storage_path('logs/security.log'),
'level' => 'warning',
'days' => 180,
],
],
🔧 Configuration Commands
Artisan Commands for Configuration
# Cache all configurations
php artisan config:cache
# Clear configuration cache
php artisan config:clear
# Publish configuration files
php artisan vendor:publish --tag=config
# View current configuration
php artisan config:show database
php artisan config:show cache
# Environment specific commands
php artisan env:encrypt
php artisan env:decrypt
Custom Configuration Commands
Create app/Console/Commands/ConfigOptimize.php
:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ConfigOptimize extends Command
{
protected $signature = 'barbershop:optimize {--env=production}';
protected $description = 'Optimize barbershop configuration for specific environment';
public function handle()
{
$env = $this->option('env');
$this->info("Optimizing for {$env} environment...");
switch ($env) {
case 'production':
$this->call('config:cache');
$this->call('route:cache');
$this->call('view:cache');
$this->call('event:cache');
break;
case 'development':
$this->call('config:clear');
$this->call('route:clear');
$this->call('view:clear');
$this->call('cache:clear');
break;
}
$this->info('Configuration optimization completed!');
}
}
📝 Configuration Validation
Environment Validation
Create app/Console/Commands/ValidateConfig.php
:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ValidateConfig extends Command
{
protected $signature = 'barbershop:validate-config';
protected $description = 'Validate barbershop configuration';
public function handle()
{
$errors = [];
// Validate required environment variables
$required = [
'APP_KEY',
'DB_CONNECTION',
'DB_DATABASE',
'DB_USERNAME',
];
foreach ($required as $key) {
if (empty(env($key))) {
$errors[] = "Missing required environment variable: {$key}";
}
}
// Validate database connection
try {
\DB::connection()->getPdo();
} catch (\Exception $e) {
$errors[] = "Database connection failed: " . $e->getMessage();
}
// Validate cache connection
try {
\Cache::store()->get('test');
} catch (\Exception $e) {
$errors[] = "Cache connection failed: " . $e->getMessage();
}
if (empty($errors)) {
$this->info('✅ All configuration checks passed!');
} else {
$this->error('❌ Configuration validation failed:');
foreach ($errors as $error) {
$this->error(" - {$error}");
}
}
}
}
Next: Project Structure untuk memahami arsitektur aplikasi.