create-filament 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +417 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.js +937 -0
  4. package/package.json +38 -0
  5. package/templates/api/src/config/app.ts +17 -0
  6. package/templates/api/src/handlers/errors.ts +32 -0
  7. package/templates/api/src/handlers/finalizers.ts +27 -0
  8. package/templates/api/src/handlers/transforms.ts +18 -0
  9. package/templates/api/src/index.ts +45 -0
  10. package/templates/api/src/meta/defaults.ts +28 -0
  11. package/templates/api/src/meta/index.ts +50 -0
  12. package/templates/api/src/middleware/index.ts +36 -0
  13. package/templates/api/src/routes/index.ts +26 -0
  14. package/templates/api/tests/integration/example.test.ts +20 -0
  15. package/templates/full/src/config/app.ts +17 -0
  16. package/templates/full/src/handlers/errors.ts +32 -0
  17. package/templates/full/src/handlers/finalizers.ts +27 -0
  18. package/templates/full/src/handlers/transforms.ts +18 -0
  19. package/templates/full/src/index.ts +45 -0
  20. package/templates/full/src/meta/defaults.ts +28 -0
  21. package/templates/full/src/meta/index.ts +31 -0
  22. package/templates/full/src/middleware/index.ts +36 -0
  23. package/templates/full/src/routes/index.ts +26 -0
  24. package/templates/full/tests/integration/example.test.ts +20 -0
  25. package/templates/minimal/src/config/app.ts +17 -0
  26. package/templates/minimal/src/handlers/errors.ts +32 -0
  27. package/templates/minimal/src/handlers/finalizers.ts +27 -0
  28. package/templates/minimal/src/handlers/transforms.ts +18 -0
  29. package/templates/minimal/src/index.ts +45 -0
  30. package/templates/minimal/src/meta/defaults.ts +28 -0
  31. package/templates/minimal/src/meta/index.ts +31 -0
  32. package/templates/minimal/src/middleware/index.ts +36 -0
  33. package/templates/minimal/src/routes/index.ts +26 -0
  34. package/templates/minimal/tests/integration/example.test.ts +20 -0
