canting 1.0.2

The official Artisan-like CLI toolchain for Pakem Framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
use std::fs;
use std::path::Path;

pub fn create_full_skeleton(base: &Path, name: &str, db_type: &str) {
    // 1. Create Folder Structure
    let folders = [
        "src",
        "src/app",
        "src/app/controllers",
        "src/app/models",
        "src/app/services",
        "src/app/requests",
        "src/core",
        "src/routes",
        "resources",
        "resources/views",
        "resources/views/auth",
        "resources/views/layouts",
        "resources/js",
        "resources/css",
        "database",
        "database/migrations",
        "database/seeders",
        "database/factories",
        "storage",
        "storage/app/public",
        "storage/cache",
        "public",
        "tests",
        "plugins",
        "app/scripts",
        ".github",
    ];
    for folder in folders {
        fs::create_dir_all(base.join(folder)).ok();
    }

    let db_normalized = match db_type {
        "postgres" | "postgresql" | "pg" => "postgres",
        "mysql" | "mariadb" => "mysql",
        "all" | "full" => "all",
        _ => "sqlite",
    };

    let (sqlx_features, default_features, env_db_block) = match db_normalized {
        "postgres" => (
            r#"features = ["runtime-tokio", "macros", "any", "chrono", "postgres"]"#,
            r#"default = ["postgres"]
sqlite = []
postgres = []
mysql = []"#,
            format!(
                r#"# Database Configuration (PostgreSQL)
DB_CONNECTION=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE={}_db
DB_USERNAME=postgres
DB_PASSWORD=secret

# Atau gunakan URL eksplisit:
DATABASE_URL=postgres://postgres:secret@127.0.0.1:5432/{}_db"#,
                name, name
            ),
        ),
        "mysql" => (
            r#"features = ["runtime-tokio", "macros", "any", "chrono", "mysql"]"#,
            r#"default = ["mysql"]
sqlite = []
postgres = []
mysql = []"#,
            format!(
                r#"# Database Configuration (MySQL / MariaDB)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE={}_db
DB_USERNAME=root
DB_PASSWORD=

# Atau gunakan URL eksplisit:
DATABASE_URL=mysql://root:@127.0.0.1:3306/{}_db"#,
                name, name
            ),
        ),
        "mssql" => (
            r#"features = ["runtime-tokio", "macros", "any", "chrono", "sqlite"]"#,
            r#"default = ["mssql"]
sqlite = []
postgres = []
mysql = []
mssql = ["pakem/mssql"]"#,
            format!(
                r#"# Database Configuration (Microsoft SQL Server / MSSQL)
DB_CONNECTION=mssql
DB_HOST=127.0.0.1
DB_PORT=1433
DB_DATABASE={}_db
DB_USERNAME=sa
DB_PASSWORD=YourPassword123

# Atau gunakan format connection string MSSQL:
DATABASE_URL="jdbc:sqlserver://127.0.0.1:1433;user=sa;password=YourPassword123;database={}_db;trustServerCertificate=true"
# Format URL: DATABASE_URL="sqlserver://sa:YourPassword123@127.0.0.1:1433?database={}_db&trustServerCertificate=true"
# Format Named Instance (gunakan double backslash \): DATABASE_URL="jdbc:sqlserver://127.0.0.1\\INSTANCE;user=sa;password=YourPassword123;database={}_db;trustServerCertificate=true""#,
                name, name, name, name
            ),
        ),
        "all" => (
            r#"features = ["runtime-tokio", "macros", "any", "chrono", "sqlite", "postgres", "mysql"]"#,
            r#"default = ["sqlite", "postgres", "mysql"]
sqlite = []
postgres = []
mysql = []"#,
            format!(
                r#"# Database Configuration (Multi-Driver: sqlite / postgres / mysql)
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=./database.sqlite
DB_USERNAME=root
DB_PASSWORD=

# Atau gunakan URL eksplisit:
DATABASE_URL=sqlite:./database.sqlite
# DATABASE_URL=postgres://postgres:secret@127.0.0.1:5432/{}_db
# DATABASE_URL=mysql://root:@127.0.0.1:3306/{}_db"#,
                name, name
            ),
        ),
        _ => (
            r#"features = ["runtime-tokio", "macros", "any", "chrono", "sqlite"]"#,
            r#"default = ["sqlite"]
sqlite = []
postgres = []
mysql = []"#,
            r#"# Database Configuration (SQLite - Zero Config)
DB_CONNECTION=sqlite
DB_HOST=127.0.0.1
DB_PORT=
DB_DATABASE=./database.sqlite
DB_USERNAME=
DB_PASSWORD=

# URL eksplisit:
DATABASE_URL=sqlite:./database.sqlite"#.to_string(),
        ),
    };

    // 2. Cargo.toml
    let lib_name = name.replace("-", "_");
    let cargo_toml = format!(
        r#"[workspace]

[package]
name = "{}"
version = "0.1.0"
edition = "2021"
default-run = "{}-server"

[lib]
name = "{}"
path = "src/lib.rs"

[[bin]]
name = "{}-server"
path = "src/main.rs"

[dependencies]
pakem = "1.0"
tokio = {{ version = "1", features = ["full"] }}
axum = {{ version = "0.7", features = ["macros", "multipart"] }}
serde = {{ version = "1", features = ["derive"] }}
serde_json = "1"
dotenv = "0.15"
async-trait = "0.1"
chrono = {{ version = "0.4", features = ["serde"] }}
sqlx = {{ version = "0.8", default-features = false, {} }}
validator = {{ version = "0.18", features = ["derive"] }}

[features]
{}

[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
panic = "abort"
strip = true
"#,
        name, name, lib_name, name, sqlx_features, default_features
    );
    fs::write(base.join("Cargo.toml"), cargo_toml).ok();

    // 3. .env.example & .env
    let env_example = format!(
        r#"# ─── PAKEM FRAMEWORK CONFIGURATION ──────────────────────────────────────────

# Application Settings
APP_NAME=Pakem
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost:8000
APP_KEY=pakem-super-secret-key-change-me-in-production

# Logging
LOG_LEVEL=info
LOG_TO_FILE=true

{}

# Rate Limiting
RATE_LIMIT_MAX=60
RATE_LIMIT_WINDOW=60

# Universal Storage (Filesystem: local | public | s3)
FILESYSTEM_DISK=local
UPLOAD_MAX_SIZE_MB=10

# Redis Multi-Driver Suite (Cache, Queue, Broadcaster)
REDIS_URL="redis://127.0.0.1:6379/0"
CACHE_DRIVER=moka
QUEUE_CONNECTION=database
BROADCAST_DRIVER=log

# Session Configuration
JWT_SECRET=pakem-jwt-secret-key-change-me-in-production

# ──────────────────────────────────────────────────────────────────────────────
"#,
        env_db_block
    );
    fs::write(base.join(".env.example"), &env_example).ok();
    fs::write(base.join(".env"), &env_example).ok();

    if db_normalized == "sqlite" || db_normalized == "all" {
        fs::write(base.join("database.sqlite"), "").ok();
    }

    // 4. src/lib.rs (Enables modular code & integration tests in tests/)
    let lib_rs = r#"pub mod app;
pub mod routes;
"#;
    fs::write(base.join("src/lib.rs"), lib_rs).ok();

    // 5. src/main.rs
    let main_rs = r#"mod app;
mod routes;

use pakem::prelude::*;

//                  PAKEM FRAMEWORK APPLICATION ENTRYPOINT
// High-performance, elegant Rust web backend & API engine.

#[tokio::main]
async fn main() {
    // 1. Load configuration from .env file
    dotenv::dotenv().ok();

    // 2. Initialize the application engine with Web & API routes
    let app = Application::new()
        .with_web(routes::web::router())
        .with_api(routes::api::router());

    println!("⚡ Welcome to Pakem Framework");
    println!("🚀 Server running at http://127.0.0.1:8000");
    println!("📖 API Endpoints ready at http://127.0.0.1:8000/api");

    // 3. Launch HTTP server
    app.serve("127.0.0.1:8000").await;
}
"#;
    fs::write(base.join("src/main.rs"), main_rs).ok();

    // 6. src/app/mod.rs
    fs::write(
        base.join("src/app/mod.rs"),
        r#"pub mod controllers;
pub mod models;
pub mod services;
pub mod requests;

/// Application Prelude Hub — Satu baris import untuk seluruh controller & service:
/// `use crate::app::prelude::*;`
#[allow(unused_imports)]
pub mod prelude {
    pub use pakem::prelude::*;
    pub use crate::app::models::*;
    pub use crate::app::requests::*;
}
"#,
    )
    .ok();

    // 7. src/app/models/mod.rs & requests/mod.rs & services/mod.rs
    fs::write(base.join("src/app/models/mod.rs"), "// Models module\n").ok();
    fs::write(base.join("src/app/requests/mod.rs"), "// Requests module\n").ok();
    fs::write(base.join("src/app/services/mod.rs"), "// Services module\n").ok();

    // 8. src/app/controllers/mod.rs
    fs::write(
        base.join("src/app/controllers/mod.rs"),
        "pub mod welcome_controller;\n",
    )
    .ok();

    // 9. src/app/controllers/welcome_controller.rs (Dual-Mode Response: HTML + Lumen JSON)
    let welcome_ctrl = r#"use pakem::prelude::*;
use serde_json::json;

//                        WELCOME CONTROLLER
// Controller halaman utama aplikasi Pakem.
// Mendukung Dual-Mode Response:
// 1. Browser Request (Accept: text/html) -> Mengembalikan Dashboard HTML modern ala Laravel.
// 2. API / cURL Request (Accept: application/json atau ?format=json) -> Mengembalikan JSON ala Lumen!

pub struct WelcomeController;

impl WelcomeController {
    /// Halaman Utama ("/") - Dual Mode Response
    pub async fn index(req: Request) -> impl IntoResponse {
        // Cek informasi koneksi database aktif
        let db_info = if let Some(pool) = &req.state.db {
            let driver = format!("{:?}", pool.kind);
            let is_ok = sqlx::query("SELECT 1").execute(&pool.pool).await.is_ok();
            (driver, if is_ok { "connected" } else { "disconnected" })
        } else {
            ("SQLite".to_string(), "not connected")
        };

        // 1. Jika request meminta JSON (via Header Accept: application/json atau ?format=json)
        // Mengembalikan spesifikasi framework ala Lumen microframework!
        let wants_json = req.wants_json() 
            || req.header("accept").map(|a| a.contains("json")).unwrap_or(false);

        if wants_json {
            return axum::Json(json!({
                "name": "Pakem Framework",
                "tagline": "Look like Laravel, Run at Rust Speed",
                "version": "1.0.1",
                "rust_edition": "2021",
                "engine": "Axum 0.7 + Tokio Async",
                "environment": "local",
                "database": {
                    "driver": db_info.0,
                    "status": db_info.1
                },
                "documentation": "https://pakem.my.id",
                "endpoints": {
                    "home": "/",
                    "health": "/health",
                    "api_index": "/api",
                    "api_health": "/api/health"
                }
            })).into_response();
        }

        // 2. Jika diakses via Web Browser biasa, render Blade HTML Dashboard
        req.view("welcome")
            .with("title", "Pakem Framework - Look like Laravel, Run at Rust Speed")
            .with("app_name", "Pakem Framework")
            .with("version", "0.3.0")
            .with("rust_edition", "2021")
            .with("db_driver", db_info.0)
            .with("db_status", db_info.1)
            .with("docs_url", "https://github.com/pakem-rs/framework")
            .render(req)
            .await
            .into_response()
    }

    /// Menampilkan Halaman Login ("/login")
    #[allow(dead_code)]
    pub async fn login(req: Request) -> impl IntoResponse {
        req.view("auth.login")
            .with("title", "Login - Pakem")
            .render(req)
            .await
            .into_response()
    }

    /// Menampilkan Halaman Register ("/register")
    #[allow(dead_code)]
    pub async fn register(req: Request) -> impl IntoResponse {
        req.view("auth.register")
            .with("title", "Register - Pakem")
            .render(req)
            .await
            .into_response()
    }
}
"#;
    fs::write(
        base.join("src/app/controllers/welcome_controller.rs"),
        welcome_ctrl,
    )
    .ok();

    // 10. src/routes/mod.rs, web.rs & api.rs
    fs::create_dir_all(base.join("src/routes")).ok();
    fs::write(
        base.join("src/routes/mod.rs"),
        "pub mod api;\npub mod web;\n",
    )
    .ok();

    let web_routes = r#"use pakem::prelude::*;
use crate::app::controllers::welcome_controller::WelcomeController;

//                            WEB ROUTING
// Rute untuk web browser (HTML views, Blade templates, auth UI).

pub fn router() -> Router<AppState> {
    Router::new()
        // Halaman Utama Pakem (Dual Mode: HTML Dashboard di browser / JSON di API)
        .get("/", WelcomeController::index)
        
        // Rute autentikasi
        .get("/login", WelcomeController::login)
        .get("/register", WelcomeController::register)
}
"#;
    fs::write(base.join("src/routes/web.rs"), web_routes).ok();

    let api_routes = r#"use pakem::prelude::*;
use serde_json::json;

//                            API ROUTING
// Rute di sini otomatis diprefix dengan "/api" oleh Application engine.
// Sangat ideal untuk membangun RESTful API, Microservices, dan Webhooks.

pub fn router() -> Router<AppState> {
    Router::new()
        .get("/", api_index)
        .get("/health", api_health)
        .get("/v1", api_v1_index)
}

/// Endpoint: GET /api
async fn api_index(req: Request) -> PakemResult {
    req.ok(json!({
        "framework": "Pakem Framework",
        "tagline": "Look like Laravel, Run at Rust Speed",
        "version": "1.0.1",
        "status": "online",
        "endpoints": {
            "health": "/api/health",
            "v1": "/api/v1"
        }
    }))
}

/// Endpoint: GET /api/health
async fn api_health(req: Request) -> PakemResult {
    let db_status = if let Some(pool) = &req.state.db {
        if sqlx::query("SELECT 1").execute(&pool.pool).await.is_ok() {
            "connected"
        } else {
            "error"
        }
    } else {
        "disabled"
    };

    req.ok(json!({
        "status": "ok",
        "database": db_status,
        "timestamp": chrono::Utc::now().to_rfc3339()
    }))
}

/// Endpoint: GET /api/v1
async fn api_v1_index(req: Request) -> PakemResult {
    req.ok(json!({
        "version": "v1",
        "message": "Pakem API v1 is ready. Register your controllers in src/routes/api.rs!"
    }))
}
"#;
    fs::write(base.join("src/routes/api.rs"), api_routes).ok();

    // 11. resources/views/layouts/app.blade.rs
    let layout = r#"<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title | default("Pakem Framework") }}</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&family=Space+Grotesk:wght@500;600;700;800&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Plus Jakarta Sans', sans-serif;
            background-color: #030712;
        }
        .heading-font {
            font-family: 'Space Grotesk', sans-serif;
        }
        .mono-font {
            font-family: 'JetBrains Mono', monospace;
        }
        .glass-nav {
            background: rgba(10, 15, 30, 0.75);
            backdrop-filter: blur(16px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        }
        .glass-card {
            background: rgba(17, 24, 39, 0.6);
            backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.08);
        }
        .glass-card:hover {
            border-color: rgba(99, 102, 241, 0.4);
            box-shadow: 0 10px 30px -10px rgba(99, 102, 241, 0.2);
        }
    </style>
</head>
<body class="text-slate-100 min-h-screen flex flex-col justify-between selection:bg-indigo-500 selection:text-white">

    <!-- Top Navigation Header -->
    <nav class="glass-nav sticky top-0 z-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex justify-between h-16 items-center">
                <div class="flex items-center space-x-3">
                    <a href="/" class="flex items-center space-x-3">
                        <div class="w-9 h-9 bg-gradient-to-tr from-indigo-500 via-purple-500 to-pink-500 rounded-xl flex items-center justify-center shadow-lg shadow-indigo-500/25">
                            <span class="text-white font-black heading-font text-xl">⚡</span>
                        </div>
                        <div class="flex items-center gap-2">
                            <span class="text-xl font-bold tracking-tight text-white heading-font">Pakem</span>
                            <span class="text-[10px] uppercase font-bold tracking-widest px-2 py-0.5 rounded-full bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">Backend</span>
                        </div>
                    </a>
                </div>
                <div class="flex items-center space-x-6">
                    <a href="/api" target="_blank" class="text-slate-300 hover:text-indigo-400 font-medium text-sm transition flex items-center gap-1.5">
                        <span class="w-2 h-2 rounded-full bg-emerald-400 animate-pulse"></span>
                        API Endpoints
                    </a>
                    <a href="https://github.com/pakem-rs/framework" target="_blank" class="text-slate-300 hover:text-indigo-400 font-medium text-sm transition">Docs</a>
                    <a href="https://github.com/pakem-rs/framework" target="_blank" class="bg-indigo-600 hover:bg-indigo-500 text-white px-4 py-2 rounded-xl text-sm font-semibold shadow-lg shadow-indigo-500/20 transition-all">GitHub Repo</a>
                </div>
            </div>
        </div>
    </nav>

    <!-- Main Content Slot -->
    <main class="flex-grow">
        @yield('content')
    </main>

    <!-- Footer Segment -->
    <footer class="border-t border-slate-900 bg-black/60 py-8">
        <div class="max-w-7xl mx-auto px-4 text-center text-slate-500 text-sm flex flex-col sm:flex-row justify-between items-center gap-4">
            <div class="flex items-center gap-2">
                <span>&copy; 2026 <strong>Pakem Framework</strong>. All rights reserved.</span>
            </div>
            <div class="flex items-center gap-1.5 text-slate-400">
                Engineered with <span class="text-red-500">❤️</span> in <strong>Rust</strong> (Axum 0.7 + Tokio) for ultra-fast APIs.
            </div>
        </div>
    </footer>

</body>
</html>
"#;
    fs::write(base.join("resources/views/layouts/app.blade.rs"), layout).ok();

    // 12. resources/views/welcome.blade.rs (Laravel / Lumen Backend Homepage)
    let welcome = r#"@extends('layouts.app')

@section('content')
<div class="relative overflow-hidden pt-12 pb-24">
    <!-- Ambient Glow Effects -->
    <div class="absolute top-[-10%] left-[-10%] w-[50vw] h-[50vw] bg-indigo-600/15 rounded-full blur-[140px] pointer-events-none"></div>
    <div class="absolute top-[20%] right-[-10%] w-[45vw] h-[45vw] bg-pink-600/10 rounded-full blur-[140px] pointer-events-none"></div>

    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
        <!-- Hero Section -->
        <div class="text-center max-w-4xl mx-auto">
            <div class="inline-flex items-center gap-2 py-1 px-3.5 rounded-full text-xs font-semibold bg-indigo-500/10 text-indigo-300 border border-indigo-500/25 mb-6 uppercase tracking-wider shadow-inner">
                <span class="w-2 h-2 rounded-full bg-emerald-400 animate-ping"></span>
                <span>Pakem v{{ version }} • High-Performance Rust Backend Engine</span>
            </div>
            <h1 class="text-5xl md:text-7xl font-extrabold tracking-tight text-white mb-6 heading-font leading-tight">
                The <span class="bg-clip-text text-transparent bg-gradient-to-r from-indigo-400 via-purple-300 to-pink-400">Elegance</span> of Laravel.<br>
                The <span class="text-white underline decoration-indigo-500 decoration-wavy decoration-2">Raw Speed</span> of Rust.
            </h1>
            <p class="text-lg md:text-xl text-slate-400 max-w-3xl mx-auto mb-10 leading-relaxed">
                Pakem is a developer-first Rust web framework specifically built for modern <strong>Backend APIs</strong>, microservices, and enterprise applications. Enjoy seamless routing, unified database pooling, and rapid scaffolding.
            </p>
            <div class="flex flex-wrap justify-center gap-4">
                <a href="/api" target="_blank" class="bg-gradient-to-r from-indigo-600 to-purple-600 text-white px-7 py-3.5 rounded-xl font-bold hover:shadow-lg hover:shadow-indigo-500/25 transition-all transform hover:-translate-y-0.5 flex items-center gap-2">
                    <span>🚀 Inspect API Spec</span>
                    <span class="text-xs bg-black/30 px-2 py-0.5 rounded-md mono-font">GET /api</span>
                </a>
                <a href="https://github.com/pakem-rs/framework" target="_blank" class="bg-slate-900/80 text-slate-200 border border-slate-800 px-7 py-3.5 rounded-xl font-semibold hover:bg-slate-800 hover:text-white transition-all transform hover:-translate-y-0.5 flex items-center gap-2">
                    <span>📖 Documentation</span>
                </a>
            </div>
        </div>

        <!-- Telemetry Status Grid (Laravel / Lumen Health Badges) -->
        <div class="mt-14 grid grid-cols-2 md:grid-cols-4 gap-4">
            <div class="glass-card rounded-2xl p-5 text-left">
                <div class="text-slate-400 text-xs font-semibold uppercase tracking-wider mb-1">Framework Version</div>
                <div class="text-xl font-bold text-white heading-font flex items-center gap-2">
                    <span>Pakem {{ version }}</span>
                </div>
                <div class="text-xs text-indigo-400 mt-1">Rust {{ rust_edition }} Edition</div>
            </div>

            <div class="glass-card rounded-2xl p-5 text-left">
                <div class="text-slate-400 text-xs font-semibold uppercase tracking-wider mb-1">Runtime Engine</div>
                <div class="text-xl font-bold text-white heading-font">Axum 0.7</div>
                <div class="text-xs text-emerald-400 mt-1">Tokio Multi-Threaded Async</div>
            </div>

            <div class="glass-card rounded-2xl p-5 text-left">
                <div class="text-slate-400 text-xs font-semibold uppercase tracking-wider mb-1">Database Driver</div>
                <div class="text-xl font-bold text-white heading-font flex items-center gap-2">
                    <span>{{ db_driver }}</span>
                    <span class="w-2.5 h-2.5 rounded-full {% if db_status == 'connected' %}bg-emerald-400 shadow-sm shadow-emerald-400/50{% else %}bg-amber-400{% endif %}"></span>
                </div>
                <div class="text-xs {% if db_status == 'connected' %}text-emerald-400{% else %}text-amber-400{% endif %} mt-1 font-medium capitalize">{{ db_status }}</div>
            </div>

            <div class="glass-card rounded-2xl p-5 text-left">
                <div class="text-slate-400 text-xs font-semibold uppercase tracking-wider mb-1">Environment</div>
                <div class="text-xl font-bold text-white heading-font">Local</div>
                <div class="text-xs text-slate-400 mt-1">Debug Mode Active</div>
            </div>
        </div>

        <!-- Dual Mode Lumen API Showcase -->
        <div class="mt-10 bg-slate-950/80 border border-slate-800 rounded-3xl p-6 md:p-8 backdrop-blur-md shadow-2xl text-left">
            <div class="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 border-b border-slate-800/80 pb-5 mb-6">
                <div>
                    <div class="flex items-center gap-2">
                        <span class="px-2.5 py-0.5 rounded-full text-xs font-bold bg-pink-500/20 text-pink-300 border border-pink-500/30">Dual-Mode API</span>
                        <h2 class="text-xl font-bold text-white heading-font">Lumen-Style Headless JSON Response</h2>
                    </div>
                    <p class="text-slate-400 text-sm mt-1">Kirim header <code class="mono-font bg-slate-900 text-indigo-300 px-1.5 py-0.5 rounded">Accept: application/json</code> ke URL root (<code class="mono-font text-indigo-300">/</code>) untuk langsung menerima JSON spec.</p>
                </div>
                <div class="flex items-center gap-2">
                    <a href="/?format=json" target="_blank" class="text-xs font-semibold bg-slate-800 hover:bg-slate-700 text-indigo-300 px-3 py-1.5 rounded-lg border border-slate-700 transition flex items-center gap-1.5">
                        <span>Lihat Raw JSON</span>
                        <span>↗</span>
                    </a>
                </div>
            </div>

            <div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
                <!-- Terminal Command -->
                <div>
                    <div class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-2">1. Coba Request via Terminal / cURL:</div>
                    <div class="bg-black/90 rounded-2xl p-4 border border-slate-800 mono-font text-sm text-slate-300 relative group">
                        <div class="flex items-center justify-between text-xs text-slate-500 pb-2 border-b border-slate-800/60 mb-3">
                            <span>bash terminal</span>
                            <span class="text-emerald-400 font-semibold">GET /</span>
                        </div>
                        <div class="overflow-x-auto text-pink-400 select-all">
                            curl -H "Accept: application/json" http://127.0.0.1:8000/
                        </div>
                    </div>
                </div>

                <!-- JSON Response Preview -->
                <div>
                    <div class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-2">2. JSON Response yang Dihasilkan:</div>
                    <pre class="bg-black/90 rounded-2xl p-4 border border-slate-800 mono-font text-xs text-emerald-400 overflow-x-auto leading-relaxed">
{
  <span class="text-slate-400">"name"</span>: <span class="text-amber-300">"Pakem Framework"</span>,
  <span class="text-slate-400">"version"</span>: <span class="text-amber-300">"{{ version }}"</span>,
  <span class="text-slate-400">"engine"</span>: <span class="text-amber-300">"Axum 0.7 + Tokio Async"</span>,
  <span class="text-slate-400">"database"</span>: {
    <span class="text-slate-400">"driver"</span>: <span class="text-amber-300">"{{ db_driver }}"</span>,
    <span class="text-slate-400">"status"</span>: <span class="text-amber-300">"{{ db_status }}"</span>
  },
  <span class="text-slate-400">"documentation"</span>: <span class="text-amber-300">"https://github.com/pakem-rs/framework"</span>
}</pre>
                </div>
            </div>
        </div>

        <!-- Backend Capabilities Feature Cards -->
        <div class="mt-14 grid grid-cols-1 md:grid-cols-3 gap-6 text-left">
            <div class="glass-card rounded-3xl p-7 transition duration-300">
                <div class="w-12 h-12 bg-indigo-500/10 border border-indigo-500/20 text-indigo-400 rounded-2xl flex items-center justify-center text-2xl mb-5">
                    🛣️
                </div>
                <h3 class="text-xl font-bold text-white heading-font mb-2">Dedicated API Routing</h3>
                <p class="text-slate-400 text-sm leading-relaxed mb-4">
                    Pisahkan rute API dan Web dengan mudah. File <code class="mono-font bg-slate-900 text-indigo-300 px-1 rounded">src/routes/api.rs</code> otomatis diprefix dengan <code class="mono-font text-indigo-300">/api</code> lengkap dengan middleware CORS & Rate Limiter.
                </p>
                <a href="/api/health" target="_blank" class="text-xs font-semibold text-indigo-400 hover:text-indigo-300 flex items-center gap-1">
                    Cek /api/health <span>&rarr;</span>
                </a>
            </div>

            <div class="glass-card rounded-3xl p-7 transition duration-300">
                <div class="w-12 h-12 bg-pink-500/10 border border-pink-500/20 text-pink-400 rounded-2xl flex items-center justify-center text-2xl mb-5">
                    🗄️
                </div>
                <h3 class="text-xl font-bold text-white heading-font mb-2">Unified Multi-DB Pool</h3>
                <p class="text-slate-400 text-sm leading-relaxed mb-4">
                    Gunakan SQLite untuk development lokal cepat tanpa setup, lalu beralih ke <strong>PostgreSQL</strong> atau <strong>MySQL</strong> di production cukup dengan mengubah file <code class="mono-font bg-slate-900 text-indigo-300 px-1 rounded">.env</code>.
                </p>
                <span class="text-xs font-semibold text-pink-400 flex items-center gap-1">
                    PostgreSQL • MySQL • SQLite
                </span>
            </div>

            <div class="glass-card rounded-3xl p-7 transition duration-300">
                <div class="w-12 h-12 bg-purple-500/10 border border-purple-500/20 text-purple-400 rounded-2xl flex items-center justify-center text-2xl mb-5">
                    🪄
                </div>
                <h3 class="text-xl font-bold text-white heading-font mb-2">Active Record Models</h3>
                <p class="text-slate-400 text-sm leading-relaxed mb-4">
                    Tulis model database semudah di Laravel Eloquent dengan makro sakti <code class="mono-font bg-slate-900 text-indigo-300 px-1 rounded">#[derive(PakemModel)]</code>. Otomatis menyediakan <code class="mono-font text-indigo-300">all()</code>, <code class="mono-font text-indigo-300">find(id)</code>, dan CRUD.
                </p>
                <a href="https://github.com/pakem-rs/framework#models" target="_blank" class="text-xs font-semibold text-purple-400 hover:text-purple-300 flex items-center gap-1">
                    Pelajari Makro Model <span>&rarr;</span>
                </a>
            </div>
        </div>

        <!-- Quick Start Guide -->
        <div class="mt-14 bg-slate-900/40 border border-slate-800 rounded-3xl p-8 md:p-10 text-left">
            <h3 class="text-2xl font-bold text-white heading-font mb-6 flex items-center gap-3">
                <span class="w-8 h-8 rounded-xl bg-indigo-600 text-white flex items-center justify-center text-sm font-black">⚡</span>
                <span>Cara Cepat Membuat API Endpoint Baru:</span>
            </h3>

            <div class="space-y-6">
                <div class="flex gap-4">
                    <div class="w-8 h-8 shrink-0 bg-indigo-500/20 text-indigo-300 rounded-full flex items-center justify-center font-bold text-sm border border-indigo-500/30">1</div>
                    <div class="flex-grow">
                        <div class="text-white font-semibold mb-1">Daftarkan rute di <code class="mono-font bg-slate-950 text-indigo-300 px-2 py-0.5 rounded text-sm">src/routes/api.rs</code></div>
                        <pre class="bg-black/80 p-3.5 rounded-xl text-xs mono-font text-slate-300 overflow-x-auto border border-slate-800/80 mt-2">
pub fn router() -> Router&lt;AppState&gt; {
    Router::new()
        .get("/products", get_products)
}</pre>
                    </div>
                </div>

                <div class="flex gap-4">
                    <div class="w-8 h-8 shrink-0 bg-indigo-500/20 text-indigo-300 rounded-full flex items-center justify-center font-bold text-sm border border-indigo-500/30">2</div>
                    <div class="flex-grow">
                        <div class="text-white font-semibold mb-1">Kembalikan respons JSON dengan mudah:</div>
                        <pre class="bg-black/80 p-3.5 rounded-xl text-xs mono-font text-slate-300 overflow-x-auto border border-slate-800/80 mt-2">
async fn get_products() -> impl IntoResponse {
    Json(serde_json::json!({
        "status": "success",
        "data": ["Rust", "Axum", "Pakem"]
    }))
}</pre>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
@endsection
"#;
    fs::write(base.join("resources/views/welcome.blade.rs"), welcome).ok();

    // 13. resources/views/auth/login.blade.rs & register.blade.rs
    let login = r#"@extends('layouts.app')

@section('content')
<div class="min-h-[75vh] flex items-center justify-center px-4 relative">
    <div class="absolute w-[400px] h-[400px] bg-indigo-500/5 rounded-full blur-[100px] pointer-events-none"></div>

    <div class="max-w-md w-full bg-slate-900/60 border border-slate-800/80 rounded-3xl p-10 backdrop-filter backdrop-blur-md shadow-2xl relative z-10">
        <div class="text-center mb-8">
            <h2 class="text-3xl font-extrabold heading-font text-white">Welcome Back</h2>
            <p class="text-slate-400 mt-2 text-sm">Enter your credentials to manage your account</p>
        </div>
        
        <form action="/login" method="POST" class="space-y-6">
            @csrf
            <div>
                <label class="block text-sm font-semibold text-slate-300 mb-2">Email Address</label>
                <input type="email" name="email" class="w-full bg-slate-950/80 border border-slate-800 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition" placeholder="you@example.com" required>
            </div>
            <div>
                <label class="block text-sm font-semibold text-slate-300 mb-2">Password</label>
                <input type="password" name="password" class="w-full bg-slate-950/80 border border-slate-800 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition" placeholder="••••••••" required>
            </div>
            <button type="submit" class="w-full bg-indigo-600 text-white py-3.5 rounded-xl font-bold hover:bg-indigo-500 shadow-lg shadow-indigo-600/20 transition transform active:scale-98">
                Sign In
            </button>
        </form>
        
        <p class="text-center text-sm text-slate-400 mt-8">
            Don't have an account? <a href="/register" class="text-indigo-400 font-bold hover:underline">Register</a>
        </p>
    </div>
</div>
@endsection
"#;
    fs::write(base.join("resources/views/auth/login.blade.rs"), login).ok();

    let register = r#"@extends('layouts.app')

@section('content')
<div class="min-h-[75vh] flex items-center justify-center px-4 relative">
    <div class="absolute w-[400px] h-[400px] bg-pink-500/5 rounded-full blur-[100px] pointer-events-none"></div>

    <div class="max-w-md w-full bg-slate-900/60 border border-slate-800/80 rounded-3xl p-10 backdrop-filter backdrop-blur-md shadow-2xl relative z-10">
        <div class="text-center mb-8">
            <h2 class="text-3xl font-extrabold heading-font text-white">Create Account</h2>
            <p class="text-slate-400 mt-2 text-sm">Get started with the Pakem ecosystem</p>
        </div>
        
        <form action="/register" method="POST" class="space-y-6">
            @csrf
            <div>
                <label class="block text-sm font-semibold text-slate-300 mb-2">Full Name</label>
                <input type="text" name="name" class="w-full bg-slate-950/80 border border-slate-800 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition" placeholder="John Doe" required>
            </div>
            <div>
                <label class="block text-sm font-semibold text-slate-300 mb-2">Email Address</label>
                <input type="email" name="email" class="w-full bg-slate-950/80 border border-slate-800 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition" placeholder="you@example.com" required>
            </div>
            <div>
                <label class="block text-sm font-semibold text-slate-300 mb-2">Password</label>
                <input type="password" name="password" class="w-full bg-slate-950/80 border border-slate-800 rounded-xl px-4 py-3 text-white focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 transition" placeholder="••••••••" required>
            </div>
            <button type="submit" class="w-full bg-indigo-600 text-white py-3.5 rounded-xl font-bold hover:bg-indigo-500 shadow-lg shadow-indigo-600/20 transition transform active:scale-98">
                Create Account
            </button>
        </form>
        
        <p class="text-center text-sm text-slate-400 mt-8">
            Already have an account? <a href="/login" class="text-indigo-400 font-bold hover:underline">Sign In</a>
        </p>
    </div>
</div>
@endsection
"#;
    fs::write(
        base.join("resources/views/auth/register.blade.rs"),
        register,
    )
    .ok();

    // 14. database/migrations/0001_create_users_table.sql
    let migration = r#"-- Users Table Migration
CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    email TEXT NOT NULL UNIQUE,
    password TEXT NOT NULL,
    role TEXT NOT NULL DEFAULT 'member',
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    deleted_at DATETIME
);
"#;
    fs::write(
        base.join("database/migrations/0001_create_users_table.sql"),
        migration,
    )
    .ok();

    // 14a. database/seeders/0001_users_seeder.sql
    let default_seeder = r#"-- Pakem Default Users Seeder (Admin, Editor, Member)
