envx_core/
templates.rs

1use ahash::AHashMap as HashMap;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct ProjectTemplate {
6    pub name: String,
7    pub description: String,
8    pub category: String,
9    pub variables: Vec<TemplateVariable>,
10    pub profiles: HashMap<String, ProfileTemplate>,
11    pub scripts: HashMap<String, ScriptTemplate>,
12}
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct TemplateVariable {
16    pub name: String,
17    pub description: String,
18    pub default: Option<String>,
19    pub example: String,
20    pub required: bool,
21    pub sensitive: bool,
22    pub pattern: Option<String>,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct ProfileTemplate {
27    pub description: String,
28    pub variables: HashMap<String, String>,
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
32pub struct ScriptTemplate {
33    pub description: String,
34    pub run: String,
35    pub env: HashMap<String, String>,
36}
37
38#[must_use]
39#[allow(clippy::too_many_lines)]
40pub fn get_builtin_templates() -> Vec<ProjectTemplate> {
41    vec![
42        // Next.js Full-Stack Template
43        ProjectTemplate {
44            name: "Next.js Full-Stack App".to_string(),
45            description: "Next.js application with TypeScript and PostgreSQL".to_string(),
46            category: "web".to_string(),
47            variables: vec![
48                TemplateVariable {
49                    name: "DATABASE_URL".to_string(),
50                    description: "PostgreSQL connection string".to_string(),
51                    default: None,
52                    example: "postgresql://user:pass@localhost:5432/myapp".to_string(),
53                    required: true,
54                    sensitive: true,
55                    pattern: Some(r"^postgresql://.*".to_string()),
56                },
57                TemplateVariable {
58                    name: "NEXTAUTH_URL".to_string(),
59                    description: "NextAuth.js callback URL".to_string(),
60                    default: Some("http://localhost:3000".to_string()),
61                    example: "https://myapp.com".to_string(),
62                    required: true,
63                    sensitive: false,
64                    pattern: Some(r"^https?://.*".to_string()),
65                },
66                TemplateVariable {
67                    name: "NEXTAUTH_SECRET".to_string(),
68                    description: "NextAuth.js secret for JWT encryption".to_string(),
69                    default: None,
70                    example: "your-secret-key".to_string(),
71                    required: true,
72                    sensitive: true,
73                    pattern: None,
74                },
75            ],
76            profiles: HashMap::from([
77                (
78                    "development".to_string(),
79                    ProfileTemplate {
80                        description: "Local development environment".to_string(),
81                        variables: HashMap::from([
82                            ("NODE_ENV".to_string(), "development".to_string()),
83                            (
84                                "NEXT_PUBLIC_API_URL".to_string(),
85                                "http://localhost:3000/api".to_string(),
86                            ),
87                        ]),
88                    },
89                ),
90                (
91                    "production".to_string(),
92                    ProfileTemplate {
93                        description: "Production environment".to_string(),
94                        variables: HashMap::from([
95                            ("NODE_ENV".to_string(), "production".to_string()),
96                            ("NEXT_PUBLIC_API_URL".to_string(), "https://api.myapp.com".to_string()),
97                        ]),
98                    },
99                ),
100            ]),
101            scripts: HashMap::from([
102                (
103                    "dev".to_string(),
104                    ScriptTemplate {
105                        description: "Start development server".to_string(),
106                        run: "npm run dev".to_string(),
107                        env: HashMap::from([("NODE_ENV".to_string(), "development".to_string())]),
108                    },
109                ),
110                (
111                    "build".to_string(),
112                    ScriptTemplate {
113                        description: "Build for production".to_string(),
114                        run: "npm run build".to_string(),
115                        env: HashMap::from([("NODE_ENV".to_string(), "production".to_string())]),
116                    },
117                ),
118            ]),
119        },
120        // Django + PostgreSQL Template
121        ProjectTemplate {
122            name: "Django + PostgreSQL".to_string(),
123            description: "Django web application with PostgreSQL database".to_string(),
124            category: "web".to_string(),
125            variables: vec![
126                TemplateVariable {
127                    name: "SECRET_KEY".to_string(),
128                    description: "Django secret key".to_string(),
129                    default: None,
130                    example: "django-insecure-...".to_string(),
131                    required: true,
132                    sensitive: true,
133                    pattern: None,
134                },
135                TemplateVariable {
136                    name: "DATABASE_URL".to_string(),
137                    description: "PostgreSQL connection string".to_string(),
138                    default: None,
139                    example: "postgres://user:pass@localhost:5432/mydb".to_string(),
140                    required: true,
141                    sensitive: true,
142                    pattern: Some(r"^postgres://.*".to_string()),
143                },
144                TemplateVariable {
145                    name: "ALLOWED_HOSTS".to_string(),
146                    description: "Comma-separated list of allowed hosts".to_string(),
147                    default: Some("localhost,127.0.0.1".to_string()),
148                    example: "myapp.com,www.myapp.com".to_string(),
149                    required: true,
150                    sensitive: false,
151                    pattern: None,
152                },
153            ],
154            profiles: HashMap::from([
155                (
156                    "development".to_string(),
157                    ProfileTemplate {
158                        description: "Local development".to_string(),
159                        variables: HashMap::from([
160                            ("DEBUG".to_string(), "True".to_string()),
161                            ("DJANGO_SETTINGS_MODULE".to_string(), "myapp.settings.dev".to_string()),
162                        ]),
163                    },
164                ),
165                (
166                    "production".to_string(),
167                    ProfileTemplate {
168                        description: "Production deployment".to_string(),
169                        variables: HashMap::from([
170                            ("DEBUG".to_string(), "False".to_string()),
171                            ("DJANGO_SETTINGS_MODULE".to_string(), "myapp.settings.prod".to_string()),
172                        ]),
173                    },
174                ),
175            ]),
176            scripts: HashMap::from([
177                (
178                    "migrate".to_string(),
179                    ScriptTemplate {
180                        description: "Run database migrations".to_string(),
181                        run: "python manage.py migrate".to_string(),
182                        env: HashMap::new(),
183                    },
184                ),
185                (
186                    "runserver".to_string(),
187                    ScriptTemplate {
188                        description: "Start development server".to_string(),
189                        run: "python manage.py runserver".to_string(),
190                        env: HashMap::new(),
191                    },
192                ),
193            ]),
194        },
195        // Add more templates as needed...
196    ]
197}