allframe_forge/
templates.rs1pub fn cargo_toml(project_name: &str) -> String {
28 format!(
32 r#"[package]
33name = "{}"
34version = "0.1.0"
35edition = "2021"
36
37[dependencies]
38tokio = {{ version = "1", features = ["full"] }}
39serde = {{ version = "1", features = ["derive"] }}
40anyhow = "1.0"
41async-trait = "0.1"
42
43[[bin]]
44name = "{}"
45path = "src/main.rs"
46"#,
47 project_name, project_name
48 )
49}
50
51pub fn main_rs() -> &'static str {
61 r#"//! AllFrame Application
62//!
63//! This is an AllFrame application following Clean Architecture principles.
64
65mod domain;
66mod application;
67mod infrastructure;
68mod presentation;
69
70#[tokio::main]
71async fn main() {
72 println!("AllFrame - One frame. Infinite transformations.");
73 println!("Your application is ready!");
74}
75
76#[cfg(test)]
77mod tests {
78 use super::*;
79
80 #[test]
81 fn test_application_compiles() {
82 // This test verifies the application structure compiles
83 assert!(true);
84 }
85}
86"#
87}
88
89pub fn domain_mod() -> &'static str {
91 r#"//! Domain Layer
92//!
93//! This layer contains the core business logic and has NO external dependencies.
94//!
95//! Structure:
96//! - entities/: Business entities with behavior
97//! - repositories/: Repository trait definitions (interfaces)
98//! - services/: Domain services for complex business logic
99//! - value_objects/: Immutable value types
100
101pub mod entities;
102pub mod repositories;
103
104// Re-export commonly used types
105pub use entities::*;
106pub use repositories::*;
107"#
108}
109
110pub fn domain_entities() -> &'static str {
112 r#"//! Domain Entities
113//!
114//! Business entities with behavior live here.
115
116// Example entity (remove and add your own)
117pub struct ExampleEntity {
118 id: String,
119 name: String,
120}
121
122impl ExampleEntity {
123 pub fn new(id: String, name: String) -> Self {
124 Self { id, name }
125 }
126
127 pub fn id(&self) -> &str {
128 &self.id
129 }
130
131 pub fn name(&self) -> &str {
132 &self.name
133 }
134}
135"#
136}
137
138pub fn domain_repositories() -> &'static str {
140 r#"//! Repository Traits
141//!
142//! Repository interfaces (traits) are defined here.
143//! Implementations live in the infrastructure layer.
144
145// Example repository trait (remove and add your own)
146#[async_trait::async_trait]
147pub trait ExampleRepository: Send + Sync {
148 async fn find_by_id(&self, id: &str) -> anyhow::Result<Option<String>>;
149 async fn save(&self, id: &str, data: String) -> anyhow::Result<()>;
150}
151"#
152}
153
154pub fn application_mod() -> &'static str {
156 r#"//! Application Layer
157//!
158//! This layer orchestrates domain objects to fulfill use cases.
159//! It depends only on the domain layer.
160
161pub mod services;
162
163pub use services::*;
164"#
165}
166
167pub fn application_services() -> &'static str {
169 r#"//! Application Services
170//!
171//! Use case orchestration lives here.
172
173// Example service (remove and add your own)
174pub struct ExampleService;
175
176impl ExampleService {
177 pub fn new() -> Self {
178 Self
179 }
180
181 pub async fn do_something(&self) -> anyhow::Result<String> {
182 Ok("Service executed successfully".to_string())
183 }
184}
185"#
186}
187
188pub fn infrastructure_mod() -> &'static str {
190 r#"//! Infrastructure Layer
191//!
192//! This layer implements domain repository traits and handles external concerns.
193//! It depends on the domain layer (implements traits defined there).
194
195pub mod repositories;
196
197pub use repositories::*;
198"#
199}
200
201pub fn infrastructure_repositories() -> &'static str {
203 r#"//! Repository Implementations
204//!
205//! Concrete implementations of domain repository traits.
206
207// Example repository implementation (remove and add your own)
208pub struct InMemoryExampleRepository;
209
210impl InMemoryExampleRepository {
211 pub fn new() -> Self {
212 Self
213 }
214}
215
216#[async_trait::async_trait]
217impl crate::domain::repositories::ExampleRepository for InMemoryExampleRepository {
218 async fn find_by_id(&self, _id: &str) -> anyhow::Result<Option<String>> {
219 Ok(None)
220 }
221
222 async fn save(&self, _id: &str, _data: String) -> anyhow::Result<()> {
223 Ok(())
224 }
225}
226"#
227}
228
229pub fn presentation_mod() -> &'static str {
231 r#"//! Presentation Layer
232//!
233//! This layer handles HTTP/gRPC/GraphQL requests and responses.
234//! It depends on the application and domain layers.
235
236pub mod handlers;
237
238pub use handlers::*;
239"#
240}
241
242pub fn presentation_handlers() -> &'static str {
244 r#"//! HTTP/API Handlers
245//!
246//! Thin handlers that delegate to application services.
247
248// Example handler (remove and add your own)
249pub async fn example_handler() -> String {
250 "Hello from AllFrame!".to_string()
251}
252"#
253}
254
255pub fn gitignore() -> &'static str {
257 r#"# Rust
258target/
259Cargo.lock
260
261# IDE
262.vscode/
263.idea/
264*.swp
265*.swo
266
267# OS
268.DS_Store
269Thumbs.db
270
271# Environment
272.env
273.env.local
274
275# Logs
276*.log
277"#
278}
279
280pub fn readme(project_name: &str) -> String {
293 format!(
294 r#"# {}
295
296An AllFrame application following Clean Architecture principles.
297
298## Quick Start
299
300```bash
301# Run the application
302cargo run
303
304# Run tests
305cargo test
306
307# Run with all features
308cargo run --all-features
309```
310
311## Structure
312
313This project follows Clean Architecture:
314
315```
316src/
317├── domain/ # Core business logic (no external dependencies)
318├── application/ # Use case orchestration
319├── infrastructure/ # External implementations (database, HTTP clients)
320└── presentation/ # HTTP/gRPC/GraphQL handlers
321```
322
323## Features
324
325- Clean Architecture enforced
326- TDD-first development
327- Protocol-agnostic (REST/GraphQL/gRPC)
328
329## Built with AllFrame
330
331[AllFrame](https://github.com/all-source-os/all-frame) - The composable Rust API framework.
332
333*One frame. Infinite transformations.*
334"#,
335 project_name
336 )
337}