-- Password default: password123 (bcrypt cost 12)
DELETE FROM users WHERE email IN ('admin@pakem.my.id', 'editor@pakem.my.id', 'member@pakem.my.id');

INSERT INTO users (name, email, password, role) VALUES 
('Administrator Pakem', 'admin@pakem.my.id', '$2b$12$9PoqqsF9tgdGa57MX.JIA.ejM3WzhUR.2qslio9xbRzxVWnB9rhSu', 'admin'),
('Editor Konten', 'editor@pakem.my.id', '$2b$12$9PoqqsF9tgdGa57MX.JIA.ejM3WzhUR.2qslio9xbRzxVWnB9rhSu', 'editor'),
('Member Komunitas', 'member@pakem.my.id', '$2b$12$9PoqqsF9tgdGa57MX.JIA.ejM3WzhUR.2qslio9xbRzxVWnB9rhSu', 'member');
"#;
    fs::write(
        base.join("database/seeders/0001_users_seeder.sql"),
        default_seeder,
    )
    .ok();

    // 14b. database/factories/mod.rs & user_factory.rs
    fs::write(
        base.join("database/factories/mod.rs"),
        "pub mod user_factory;\n",
    )
    .ok();

    let user_factory = r#"use pakem::prelude::*;
use crate::app::models::user::User;

