arcature 0.1.0

Arcature: an opinionated full-stack Rust web framework. One package, batteries included.
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
//! The template file catalog.
//!
//! Every template file is embedded with `include_str!` and tagged with the
//! path it lands on inside the generated project. Embedding rather than
//! reading from disk is what makes `arc new` work from an installed binary
//! with no copy of the framework source anywhere on the machine.
//!
//! The tree under `files/` is split three ways:
//!
//! - `files/shared/` -- everything independent of the two choices.
//! - `files/{react,vue,svelte}/` -- the frontend, one directory per stack.
//! - `files/db/{postgres,sqlite,mysql}/` -- the development services.
//!
//! The three lists are concatenated, so a stack directory and the shared
//! directory must never claim the same output path.

/// The frontend framework a generated application is scaffolded with.
///
/// This mirrors the CLI's `--stack` flag. It is declared here rather than
/// reused from `crate::cli` because the `templates` feature is usable without
/// `cli` -- a build script or a test harness can generate a project without
/// pulling in an argument parser.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum Stack {
    /// React 19 with `@inertiajs/react`.
    #[default]
    React,
    /// Vue 3 with `@inertiajs/vue3`.
    Vue,
    /// Svelte 5 with `@inertiajs/svelte`.
    Svelte,
}

impl Stack {
    /// Every stack, in the order the CLI lists them.
    pub const ALL: [Self; 3] = [Self::React, Self::Vue, Self::Svelte];

    /// The lowercase name used on the command line and for `__STACK__`.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::React => "react",
            Self::Vue => "vue",
            Self::Svelte => "svelte",
        }
    }

    /// The Vite entry module, relative to the project root.
    ///
    /// Only React needs a `.tsx` entry; Vue and Svelte keep their templates
    /// in single-file components and bootstrap from plain TypeScript.
    #[must_use]
    pub const fn entry(self) -> &'static str {
        match self {
            Self::React => "resources/js/app.tsx",
            Self::Vue | Self::Svelte => "resources/js/app.ts",
        }
    }
}

/// The database driver a generated application is scaffolded against.
///
/// Declared here for the same reason as [`Stack`]: `templates` must not
/// depend on `cli`.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum Database {
    /// PostgreSQL 17.
    #[default]
    Postgres,
    /// SQLite, as a file under `storage/`.
    Sqlite,
    /// MySQL 8.4.
    Mysql,
}

impl Database {
    /// Every driver, in the order the CLI lists them.
    pub const ALL: [Self; 3] = [Self::Postgres, Self::Sqlite, Self::Mysql];

    /// The lowercase name used on the command line.
    #[must_use]
    pub const fn as_str(self) -> &'static str {
        match self {
            Self::Postgres => "postgres",
            Self::Sqlite => "sqlite",
            Self::Mysql => "mysql",
        }
    }

    /// The Arcature cargo feature this driver needs, substituted for
    /// `__DB_DRIVER__` in the generated `Cargo.toml`.
    #[must_use]
    pub const fn feature(self) -> &'static str {
        match self {
            Self::Postgres => "db-postgres",
            Self::Sqlite => "db-sqlite",
            Self::Mysql => "db-mysql",
        }
    }

    /// The `DATABASE_URL` written into the generated `.env`.
    ///
    /// Still contains `__RUST_NAME__`; the renderer expands this token before
    /// the project name so the default database is named after the crate.
    #[must_use]
    pub const fn default_url(self) -> &'static str {
        match self {
            Self::Postgres => "postgres://postgres:postgres@127.0.0.1:5432/__RUST_NAME__",
            Self::Sqlite => "sqlite://storage/__RUST_NAME__.sqlite?mode=rwc",
            Self::Mysql => "mysql://__RUST_NAME__:secret@127.0.0.1:3306/__RUST_NAME__",
        }
    }
}