package/README.md ADDED
@@ -0,0 +1,417 @@
1
+ # create-filament
2
+
3
+ Scaffold a new Filament application with best practices built-in.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ # Interactive mode
9
+
10
+ npm create filament@latest
11
+
12
+ # With project name
13
+
14
+ npm create filament@latest my-api
15
+
16
+ # Non-interactive with options
17
+
18
+ npm create filament@latest my-api --template=full --docker --ci=github
19
+ ```
20
+
21
+ ## Templates
22
+
23
+ ### Minimal
24
+
25
+ Core framework with essential tooling:
26
+
27
+ - ✅ Filament framework
28
+ - ✅ TypeScript with strict mode
29
+ - ✅ ESLint + Prettier
30
+ - ✅ Husky + lint-staged + commitlint
31
+ - ✅ Pino logging
32
+ - ✅ Node test runner + test-battery
33
+ - ✅ Example endpoints
34
+ - ✅ Graceful shutdown handling
35
+
36
+ ### API
37
+
38
+ Everything in Minimal plus:
39
+
40
+ - ✅ JWT authentication middleware
41
+ - ✅ OAuth middleware examples
42
+ - ✅ Role-based access control (RBAC)
43
+ - ✅ Session management (Redis-backed)
44
+ - ✅ Rate limiting (Redis-backed)
45
+ - ✅ OpenAPI/Swagger generation
46
+ - ✅ Request validation examples
47
+ - ✅ Docker + Docker Compose (app + Redis)
48
+
49
+ ### Full
50
+
51
+ Everything in API plus:
52
+
53
+ - ✅ OpenTelemetry distributed tracing
54
+ - ✅ Prometheus metrics endpoint
55
+ - ✅ Analytics event collection
56
+ - ✅ Complete CI/CD pipeline (GitHub Actions)
57
+ - ✅ Production-ready Docker setup
58
+ - ✅ More comprehensive examples
59
+
60
+ ## Command-Line Options
61
+
62
+ ```bash
63
+ Options:
64
+ --template=<minimal|api|full> Choose template (default: interactive)
65
+ --docker Include Dockerfile
66
+ --docker-compose Include docker-compose.yml
67
+ --ci=<github|gitlab|none> CI/CD workflow
68
+ --pm=<npm|pnpm|yarn|bun> Package manager (default: npm)
69
+ --git Initialize git repository
70
+ --no-git-commit Skip initial commit
71
+
72
+ --no-install Skip dependency installation
73
+ ```
74
+
75
+ ## What Gets Generated
76
+
77
+ ### Project Structure
78
+
79
+ ```text
80
+ my-api/
81
+ ├── src/
82
+ │ ├── meta/ # Metadata interface and defaults
83
+ │ │ ├── index.ts # AppMeta interface definition
84
+ │ │ └── defaults.ts # Default metadata + presets
85
+ │ ├── middleware/ # Middleware functions
86
+ │ │ └── index.ts # Middleware registration
87
+ │ ├── routes/ # Route definitions
88
+ │ │ └── index.ts # Route registration
89
+ │ ├── handlers/ # Post-request handlers
90
+ │ │ ├── errors.ts # Error handlers
91
+ │ │ ├── transforms.ts # Response transformers
92
+ │ │ └── finalizers.ts # Finalizers (always run)
93
+ │ ├── config/ # Application configuration
94
+ │ │ └── app.ts # App config + validation
95
+ │ └── index.ts # Entry point
96
+ ├── tests/
97
+ │ ├── integration/ # Integration tests
98
+ │ └── unit/ # Unit tests
99
+ ├── .github/
100
+ │ └── workflows/
101
+ │ └── ci.yml # CI/CD pipeline (if --ci=github)
102
+ ├── .husky/ # Git hooks
103
+ │ ├── pre-commit # Runs lint-staged
104
+ │ └── commit-msg # Runs commitlint
105
+ ├── Dockerfile # Multi-stage Docker build (if --docker)
106
+ ├── docker-compose.yml # Local dev environment (if --docker-compose)
107
+ ├── .dockerignore
108
+ ├── .gitignore
109
+ ├── .env.example
110
+ ├── .eslintrc.json
111
+ ├── .prettierrc
112
+ ├── .lintstagedrc
113
+ ├── commitlint.config.js
114
+ ├── tsconfig.json
115
+ ├── package.json
116
+ ├── README.md
117
+ └── ARCHITECTURE.md
118
+ ```
119
+
120
+ ### Quality Management Tools
121
+
122
+ Every generated project includes:
123
+
124
+ **Linting & Formatting:**
125
+
126
+ - ESLint with TypeScript support
127
+ - Prettier for code formatting
128
+ - Pre-commit hooks to enforce quality
129
+
130
+ **Git Hygiene:**
131
+
132
+ - Husky for git hooks
133
+ - lint-staged (run linters only on staged files)
134
+ - commitlint (enforce conventional commits)
135
+
136
+ **Testing:**
137
+
138
+ - Node.js native test runner
139
+ - test-battery for assertions
140
+ - Test coverage reporting
141
+
142
+ **Dependency Management:**
143
+
144
+ - depcheck to find unused dependencies
145
+ - Configured in package.json scripts
146
+
147
+ **Type Safety:**
148
+
149
+ - TypeScript strict mode
150
+ - Path aliases configured (@/\* → src/\*)
151
+
152
+ ## Generated Scripts
153
+
154
+ ```json
155
+ {
156
+ "dev": "tsx watch src/index.ts",
157
+ "build": "tsc",
158
+ "start": "node dist/index.js",
159
+ "test": "node --test tests/**/*.test.ts",
160
+ "test:watch": "node --test --watch tests/**/*.test.ts",
161
+ "lint": "eslint src/**/*.ts",
162
+ "lint:fix": "eslint src/**/*.ts --fix",
163
+ "format": "prettier --write src/**/*.ts",
164
+ "type-check": "tsc --noEmit",
165
+ "depcheck": "depcheck",
166
+ "docker:build": "docker build -t <name> .",
167
+ "docker:run": "docker run -p 3000:3000 <name>",
168
+ "docker:up": "docker-compose up",
169
+ "docker:down": "docker-compose down"
170
+ }
171
+ ```
172
+
173
+ ## Environment Variables
174
+
175
+ Generated `.env.example`:
176
+
177
+ ```bash
178
+ # Server
179
+
180
+ PORT=3000
181
+ NODE_ENV=development
182
+ LOG_LEVEL=info
183
+
184
+ # Authentication (API+ templates)
185
+
186
+ JWT_SECRET=your-secret-here
187
+ JWT_EXPIRY=7d
188
+ REDIS_URL=redis://localhost:6379
189
+
190
+ # OpenTelemetry (Full template)
191
+
192
+ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
193
+ ```
194
+
195
+ ## Docker Support
196
+
197
+ ### Dockerfile Features
198
+
199
+ - Multi-stage build (builder + runtime)
200
+ - Minimal Alpine Linux base image
201
+ - Non-root user for security
202
+ - Health check built-in
203
+ - Optimized layer caching
204
+
205
+ ### docker-compose.yml
206
+
207
+ Includes services based on template:
208
+
209
+ - **app**: Your Filament application
210
+ - **redis**: For sessions, caching, rate limiting (API+)
211
+
212
+ ## CI/CD
213
+
214
+ ### GitHub Actions
215
+
216
+ Generated CI workflow runs on every push/PR:
217
+
218
+ 1. Install dependencies
219
+ 2. Run linter
220
+ 3. Run type checker
221
+ 4. Run tests
222
+ 5. Run depcheck
223
+ 6. Build project
224
+ 7. Build Docker image (if enabled)
225
+
226
+ ## Database Integration
227
+
228
+ Filament doesn't include a database ORM by design. The generated README includes examples for:
229
+
230
+ - Prisma
231
+ - Drizzle
232
+ - Kysely
233
+ - Raw SQL with node-postgres
234
+
235
+ ## Development Experience
236
+
237
+ ### First Run
238
+
239
+ ```bash
240
+ cd my-api
241
+ npm install # if not already run
242
+ npm run dev
243
+ ```
244
+
245
+ Output:
246
+
247
+ ```text
248
+ 🔥 Filament server running on http://localhost:3000
249
+ Environment: development
250
+ Log level: info
251
+ ```
252
+
253
+ ### Hot Reload
254
+
255
+ Uses `tsx watch` for instant restarts on file changes.
256
+
257
+ ### Logging
258
+
259
+ Structured JSON logging with Pino:
260
+
261
+ - Beautiful formatting in development (pino-pretty)
262
+ - JSON output in production
263
+ - Configurable log levels per endpoint
264
+
265
+ ## Metadata-Driven Architecture
266
+
267
+ The scaffold teaches Filament's metadata-driven approach from the start:
268
+
269
+ ### Metadata Interface
270
+
271
+ ```typescript
272
+ export interface AppMeta extends FrameworkMeta {
273
+ requiresAuth: boolean;
274
+ rateLimit: number;
275
+ logging: { level: string };
276
+ tags: string[];
277
+ }
278
+ ```
279
+
280
+ ### Metadata Presets
281
+
282
+ ```typescript
283
+ export const PUBLIC = { requiresAuth: false, rateLimit: 100 };
284
+ export const AUTHENTICATED = { requiresAuth: true, rateLimit: 50 };
285
+ ```
286
+
287
+ ### Usage in Routes
288
+
289
+ ```typescript
290
+ app.get('/users', PUBLIC, handler);
291
+ app.post('/admin', AUTHENTICATED, handler);
292
+ ```
293
+
294
+ ### Middleware Checks Metadata
295
+
296
+ ```typescript
297
+ app.use(async (req, res, next) => {
298
+ if (req.endpointMeta.requiresAuth) {
299
+ // Perform authentication
300
+ }
301
+ await next();
302
+ });
303
+ ```
304
+
305
+ ## Post-Request Handlers
306
+
307
+ Every template includes examples of:
308
+
309
+ ### Error Handlers
310
+
311
+ ```typescript
312
+ app.onError(async (err, req, res) => {
313
+ logger.error({ error: err.message });
314
+ res.status(500).json({ error: 'Internal Server Error' });
315
+ });
316
+ ```
317
+
318
+ ### Response Transformers
319
+
320
+ ```typescript
321
+ app.onTransform(async (req, res) => {
322
+ if (req.endpointMeta.tags.includes('api')) {
323
+ res.setHeader('X-API-Version', '1.0');
324
+ }
325
+ });
326
+ ```
327
+
328
+ ### Finalizers
329
+
330
+ ```typescript
331
+ app.onFinalize(async (req, res) => {
332
+ const duration = Date.now() - req._startTime;
333
+ logger.info({ duration, status: res.statusCode });
334
+ });
335
+ ```
336
+
337
+ ## Graceful Shutdown
338
+
339
+ All templates include proper signal handling:
340
+
341
+ ```typescript
342
+ process.on('SIGTERM', async () => {
343
+ await app.close();
344
+ process.exit(0);
345
+ });
346
+ ```
347
+
348
+ ## Best Practices Built-In
349
+
350
+ 1. **Type Safety**: Strict TypeScript configuration
351
+ 2. **Code Quality**: ESLint + Prettier + pre-commit hooks
352
+ 3. **Git Hygiene**: Conventional commits enforced
353
+ 4. **Testing**: Node test runner ready to use
354
+ 5. **Security**: Non-root Docker user, helmet headers
355
+ 6. **Observability**: Structured logging, request IDs
356
+ 7. **Performance**: Rate limiting, caching patterns
357
+ 8. **Maintainability**: Clear separation of concerns
358
+
359
+ ## Extending Your Project
360
+
361
+ ### Adding a New Route
362
+
363
+ 1. Create route file in `src/routes/<name>.ts`
364
+ 2. Export a registration function
365
+ 3. Import and call in `src/routes/index.ts`
366
+
367
+ ### Adding Middleware
368
+
369
+ 1. Create middleware file in `src/middleware/<name>.ts`
370
+ 2. Check `req.endpointMeta` for configuration
371
+ 3. Register in `src/middleware/index.ts`
372
+
373
+ ### Adding Metadata Fields
374
+
375
+ 1. Add to `AppMeta` interface in `src/meta/index.ts`
376
+ 2. Update `defaultMeta` in `src/meta/defaults.ts`
377
+ 3. Create presets for common combinations
378
+
379
+ ## Requirements
380
+
381
+ - Node.js 20+
382
+ - npm, pnpm, yarn, or bun
383
+ - Docker (optional, for containerization)
384
+
385
+ ## Development
386
+
387
+ ```bash
388
+ # Clone create-filament repo
389
+
390
+ git clone https://github.com/rocketcode-dev/create-filament
391
+
392
+ # Install dependencies
393
+
394
+ npm install
395
+
396
+ # Build CLI
397
+
398
+ npm run build
399
+
400
+ # Test locally
401
+
402
+ node dist/index.js my-test-app
403
+ ```
404
+
405
+ ## Contributing
406
+
407
+ Contributions welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md).
408
+
409
+ ## License
410
+
411
+ ISC
412
+
413
+ ## Related
414
+
415
+ - [Filament](https://github.com/rocketcode-dev/filament) - The framework
416
+ - [Filament Examples](https://github.com/rocketcode-dev/filament/tree/main/examples)
417
+ - [Documentation](https://filament.dev)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};