// =========================================================================
//  UserFactory (Pakem Model Factory)
// =========================================================================

pub struct UserFactory;

impl UserFactory {
    pub fn new() -> Self {
        Self
    }
}

impl Factory<User> for UserFactory {
    /// Definisikan nilai dummy default untuk model User
    fn definition(&self) -> User {
        User {
            name: Faker::name(),
            email: Faker::unique_email(),
            password: "password".to_string(),
            role: "user".to_string(),
            ..Default::default()
        }
    }
}

impl HasFactory<UserFactory> for User {
    fn factory() -> UserFactory {
        UserFactory::new()
    }
}
"#;
    fs::write(
        base.join("database/factories/user_factory.rs"),
        user_factory,
    )
    .ok();

    // 15. src/app/models/mod.rs & user.rs
    fs::write(base.join("src/app/models/mod.rs"), "pub mod user;\n").ok();

    let user_model = r#"#![allow(dead_code)]
use serde::{Serialize, Deserialize};
use sqlx::FromRow;
use pakem::prelude::*;

//                            USER MODEL
// Di Laravel, ini adalah class Eloquent (`User extends Model`).
// Cukup tambahkan `#[derive(PakemModel)]` untuk mendapatkan fungsi CRUD otomatis:
// `User::find(id)`, `User::all()`, dll.
#[derive(Debug, Serialize, Deserialize, FromRow, Clone, Default, PakemModel)]
#[table("users")]
pub struct User {
    pub id: i64,
    pub name: String,
    pub email: String,
    pub password: String,
    pub role: String,
    pub created_at: Option<String>,
    pub updated_at: Option<String>,
    pub deleted_at: Option<String>,
}