/// A template file: the path it lands on inside the generated project, and
/// the embedded content to render into it.
pub struct TemplateFile {
    /// Destination path, relative to the project root, `/`-separated.
    pub path: &'static str,
    /// The unrendered file content.
    pub content: &'static str,
}

/// Every file a `stack` + `database` project is made of, shared files first.
#[must_use]
pub fn files(stack: Stack, database: Database) -> Vec<TemplateFile> {
    let mut all = shared();
    all.extend(match stack {
        Stack::React => react(),
        Stack::Vue => vue(),
        Stack::Svelte => svelte(),
    });
    all.extend(match database {
        Database::Postgres => postgres(),
        Database::Sqlite => sqlite(),
        Database::Mysql => mysql(),
    });
    all
}

/// Files every generated application gets, whatever the stack or driver.
fn shared() -> Vec<TemplateFile> {
    vec![
        TemplateFile {
            path: ".cargo/config.toml",
            content: include_str!("files/shared/.cargo/config.toml"),
        },
        TemplateFile {
            path: ".dockerignore",
            content: include_str!("files/shared/.dockerignore"),
        },
        TemplateFile {
            path: ".env",
            content: include_str!("files/shared/.env"),
        },
        TemplateFile {
            path: ".env.example",
            content: include_str!("files/shared/.env.example"),
        },
        TemplateFile {
            path: ".gitignore",
            content: include_str!("files/shared/.gitignore"),
        },
        // The source file is `Cargo.toml.in`, not `Cargo.toml`, and the
        // suffix is load-bearing. `cargo package` skips any subdirectory
        // holding a file named `Cargo.toml` -- it reads one as a nested
        // package -- which silently dropped all 38 files under `shared/`
        // from the published crate and left these `include_str!` calls
        // pointing at nothing. Renaming the file is the whole fix; an
        // explicit `include = [...]` in the root manifest does not override
        // the rule. Only the emitted name below is `Cargo.toml`.
        TemplateFile {
            path: "Cargo.toml",
            content: include_str!("files/shared/Cargo.toml.in"),
        },
        TemplateFile {
            path: "Dockerfile",
            content: include_str!("files/shared/Dockerfile"),
        },
        TemplateFile {
            path: "app/controllers/home_controller.rs",
            content: include_str!("files/shared/app/controllers/home_controller.rs"),
        },
        TemplateFile {
            path: "app/controllers/mod.rs",
            content: include_str!("files/shared/app/controllers/mod.rs"),
        },
        TemplateFile {
            path: "app/mod.rs",
            content: include_str!("files/shared/app/mod.rs"),
        },
        TemplateFile {
            path: "app/models/mod.rs",
            content: include_str!("files/shared/app/models/mod.rs"),
        },
        TemplateFile {
            path: "app/pages/errors.rs",
            content: include_str!("files/shared/app/pages/errors.rs"),
        },
        TemplateFile {
            path: "app/pages/home.rs",
            content: include_str!("files/shared/app/pages/home.rs"),
        },
        TemplateFile {
            path: "app/pages/mod.rs",
            content: include_str!("files/shared/app/pages/mod.rs"),
        },
        TemplateFile {
            path: "app/policies/mod.rs",
            content: include_str!("files/shared/app/policies/mod.rs"),
        },
        TemplateFile {
            path: "app/requests/mod.rs",
            content: include_str!("files/shared/app/requests/mod.rs"),
        },
        TemplateFile {
            path: "app/resources/mod.rs",
            content: include_str!("files/shared/app/resources/mod.rs"),
        },
        TemplateFile {
            path: "app/services/mod.rs",
            content: include_str!("files/shared/app/services/mod.rs"),
        },
        TemplateFile {
            path: "bootstrap/app.rs",
            content: include_str!("files/shared/bootstrap/app.rs"),
        },
        TemplateFile {
            path: "bootstrap/error_pages.rs",
            content: include_str!("files/shared/bootstrap/error_pages.rs"),
        },
        TemplateFile {
            path: "bootstrap/mod.rs",
            content: include_str!("files/shared/bootstrap/mod.rs"),
        },
        TemplateFile {
            path: "bootstrap/state.rs",
            content: include_str!("files/shared/bootstrap/state.rs"),
        },
        TemplateFile {
            path: "config/mod.rs",
            content: include_str!("files/shared/config/mod.rs"),
        },
        TemplateFile {
            path: "database/migrations/mod.rs",
            content: include_str!("files/shared/database/migrations/mod.rs"),
        },
        TemplateFile {
            path: "database/mod.rs",
            content: include_str!("files/shared/database/mod.rs"),
        },
        TemplateFile {
            path: "database/seeders/mod.rs",
            content: include_str!("files/shared/database/seeders/mod.rs"),
        },
        TemplateFile {
            path: "justfile",
            content: include_str!("files/shared/justfile"),
        },
        TemplateFile {
            path: "public/.gitkeep",
            content: include_str!("files/shared/public/.gitkeep"),
        },
        TemplateFile {
            path: "public/robots.txt",
            content: include_str!("files/shared/public/robots.txt"),
        },
        TemplateFile {
            path: "resources/css/app.css",
            content: include_str!("files/shared/resources/css/app.css"),
        },
        TemplateFile {
            path: "routes/mod.rs",
            content: include_str!("files/shared/routes/mod.rs"),
        },
        TemplateFile {
            path: "src/bin/uag.rs",
            content: include_str!("files/shared/src/bin/uag.rs"),
        },
        TemplateFile {
            path: "src/lib.rs",
            content: include_str!("files/shared/src/lib.rs"),
        },
        TemplateFile {
            path: "src/main.rs",
            content: include_str!("files/shared/src/main.rs"),
        },
        TemplateFile {
            path: "storage/framework/.gitkeep",
            content: include_str!("files/shared/storage/framework/.gitkeep"),
        },
        TemplateFile {
            path: "storage/logs/.gitkeep",
            content: include_str!("files/shared/storage/logs/.gitkeep"),
        },
        TemplateFile {
            path: "storage/uploads/.gitkeep",
            content: include_str!("files/shared/storage/uploads/.gitkeep"),
        },
        TemplateFile {
            path: "tests/smoke.rs",
            content: include_str!("files/shared/tests/smoke.rs"),
        },
    ]
}

