front-end-dev-standards 1.0.0 → 1.1.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.
@@ -0,0 +1,765 @@
1
+ # Coding Standards
2
+
3
+ Version: 1.0
4
+ Target: Angular 20+
5
+ Language: TypeScript 5+
6
+ Applies To: All Frontend Applications
7
+
8
+ ---
9
+
10
+ # 1. Coding Principles
11
+
12
+ ## Core Principles
13
+
14
+ 1. Readability over cleverness
15
+ 2. Simplicity over complexity
16
+ 3. Consistency over personal preference
17
+ 4. Explicit over implicit
18
+ 5. Composition over inheritance
19
+ 6. Strong typing over shortcuts
20
+ 7. Maintainability over speed of implementation
21
+
22
+ ---
23
+
24
+ # 2. Clean Code Rules
25
+
26
+ ## Functions
27
+
28
+ ### Must
29
+
30
+ * Have a single responsibility
31
+ * Be small and focused
32
+ * Have descriptive names
33
+ * Return one type consistently
34
+
35
+ Good:
36
+
37
+ ```typescript
38
+ calculateWeeklyHours(entries: TimesheetEntry[]): number
39
+ ```
40
+
41
+ Bad:
42
+
43
+ ```typescript
44
+ calc(data: any): any
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Function Size
50
+
51
+ Recommended:
52
+
53
+ ```text
54
+ 5 - 30 lines
55
+ ```
56
+
57
+ Maximum:
58
+
59
+ ```text
60
+ 50 lines
61
+ ```
62
+
63
+ Refactor beyond this.
64
+
65
+ ---
66
+
67
+ ## Nesting
68
+
69
+ Maximum nesting level:
70
+
71
+ ```text
72
+ 3 levels
73
+ ```
74
+
75
+ Bad:
76
+
77
+ ```typescript
78
+ if (...) {
79
+ if (...) {
80
+ if (...) {
81
+ if (...) {}
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ Prefer guard clauses.
88
+
89
+ ---
90
+
91
+ # 3. TypeScript Standards
92
+
93
+ ## Strict Mode
94
+
95
+ Required:
96
+
97
+ ```json
98
+ {
99
+ "strict": true,
100
+ "noImplicitReturns": true,
101
+ "noImplicitOverride": true,
102
+ "noUncheckedIndexedAccess": true,
103
+ "exactOptionalPropertyTypes": true
104
+ }
105
+ ```
106
+
107
+ ---
108
+
109
+ ## Type Rules
110
+
111
+ ### Prefer Interface
112
+
113
+ ```typescript
114
+ interface Employee {
115
+ id: string;
116
+ }
117
+ ```
118
+
119
+ ### Use Type For
120
+
121
+ ```typescript
122
+ type Status =
123
+ | 'active'
124
+ | 'inactive';
125
+ ```
126
+
127
+ ### Never Use
128
+
129
+ ```typescript
130
+ any
131
+ ```
132
+
133
+ Use:
134
+
135
+ ```typescript
136
+ unknown
137
+ ```
138
+
139
+ with type guards.
140
+
141
+ ---
142
+
143
+ ## Explicit Return Types
144
+
145
+ Required for:
146
+
147
+ * Public methods
148
+ * Services
149
+ * Utility functions
150
+
151
+ Example:
152
+
153
+ ```typescript
154
+ getEmployee(id: string): Observable<Employee>
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Readonly First
160
+
161
+ ```typescript
162
+ readonly employees =
163
+ signal<Employee[]>([]);
164
+ ```
165
+
166
+ Use readonly whenever mutation is not required.
167
+
168
+ ---
169
+
170
+ # 4. Naming Conventions
171
+
172
+ ## Classes
173
+
174
+ ```typescript
175
+ EmployeeService
176
+ TimesheetStore
177
+ AttendanceGuard
178
+ ```
179
+
180
+ ---
181
+
182
+ ## Interfaces
183
+
184
+ ```typescript
185
+ Employee
186
+ TimesheetEntry
187
+ ```
188
+
189
+ Never:
190
+
191
+ ```typescript
192
+ IEmployee
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Signals
198
+
199
+ ```typescript
200
+ loading
201
+ employees
202
+ selectedEmployee
203
+ ```
204
+
205
+ Boolean signals:
206
+
207
+ ```typescript
208
+ isLoading
209
+ hasError
210
+ canEdit
211
+ ```
212
+
213
+ ---
214
+
215
+ ## Observables
216
+
217
+ ```typescript
218
+ employees$
219
+ user$
220
+ permissions$
221
+ ```
222
+
223
+ Must use `$` suffix.
224
+
225
+ ---
226
+
227
+ ## Constants
228
+
229
+ ```typescript
230
+ MAX_RETRY_COUNT
231
+ DEFAULT_PAGE_SIZE
232
+ ```
233
+
234
+ ---
235
+
236
+ ## Enums
237
+
238
+ Prefer union types.
239
+
240
+ Avoid:
241
+
242
+ ```typescript
243
+ enum Status {}
244
+ ```
245
+
246
+ Prefer:
247
+
248
+ ```typescript
249
+ type Status =
250
+ | 'active'
251
+ | 'inactive';
252
+ ```
253
+
254
+ ---
255
+
256
+ # 5. Angular Coding Standards
257
+
258
+ ## Component Rules
259
+
260
+ Every component must:
261
+
262
+ * Be standalone
263
+ * Use OnPush
264
+ * Use inject()
265
+ * Use signals
266
+
267
+ Example:
268
+
269
+ ```typescript
270
+ @Component({
271
+ standalone: true,
272
+ changeDetection:
273
+ ChangeDetectionStrategy.OnPush
274
+ })
275
+ ```
276
+
277
+ ---
278
+
279
+ ## Member Order
280
+
281
+ 1. inject()
282
+ 2. input()
283
+ 3. output()
284
+ 4. signals
285
+ 5. computed
286
+ 6. effects
287
+ 7. lifecycle hooks
288
+ 8. public methods
289
+ 9. private methods
290
+
291
+ ---
292
+
293
+ # 6. Import Standards
294
+
295
+ Order imports:
296
+
297
+ ```typescript
298
+ Angular
299
+ Angular Material
300
+ RxJS
301
+ Third Party
302
+ Core
303
+ Shared
304
+ Feature
305
+ Relative
306
+ ```
307
+
308
+ Example:
309
+
310
+ ```typescript
311
+ import { Component } from '@angular/core';
312
+
313
+ import { MatButtonModule } from '@angular/material/button';
314
+
315
+ import { Observable } from 'rxjs';
316
+
317
+ import { EmployeeService } from '../../services';
318
+ ```
319
+
320
+ ---
321
+
322
+ # 7. Signal Standards
323
+
324
+ Default State Management:
325
+
326
+ ```typescript
327
+ readonly loading =
328
+ signal(false);
329
+
330
+ readonly employees =
331
+ signal<Employee[]>([]);
332
+ ```
333
+
334
+ Derived State:
335
+
336
+ ```typescript
337
+ readonly activeEmployees =
338
+ computed(() =>
339
+ this.employees()
340
+ .filter(x => x.active)
341
+ );
342
+ ```
343
+
344
+ Avoid:
345
+
346
+ ```typescript
347
+ BehaviorSubject
348
+ ```
349
+
350
+ for component state.
351
+
352
+ ---
353
+
354
+ # 8. Template Standards
355
+
356
+ Use Angular Control Flow.
357
+
358
+ Preferred:
359
+
360
+ ```html
361
+ @if (loading()) {
362
+ <app-loader />
363
+ }
364
+ ```
365
+
366
+ Avoid:
367
+
368
+ ```html
369
+ <div *ngIf="loading()"></div>
370
+ ```
371
+
372
+ ---
373
+
374
+ ## Loops
375
+
376
+ Always track:
377
+
378
+ ```html
379
+ @for (
380
+ employee of employees();
381
+ track employee.id
382
+ )
383
+ ```
384
+
385
+ Never omit track.
386
+
387
+ ---
388
+
389
+ # 9. HTML Standards
390
+
391
+ ## Accessibility
392
+
393
+ Every interactive element must have:
394
+
395
+ * aria-label
396
+ * keyboard support
397
+ * visible focus state
398
+
399
+ Example:
400
+
401
+ ```html
402
+ <button
403
+ aria-label="Submit Timesheet">
404
+ </button>
405
+ ```
406
+
407
+ ---
408
+
409
+ # 10. SCSS Standards
410
+
411
+ ## Structure
412
+
413
+ ```scss
414
+ :host {}
415
+
416
+ .component {}
417
+
418
+ .component__header {}
419
+
420
+ .component__body {}
421
+
422
+ .component--active {}
423
+ ```
424
+
425
+ Use BEM.
426
+
427
+ ---
428
+
429
+ ## Forbidden
430
+
431
+ ```scss
432
+ !important
433
+ ```
434
+
435
+ Unless overriding third-party code.
436
+
437
+ ---
438
+
439
+ # 11. SOLID Principles
440
+
441
+ ## Single Responsibility
442
+
443
+ One component.
444
+
445
+ One purpose.
446
+
447
+ ---
448
+
449
+ ## Open Closed
450
+
451
+ Extend behavior.
452
+
453
+ Avoid modifying stable code.
454
+
455
+ ---
456
+
457
+ ## Dependency Inversion
458
+
459
+ Depend on abstractions.
460
+
461
+ Not concrete implementations.
462
+
463
+ ---
464
+
465
+ # 12. Error Handling Standards
466
+
467
+ Every async operation must handle:
468
+
469
+ * Loading
470
+ * Success
471
+ * Error
472
+
473
+ Example:
474
+
475
+ ```typescript
476
+ try {
477
+ ...
478
+ }
479
+ catch (error) {
480
+ ...
481
+ }
482
+ finally {
483
+ ...
484
+ }
485
+ ```
486
+
487
+ ---
488
+
489
+ ## User Messages
490
+
491
+ Never show raw API errors.
492
+
493
+ Bad:
494
+
495
+ ```typescript
496
+ error.message
497
+ ```
498
+
499
+ Good:
500
+
501
+ ```typescript
502
+ 'Unable to load employees.'
503
+ ```
504
+
505
+ ---
506
+
507
+ # 13. Logging Standards
508
+
509
+ Use:
510
+
511
+ ```typescript
512
+ LoggerService
513
+ ```
514
+
515
+ Never:
516
+
517
+ ```typescript
518
+ console.log()
519
+ ```
520
+
521
+ Production code must not contain:
522
+
523
+ ```typescript
524
+ console.log
525
+ console.warn
526
+ console.debug
527
+ ```
528
+
529
+ ---
530
+
531
+ # 14. Security Standards
532
+
533
+ Never:
534
+
535
+ ```typescript
536
+ innerHTML = value
537
+ ```
538
+
539
+ Never:
540
+
541
+ ```typescript
542
+ bypassSecurityTrustHtml()
543
+ ```
544
+
545
+ without approval.
546
+
547
+ ---
548
+
549
+ ## Secrets
550
+
551
+ Never commit:
552
+
553
+ * Tokens
554
+ * Passwords
555
+ * API Keys
556
+
557
+ Use environment configuration.
558
+
559
+ ---
560
+
561
+ # 15. Performance Standards
562
+
563
+ Mandatory:
564
+
565
+ * OnPush
566
+ * Lazy Loading
567
+ * Signals
568
+ * track in loops
569
+
570
+ Use:
571
+
572
+ ```typescript
573
+ computed()
574
+ ```
575
+
576
+ instead of recalculating data.
577
+
578
+ ---
579
+
580
+ ## Avoid
581
+
582
+ ```typescript
583
+ get employees() {
584
+ }
585
+ ```
586
+
587
+ in templates.
588
+
589
+ Prefer signals.
590
+
591
+ ---
592
+
593
+ # 16. Testing Standards
594
+
595
+ Minimum Coverage
596
+
597
+ ```text
598
+ 80%
599
+ ```
600
+
601
+ Critical Logic
602
+
603
+ ```text
604
+ 95%
605
+ ```
606
+
607
+ Required:
608
+
609
+ * Services
610
+ * Guards
611
+ * Interceptors
612
+ * Pipes
613
+ * Complex Components
614
+
615
+ ---
616
+
617
+ # 17. Documentation Standards
618
+
619
+ Document:
620
+
621
+ * Public APIs
622
+ * Shared Components
623
+ * Complex Business Rules
624
+
625
+ Example:
626
+
627
+ ```typescript
628
+ /**
629
+ * Calculates overtime based on
630
+ * company attendance policy.
631
+ */
632
+ ```
633
+
634
+ ---
635
+
636
+ # 18. TODO Standards
637
+
638
+ Required Format:
639
+
640
+ ```typescript
641
+ // TODO(HRMS-123):
642
+ // Replace mock service
643
+ ```
644
+
645
+ Never:
646
+
647
+ ```typescript
648
+ // TODO later
649
+ ```
650
+
651
+ ---
652
+
653
+ # 19. Git Standards
654
+
655
+ Branch Names:
656
+
657
+ ```text
658
+ feature/timesheet-preview
659
+ bugfix/leave-balance
660
+ hotfix/auth-redirect
661
+ ```
662
+
663
+ ---
664
+
665
+ ## Commit Format
666
+
667
+ ```text
668
+ feat(timesheet): add preview panel
669
+
670
+ fix(attendance): correct clock-out validation
671
+
672
+ refactor(shared): simplify data table
673
+
674
+ test(payroll): add salary service tests
675
+ ```
676
+
677
+ ---
678
+
679
+ # 20. AI Generated Code Standards
680
+
681
+ AI-generated code must:
682
+
683
+ ✓ Use Standalone Components
684
+
685
+ ✓ Use Signals
686
+
687
+ ✓ Use inject()
688
+
689
+ ✓ Include Error Handling
690
+
691
+ ✓ Include Loading States
692
+
693
+ ✓ Include Accessibility
694
+
695
+ ✓ Include Types
696
+
697
+ ✓ Follow Naming Standards
698
+
699
+ Reject code that:
700
+
701
+ ✗ Uses any
702
+
703
+ ✗ Uses NgModules
704
+
705
+ ✗ Uses constructor injection
706
+
707
+ ✗ Uses default change detection
708
+
709
+ ✗ Contains console.log
710
+
711
+ ✗ Contains hardcoded values
712
+
713
+ ---
714
+
715
+ # 21. Code Review Checklist
716
+
717
+ Before Approval:
718
+
719
+ □ Strict typing
720
+
721
+ □ No any types
722
+
723
+ □ OnPush enabled
724
+
725
+ □ Signals used correctly
726
+
727
+ □ No memory leaks
728
+
729
+ □ Tests added
730
+
731
+ □ Accessibility verified
732
+
733
+ □ Responsive design verified
734
+
735
+ □ Security reviewed
736
+
737
+ □ Performance reviewed
738
+
739
+ □ Documentation updated
740
+
741
+ ---
742
+
743
+ # 22. Definition of Code Quality
744
+
745
+ Code is considered production ready when:
746
+
747
+ ✓ Readable
748
+
749
+ ✓ Typed
750
+
751
+ ✓ Tested
752
+
753
+ ✓ Accessible
754
+
755
+ ✓ Secure
756
+
757
+ ✓ Performant
758
+
759
+ ✓ Maintainable
760
+
761
+ ✓ Reviewed
762
+
763
+ ✓ Documented
764
+
765
+ ✓ Follows architecture standards