impl User {
    pub fn new() -> Self {
        Self::default()
    }
}
"#;
    fs::write(base.join("src/app/models/user.rs"), user_model).ok();

    // 16. Auto-generate comprehensive README.md
    let readme = format!(
        r#"# ⚡ Welcome to Your Pakem Backend Application: {}

Selamat! Anda telah berhasil menginisialisasi project baru dengan **Pakem Framework** — Web & RESTful API framework modern berbasis Rust (Axum 0.7 & Tokio Async) yang memadukan kecepatan komputasi sistem Rust dengan elegansi dan ergonomi sintaks **Laravel** dan **Lumen**.

---

## 🚀 Menjalankan Server Lokal (Quick Start)

Secara default, project ini menggunakan database **SQLite** (file lokal). Anda dapat langsung menjalankan server tanpa perlu setup database external:

```bash
cargo run
```

Akses di browser atau API client Anda:
- 🌐 **Web Dashboard (Laravel Style)**: [http://127.0.0.1:8000](http://127.0.0.1:8000)
- ⚡ **Lumen-Style Headless JSON Spec**:
  ```bash
  curl -H "Accept: application/json" http://127.0.0.1:8000/
  ```
- 🩺 **Health Check Endpoint**: [http://127.0.0.1:8000/health](http://127.0.0.1:8000/health)
- 🛣️ **REST API Base Path**: [http://127.0.0.1:8000/api](http://127.0.0.1:8000/api)

---

## 🗄️ Beralih ke PostgreSQL atau MySQL

Pakem mendukung multi-driver database secara native. Cukup sesuaikan variabel di `.env`:

### Contoh PostgreSQL:
```env
DB_CONNECTION=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=nama_db_kamu
DB_USERNAME=postgres
DB_PASSWORD=secret
DATABASE_URL=postgres://postgres:secret@127.0.0.1:5432/nama_db_kamu
```

### Jalankan Migrasi Database:
```bash
canting migrate
```

---

## 📁 Struktur Folder Proyek

```text
├── Cargo.toml                  # Konfigurasi dependensi (Axum, Tokio, SQLx, Pakem)
├── .env                        # Variabel environment (Database, App Secret, Port)
├── src/
│   ├── main.rs                 # Application entrypoint & HTTP server bootstrap
│   ├── lib.rs                  # Module exports (app, routes) untuk modular testing
│   ├── routes/
│   │   ├── web.rs              # Route frontend / HTML views
│   │   └── api.rs              # Route RESTful API (prefix /api)
│   └── app/
│       ├── controllers/        # Request handling & responses
│       ├── models/             # Active Record models (#[derive(PakemModel)])
│       └── services/           # Business logic layer
├── resources/views/            # Blade template views (.blade.rs)
├── database/migrations/        # Migrasi skema database SQL
└── tests/                      # Automated integration tests
```

---

## 🦀 Selamat Berkarya dengan Pakem Framework!
Dokumentasi lengkap dan update framework: [github.com/lumina-java/framework](https://github.com/pakem-rs/framework)
"#,
        name
    );
    fs::write(base.join("README.md"), readme).ok();

    // 16. Dockerfile (Production Ready Multi-Stage with BuildKit Cache Mounts)
    let dockerfile = format!(
        r#"# ─── Stage 1: Build Stage ───────────────────────────────────────────────────────────
FROM rust:1.80-slim-bookworm AS builder

RUN apt-get update && apt-get install -y pkg-config libssl-dev build-essential && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY . .

# Build dengan Docker BuildKit Cache Mounts agar kompilasi ulang hanya memakan hitungan detik
RUN --mount=type=cache,target=/usr/local/cargo/registry \
    --mount=type=cache,target=/usr/local/cargo/git \
    --mount=type=cache,target=/app/target \
    cargo build --release && \
    (cp /app/target/release/{name}-server /app/server 2>/dev/null || \
     cp /app/target/release/{name} /app/server 2>/dev/null || \
     find /app/target/release/ -maxdepth 1 -type f -executable ! -name "*.so" ! -name "*.d" -exec cp {{}} /app/server \; )

# ─── Stage 2: Runtime Stage ──────────────────────────────────────────────────────────
FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y ca-certificates libssl3 curl && rm -rf /var/lib/apt/lists/*

WORKDIR /app
COPY --from=builder /app/server ./server
COPY --from=builder /app/resources ./resources
COPY --from=builder /app/public ./public
COPY --from=builder /app/database ./database
COPY --from=builder /app/storage ./storage
COPY --from=builder /app/.env.example ./.env

ENV APP_ENV=production
ENV APP_PORT=8000

EXPOSE 8000
CMD ["./server"]
"#,
        name = name
    );
    fs::write(base.join("Dockerfile"), dockerfile).ok();

    // 17. .dockerignore
    let dockerignore = r#"target/
.git/
.github/
.env
storage/cache/*
storage/logs/*
*.sqlite
*.db
node_modules/
"#;
    fs::write(base.join(".dockerignore"), dockerignore).ok();

    // 18. docker-compose.yml
    let safe_name = name.replace('.', "-").replace('_', "-").to_lowercase();
    let compose = format!(
        r#"version: "3.9"

services:
  {safe_name}:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: {safe_name}-app
    restart: unless-stopped
    ports:
      - "8000:8000"
    volumes:
      - ./.env:/app/.env
      - ./storage:/app/storage
      - ./database:/app/database
      - ./public:/app/public
    environment:
      - APP_ENV=production
      - APP_PORT=8000
    networks:
      - pakem-net

networks:
  pakem-net:
    driver: bridge
"#,
        safe_name = safe_name
    );
    fs::write(base.join("docker-compose.yml"), compose).ok();

    // 19. Universal AI Agent Context Scaffolding (AGENTS.md, .cursorrules, .github/copilot-instructions.md, CLAUDE.md)
    crate::ai_context::scaffold_ai_context(base, name).ok();
}