/// The React frontend: entry module, config, pages, layout.
fn react() -> Vec<TemplateFile> {
    vec![
        TemplateFile {
            path: "package.json",
            content: include_str!("files/react/package.json"),
        },
        TemplateFile {
            path: "resources/js/app.tsx",
            content: include_str!("files/react/resources/js/app.tsx"),
        },
        TemplateFile {
            path: "resources/js/components/.gitkeep",
            content: include_str!("files/react/resources/js/components/.gitkeep"),
        },
        TemplateFile {
            path: "resources/js/layouts/default.tsx",
            content: include_str!("files/react/resources/js/layouts/default.tsx"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/404.tsx",
            content: include_str!("files/react/resources/js/pages/errors/404.tsx"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/419.tsx",
            content: include_str!("files/react/resources/js/pages/errors/419.tsx"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/500.tsx",
            content: include_str!("files/react/resources/js/pages/errors/500.tsx"),
        },
        TemplateFile {
            path: "resources/js/pages/home.tsx",
            content: include_str!("files/react/resources/js/pages/home.tsx"),
        },
        TemplateFile {
            path: "resources/js/types.ts",
            content: include_str!("files/react/resources/js/types.ts"),
        },
        TemplateFile {
            path: "tsconfig.json",
            content: include_str!("files/react/tsconfig.json"),
        },
        TemplateFile {
            path: "vite.config.ts",
            content: include_str!("files/react/vite.config.ts"),
        },
    ]
}

/// The Vue frontend: entry module, config, pages, layout.
fn vue() -> Vec<TemplateFile> {
    vec![
        TemplateFile {
            path: "package.json",
            content: include_str!("files/vue/package.json"),
        },
        TemplateFile {
            path: "resources/js/app.ts",
            content: include_str!("files/vue/resources/js/app.ts"),
        },
        TemplateFile {
            path: "resources/js/components/.gitkeep",
            content: include_str!("files/vue/resources/js/components/.gitkeep"),
        },
        TemplateFile {
            path: "resources/js/layouts/Default.vue",
            content: include_str!("files/vue/resources/js/layouts/Default.vue"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/404.vue",
            content: include_str!("files/vue/resources/js/pages/errors/404.vue"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/419.vue",
            content: include_str!("files/vue/resources/js/pages/errors/419.vue"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/500.vue",
            content: include_str!("files/vue/resources/js/pages/errors/500.vue"),
        },
        TemplateFile {
            path: "resources/js/pages/home.vue",
            content: include_str!("files/vue/resources/js/pages/home.vue"),
        },
        TemplateFile {
            path: "resources/js/types.ts",
            content: include_str!("files/vue/resources/js/types.ts"),
        },
        TemplateFile {
            path: "tsconfig.json",
            content: include_str!("files/vue/tsconfig.json"),
        },
        TemplateFile {
            path: "vite.config.ts",
            content: include_str!("files/vue/vite.config.ts"),
        },
    ]
}

/// The Svelte frontend: entry module, config, pages, layout.
fn svelte() -> Vec<TemplateFile> {
    vec![
        TemplateFile {
            path: "package.json",
            content: include_str!("files/svelte/package.json"),
        },
        TemplateFile {
            path: "resources/js/app.ts",
            content: include_str!("files/svelte/resources/js/app.ts"),
        },
        TemplateFile {
            path: "resources/js/components/.gitkeep",
            content: include_str!("files/svelte/resources/js/components/.gitkeep"),
        },
        TemplateFile {
            path: "resources/js/layouts/Default.svelte",
            content: include_str!("files/svelte/resources/js/layouts/Default.svelte"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/404.svelte",
            content: include_str!("files/svelte/resources/js/pages/errors/404.svelte"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/419.svelte",
            content: include_str!("files/svelte/resources/js/pages/errors/419.svelte"),
        },
        TemplateFile {
            path: "resources/js/pages/errors/500.svelte",
            content: include_str!("files/svelte/resources/js/pages/errors/500.svelte"),
        },
        TemplateFile {
            path: "resources/js/pages/home.svelte",
            content: include_str!("files/svelte/resources/js/pages/home.svelte"),
        },
        TemplateFile {
            path: "resources/js/types.ts",
            content: include_str!("files/svelte/resources/js/types.ts"),
        },
        TemplateFile {
            path: "svelte.config.js",
            content: include_str!("files/svelte/svelte.config.js"),
        },
        TemplateFile {
            path: "tsconfig.json",
            content: include_str!("files/svelte/tsconfig.json"),
        },
        TemplateFile {
            path: "vite.config.ts",
            content: include_str!("files/svelte/vite.config.ts"),
        },
    ]
}

/// Development services for the postgres driver.
fn postgres() -> Vec<TemplateFile> {
    vec![TemplateFile {
        path: "docker-compose.yml",
        content: include_str!("files/db/postgres/docker-compose.yml"),
    }]
}

/// Development services for the sqlite driver.
fn sqlite() -> Vec<TemplateFile> {
    vec![TemplateFile {
        path: "docker-compose.yml",
        content: include_str!("files/db/sqlite/docker-compose.yml"),
    }]
}

/// Development services for the mysql driver.
fn mysql() -> Vec<TemplateFile> {
    vec![TemplateFile {
        path: "docker-compose.yml",
        content: include_str!("files/db/mysql/docker-compose.yml"),
    }]
}