-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_docs.py
More file actions
1394 lines (1189 loc) · 54.6 KB
/
generate_docs.py
File metadata and controls
1394 lines (1189 loc) · 54.6 KB
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
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
TaskFlow Architecture Documentation PDF Generator
Generates a comprehensive LaTeX-styled PDF using fpdf2.
"""
from fpdf import FPDF
import datetime
class TaskFlowDoc(FPDF):
INDIGO = (99, 102, 241)
INDIGO_DARK = (79, 70, 229)
DARK_BG = (15, 23, 42)
GRAY_700 = (51, 65, 85)
GRAY_500 = (100, 116, 139)
GRAY_400 = (148, 163, 184)
GRAY_200 = (226, 232, 240)
WHITE = (255, 255, 255)
SUCCESS = (16, 185, 129)
WARNING = (245, 158, 11)
DANGER = (239, 68, 68)
ACCENT = (6, 182, 212)
CODE_BG = (241, 245, 249)
def header(self):
if self.page_no() == 1:
return
self.set_font("Helvetica", "B", 8)
self.set_text_color(*self.GRAY_500)
self.cell(0, 8, "TaskFlow - Architecture Documentation", align="L")
self.cell(0, 8, f"Page {self.page_no()}", align="R", new_x="LMARGIN", new_y="NEXT")
self.set_draw_color(*self.GRAY_200)
self.line(self.l_margin, self.get_y(), self.w - self.r_margin, self.get_y())
self.ln(6)
def footer(self):
if self.page_no() == 1:
return
self.set_y(-15)
self.set_font("Helvetica", "I", 7)
self.set_text_color(*self.GRAY_400)
self.cell(0, 10, f"Generated {datetime.date.today().strftime('%B %d, %Y')} | TaskFlow v2.0", align="C")
# ---- Reusable helpers ----
def cover_page(self):
self.add_page()
# Big gradient-like header block
self.set_fill_color(*self.INDIGO)
self.rect(0, 0, 210, 120, "F")
self.set_fill_color(*self.INDIGO_DARK)
self.rect(0, 100, 210, 20, "F")
self.set_y(32)
self.set_font("Helvetica", "B", 42)
self.set_text_color(*self.WHITE)
self.cell(0, 16, "TaskFlow", align="C", new_x="LMARGIN", new_y="NEXT")
self.set_font("Helvetica", "", 14)
self.set_text_color(200, 200, 255)
self.cell(0, 10, "Smart Todo Manager", align="C", new_x="LMARGIN", new_y="NEXT")
self.ln(6)
self.set_font("Helvetica", "", 11)
self.cell(0, 8, "Architecture & Developer Documentation", align="C", new_x="LMARGIN", new_y="NEXT")
# Subtitle box
self.set_y(135)
self.set_font("Helvetica", "", 11)
self.set_text_color(*self.GRAY_700)
self.cell(0, 8, "Version 2.0 | February 2026", align="C", new_x="LMARGIN", new_y="NEXT")
self.ln(4)
self.set_font("Helvetica", "I", 10)
self.set_text_color(*self.GRAY_500)
self.cell(0, 8, "A complete guide to understanding, maintaining, and extending the TaskFlow application.", align="C", new_x="LMARGIN", new_y="NEXT")
# Tech badges
self.ln(10)
techs = ["HTML5", "CSS3", "JavaScript ES6+", "Chart.js", "PWA", "LocalStorage API"]
total_w = sum(self.get_string_width(t) + 14 for t in techs) + 6 * (len(techs) - 1)
start_x = (210 - total_w) / 2
self.set_x(start_x)
for t in techs:
w = self.get_string_width(t) + 14
self.set_fill_color(*self.INDIGO)
self.set_text_color(*self.WHITE)
self.set_font("Helvetica", "B", 9)
self.cell(w, 22, t, align="C", fill=True)
self.set_x(self.get_x() + 6)
def section_title(self, number, title):
self.ln(6)
self.set_font("Helvetica", "B", 20)
self.set_text_color(*self.INDIGO)
self.cell(0, 12, f"{number}. {title}", new_x="LMARGIN", new_y="NEXT")
self.set_draw_color(*self.INDIGO)
self.set_line_width(0.6)
self.line(self.l_margin, self.get_y() + 1, self.l_margin + 60, self.get_y() + 1)
self.set_line_width(0.2)
self.ln(6)
def subsection(self, title):
self.ln(3)
self.set_font("Helvetica", "B", 13)
self.set_text_color(*self.GRAY_700)
self.cell(0, 9, title, new_x="LMARGIN", new_y="NEXT")
self.ln(2)
def subsubsection(self, title):
self.ln(2)
self.set_font("Helvetica", "B", 11)
self.set_text_color(*self.GRAY_700)
self.cell(0, 7, title, new_x="LMARGIN", new_y="NEXT")
self.ln(1)
def body_text(self, text):
self.set_font("Helvetica", "", 10)
self.set_text_color(*self.GRAY_700)
self.multi_cell(0, 5.5, text)
self.ln(2)
def bullet(self, text, level=0):
indent = 10 + level * 8
self.set_x(self.l_margin + indent)
self.set_font("Helvetica", "B", 10)
self.set_text_color(*self.INDIGO)
marker = ">" if level == 0 else "-"
self.cell(6, 5.5, marker)
self.set_font("Helvetica", "", 10)
self.set_text_color(*self.GRAY_700)
remaining_w = self.w - self.get_x() - self.r_margin
self.multi_cell(remaining_w, 5.5, text)
self.ln(1)
def code_block(self, code, title=None):
if title:
self.set_font("Helvetica", "B", 8)
self.set_text_color(*self.GRAY_500)
self.cell(0, 5, title, new_x="LMARGIN", new_y="NEXT")
self.ln(1)
self.set_fill_color(*self.CODE_BG)
self.set_draw_color(*self.GRAY_200)
x = self.l_margin
w = self.w - self.l_margin - self.r_margin
self.set_font("Courier", "", 8)
self.set_text_color(*self.GRAY_700)
lines = code.strip().split("\n")
line_h = 4.2
block_h = len(lines) * line_h + 8
if self.get_y() + block_h > self.h - self.b_margin:
self.add_page()
y_start = self.get_y()
self.rect(x, y_start, w, block_h, "FD")
self.set_y(y_start + 4)
for line in lines:
self.set_x(x + 6)
self.cell(w - 12, line_h, line[:120], new_x="LMARGIN", new_y="NEXT")
self.set_y(y_start + block_h + 2)
self.ln(2)
def info_box(self, text, color=None):
if color is None:
color = self.INDIGO
x = self.l_margin
w = self.w - self.l_margin - self.r_margin
self.set_fill_color(color[0], color[1], color[2])
self.rect(x, self.get_y(), 3, 18, "F")
bg = (color[0] // 4 + 191, color[1] // 4 + 191, color[2] // 4 + 191)
self.set_fill_color(*bg)
self.rect(x + 3, self.get_y(), w - 3, 18, "F")
self.set_x(x + 10)
self.set_font("Helvetica", "", 9)
self.set_text_color(*self.GRAY_700)
y_start = self.get_y()
self.set_y(y_start + 3)
self.set_x(x + 10)
self.multi_cell(w - 16, 4.5, text)
self.set_y(y_start + 20)
self.ln(2)
def table_header(self, cols, widths):
self.set_fill_color(*self.INDIGO)
self.set_text_color(*self.WHITE)
self.set_font("Helvetica", "B", 9)
for i, col in enumerate(cols):
self.cell(widths[i], 8, col, border=1, align="C", fill=True)
self.ln()
def table_row(self, cells, widths, fill=False):
if fill:
self.set_fill_color(*self.CODE_BG)
else:
self.set_fill_color(*self.WHITE)
self.set_text_color(*self.GRAY_700)
self.set_font("Helvetica", "", 9)
for i, cell_text in enumerate(cells):
self.cell(widths[i], 7, cell_text, border=1, align="C" if i > 0 else "L", fill=True)
self.ln()
def build_pdf():
pdf = TaskFlowDoc(orientation="P", unit="mm", format="A4")
pdf.set_auto_page_break(auto=True, margin=20)
pdf.set_margins(20, 15, 20)
# ===================== COVER PAGE =====================
pdf.cover_page()
# ===================== TABLE OF CONTENTS =====================
pdf.add_page()
pdf.set_font("Helvetica", "B", 22)
pdf.set_text_color(*pdf.INDIGO)
pdf.cell(0, 14, "Table of Contents", new_x="LMARGIN", new_y="NEXT")
pdf.ln(6)
toc = [
("1", "Project Overview", "3"),
("2", "Technology Stack", "4"),
("3", "Project Structure", "5"),
("4", "Architecture Overview", "7"),
("5", "HTML Layer (index.html)", "9"),
("6", "CSS Architecture (style.css)", "12"),
("7", "JavaScript Architecture (app.js)", "16"),
("8", "Data Model & Storage", "21"),
("9", "Circular Progress Bar", "23"),
("10", "Chart.js Integration", "24"),
("11", "Theme System (Dark Mode)", "26"),
("12", "Responsive Design System", "27"),
("13", "Animation System", "29"),
("14", "PWA & Add to Home Screen", "30"),
("15", "Security Considerations", "31"),
("16", "Performance Notes", "31"),
("17", "Developer Guide", "32"),
]
for num, title, page in toc:
pdf.set_font("Helvetica", "B" if "." not in num else "", 11 if "." not in num else 10)
pdf.set_text_color(*pdf.GRAY_700)
dot_leader = "." * (70 - len(f"{num} {title}"))
pdf.set_x(25)
pdf.cell(12, 7, num, new_x="END")
pdf.cell(100, 7, title, new_x="END")
pdf.set_font("Helvetica", "", 9)
pdf.set_text_color(*pdf.GRAY_400)
pdf.cell(0, 7, page, align="R", new_x="LMARGIN", new_y="NEXT")
# ===================== 1. PROJECT OVERVIEW =====================
pdf.add_page()
pdf.section_title("1", "Project Overview")
pdf.body_text(
"TaskFlow is a modern, full-featured task management web application built entirely with "
"vanilla HTML, CSS, and JavaScript. It provides a professional-grade user experience with "
"a dashboard layout, real-time analytics, data visualization, and a fully responsive design "
"that works across all device sizes from desktop monitors to mobile phones."
)
pdf.body_text(
"The application follows a client-side architecture where all data is persisted in the "
"browser's localStorage API, requiring zero backend infrastructure. This makes it instantly "
"deployable as a static site on any hosting platform."
)
pdf.subsection("Key Features")
features = [
"CRUD operations: Create, read, update (toggle), and delete tasks",
"Priority system: Three levels (Low, Medium, High) with color-coded badges",
"Circular SVG progress bar: Animated ring showing completion percentage",
"Weekly activity bar chart: Tasks completed per day over the last 7 days (Chart.js)",
"Task distribution doughnut chart: Visual split of completed vs pending tasks",
"Real-time search: Instant text filtering as you type",
"Multi-filter toolbar: Filter by status (All/Active/Completed) and priority",
"Dark mode: Full theme toggle with localStorage persistence",
"Responsive design: 4 breakpoints (desktop, tablet, mobile, small mobile)",
"Data migration: Automatic upgrade from legacy localStorage format",
"XSS protection: All user input is escaped before rendering",
"Smooth animations: slideIn, slideOut, shake validation, hover micro-interactions",
"Batch operations: Clear all completed tasks at once with animated removal",
"PWA support: Installable as app (Add to Home Screen on iOS/Android), offline cache via service worker",
]
for f in features:
pdf.bullet(f)
# ===================== 2. TECHNOLOGY STACK =====================
pdf.add_page()
pdf.section_title("2", "Technology Stack")
pdf.body_text(
"TaskFlow is intentionally built with zero build tools and no npm dependencies. "
"This makes it easy to clone, open, and run instantly in any browser."
)
widths = [45, 50, 75]
pdf.table_header(["Technology", "Version", "Purpose"], widths)
rows = [
("HTML5", "Living Standard", "Semantic structure, SVG graphics, ARIA attrs"),
("CSS3", "Living Standard", "Custom Properties, Grid, Flexbox, animations"),
("JavaScript", "ES6+", "Application logic, DOM manipulation, events"),
("Chart.js", "v4.x (CDN)", "Bar chart and doughnut chart rendering"),
("Web App Manifest", "W3C", "PWA metadata, icons, theme, display mode"),
("Service Worker", "Web API", "Offline cache, installability"),
("Google Fonts", "Inter", "Typography (weights 300-800)"),
("localStorage", "Web API", "Client-side data persistence"),
("SVG", "1.1", "Circular progress bar, inline icons"),
]
for i, r in enumerate(rows):
pdf.table_row(r, widths, fill=i % 2 == 0)
pdf.ln(4)
pdf.info_box(
"Note: Chart.js is loaded from CDN (cdn.jsdelivr.net/npm/chart.js). "
"If it fails to load, the app degrades gracefully - all features work except the two charts."
)
# ===================== 3. PROJECT STRUCTURE =====================
pdf.add_page()
pdf.section_title("3", "Project Structure")
pdf.code_block(
"""taskflow-project/
|-- index.html # Single-page application entry point
|-- manifest.webmanifest # PWA manifest (name, icons, theme, display)
|-- sw.js # Service worker (offline cache)
|-- css/
| +-- style.css # Complete stylesheet
|-- js/
| +-- app.js # Application logic, charts, SW registration
|-- assets/
| +-- images/
| | +-- check.png # Legacy asset (kept for history)
| +-- icons/
| +-- icon-192.png # PWA icon 192x192 (home screen)
| +-- icon-512.png # PWA icon 512x512
|-- docs/
| +-- TaskFlow_Architecture.pdf # This document
|-- generate_docs.py # PDF documentation generator
|-- .gitignore
|-- README.md""",
title="Directory Tree"
)
pdf.body_text(
"The project follows a classic separation of concerns with three core application files, "
"plus PWA assets:"
)
pdf.bullet("index.html - Structure and content, PWA meta/link tags")
pdf.bullet("css/style.css - Presentation and responsive layout")
pdf.bullet("js/app.js - Behavior, state management, charts, service worker registration")
pdf.bullet("manifest.webmanifest - PWA name, icons, theme_color, display: standalone")
pdf.bullet("sw.js - Service worker for caching static assets (offline support)")
pdf.ln(2)
pdf.body_text(
"There is no build step, no bundler, and no transpilation. The code runs directly in "
"the browser. The app is installable as a PWA (Add to Home Screen on iOS and Android)."
)
# ===================== 4. ARCHITECTURE OVERVIEW =====================
pdf.add_page()
pdf.section_title("4", "Architecture Overview")
pdf.body_text(
"TaskFlow uses a straightforward Model-View-Controller-like pattern implemented "
"in vanilla JavaScript. The architecture is designed for simplicity and maintainability."
)
pdf.subsection("4.1 High-Level Architecture Diagram")
pdf.code_block(
"""+================================================================+
| BROWSER |
| +------------------+ +------------------+ +-------+ +------+ |
| | index.html | | css/style.css | |manifest| | sw.js| |
| | (Structure + | | (Presentation) | |(PWA) | |(Cache)| |
| | PWA meta) | +--------+---------+ +----+---+ +--+---+ |
| +--------+---------+ | | | |
| | | | | |
| +--------+---------+ +------v----------------v---------v+ |
| | js/app.js | | Chart.js (CDN) | |
| | (Behavior + | +-----------------------------------+ |
| | SW register) | |
| +---+----+---+-----+ |
| | | | |
| +---+ +-+ +--------+ +------------+ |
| v v v v |
| DOM Storage Chart.js Service Worker |
| API (local Instances (offline cache) |
| Storage) |
| | |
| +--------v--------+ |
| | localStorage | |
| | (JSON data) | |
| +-----------------+ |
+================================================================+""",
title="System Architecture"
)
pdf.subsection("4.2 Data Flow")
pdf.code_block(
"""User Action (click/type/submit)
|
v
Event Handler (handleAddTask, handleTaskClick, etc.)
|
v
State Mutation (todos array modified)
|
+----> saveTodos() ----> localStorage.setItem()
|
v
render() function called
|
+----> renderTasks() (rebuilds task list DOM)
+----> updateStats() (updates circle + stat cards)
+----> updateCharts() (refreshes Chart.js instances)""",
title="Unidirectional Data Flow"
)
pdf.body_text(
"Every user interaction follows the same unidirectional flow: Event -> State Mutation -> "
"Save -> Re-render. This predictable pattern makes debugging straightforward: if the UI "
"is wrong, check the state; if the state is wrong, check the event handler."
)
pdf.subsection("4.3 Module Organization")
pdf.body_text(
"Although contained in a single file (app.js), the code is organized into clearly "
"separated sections using comment headers:"
)
widths2 = [45, 125]
pdf.table_header(["Section", "Responsibility"], widths2)
sections = [
("Constants", "Storage keys, configuration values"),
("State", "Global todos array, chart instance references"),
("DOM References", "Cached querySelector results in 'el' object"),
("Utilities", "generateId, escapeHtml, capitalize, formatDate"),
("Local Storage", "loadTodos (with migration), saveTodos"),
("Todo CRUD", "addTodo, toggleTodo, deleteTodo, clearCompleted"),
("Filtering", "getFilteredTodos with search + status + priority"),
("Rendering", "createTaskElement, renderTasks, updateStats, render"),
("Charts", "Chart.js init, update, weekly data, color helpers"),
("Theme", "initTheme, toggleTheme with chart color sync"),
("Event Handlers", "handleAddTask, handleTaskClick"),
("Initialization", "init() - wires everything + service worker registration"),
]
for i, r in enumerate(sections):
pdf.table_row(r, widths2, fill=i % 2 == 0)
# ===================== 5. HTML LAYER =====================
pdf.add_page()
pdf.section_title("5", "HTML Layer (index.html)")
pdf.body_text(
"The HTML file is a single-page application with semantic elements. It defines the "
"complete UI structure and relies on CSS for layout and JS for dynamic behavior."
)
pdf.subsection("5.1 Document Head")
pdf.body_text(
"The <head> section includes viewport meta for responsive design (with viewport-fit=cover "
"for notched devices), theme-color, and the main stylesheet. For PWA and Add to Home "
"Screen support it also includes: <link rel='manifest' href='manifest.webmanifest'>, "
"<link rel='apple-touch-icon' href='assets/icons/icon-192.png'>, and iOS-specific meta "
"tags (apple-mobile-web-app-capable, apple-mobile-web-app-status-bar-style, "
"apple-mobile-web-app-title). Google Fonts use preconnect for faster font loading."
)
pdf.subsection("5.2 Layout Structure")
pdf.code_block(
"""<body>
<header class="app-header"> <!-- Sticky gradient header -->
+-- .brand <!-- Logo + title + date -->
+-- .theme-btn <!-- Dark mode toggle -->
</header>
<div class="container app-layout"> <!-- CSS Grid: sidebar + main -->
<aside class="sidebar"> <!-- Dashboard panel -->
+-- .circle-card <!-- SVG circular progress -->
+-- .stats-row <!-- 3x stat cards grid -->
+-- .chart-card (weekly) <!-- Bar chart canvas -->
+-- .chart-card (status) <!-- Doughnut chart canvas -->
</aside>
<main class="main-content"> <!-- Task management area -->
+-- .add-form <!-- Input + priority selector -->
+-- .toolbar <!-- Search + filters + clear -->
+-- .tasks-section <!-- Task list + empty state -->
</main>
</div>
<script src="chart.js (CDN)">
<script src="js/app.js"> <!-- Also registers service worker -->
</body>""",
title="DOM Tree Overview"
)
pdf.subsection("5.3 SVG Circular Progress Bar (HTML)")
pdf.body_text(
"The circular progress bar is built with pure SVG. Two <circle> elements share the same "
"center (cx=90, cy=90) and radius (r=75). The background circle uses a muted stroke, "
"while the foreground circle uses an SVG linearGradient and the stroke-dasharray/"
"stroke-dashoffset technique for animation."
)
pdf.code_block(
"""<svg class="circle-svg" viewBox="0 0 180 180">
<defs>
<linearGradient id="progress-gradient" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" stop-color="#6366f1"/> <!-- Indigo -->
<stop offset="100%" stop-color="#06b6d4"/> <!-- Cyan -->
</linearGradient>
</defs>
<circle class="circle-bg" cx="90" cy="90" r="75"/>
<circle class="circle-fg" cx="90" cy="90" r="75" id="circle-progress"/>
</svg>""",
title="SVG Markup"
)
pdf.subsection("5.4 Priority Selector Pattern")
pdf.body_text(
"The priority selector uses hidden <input type='radio'> elements inside <label> wrappers. "
"CSS uses the adjacent sibling selector (input:checked + .priority-tag) to style the "
"active state. This is a pure CSS solution requiring zero JavaScript for visual feedback."
)
pdf.subsection("5.5 Accessibility")
pdf.bullet("All interactive elements have aria-label attributes")
pdf.bullet("SVG icons are decorative (no alt text needed, labels on parent buttons)")
pdf.bullet("Form inputs have proper labels and autocomplete attributes")
pdf.bullet("Semantic HTML: <header>, <main>, <aside>, <section>, <nav> elements")
pdf.bullet("The theme toggle button has aria-label='Toggle theme'")
# ===================== 6. CSS ARCHITECTURE =====================
pdf.add_page()
pdf.section_title("6", "CSS Architecture (style.css)")
pdf.body_text(
"The stylesheet is 1,077 lines organized into clearly commented sections. It uses "
"CSS Custom Properties (variables) extensively for theming, and CSS Grid + Flexbox "
"for all layout needs."
)
pdf.subsection("6.1 Design Token System (CSS Custom Properties)")
pdf.body_text(
"All visual values are centralized in :root as CSS Custom Properties. "
"This enables instant theme switching by overriding variables in [data-theme='dark']."
)
pdf.code_block(
""":root {
/* Color Palette */
--primary: #6366f1; /* Indigo - brand color */
--primary-dark: #4f46e5; /* Hover state */
--primary-light: #818cf8; /* Focus rings */
--primary-subtle: #eef2ff; /* Backgrounds */
--accent: #06b6d4; /* Cyan - progress gradient end */
--success: #10b981; /* Green - completed state */
--warning: #f59e0b; /* Amber - pending/medium priority */
--danger: #ef4444; /* Red - delete/high priority */
/* Semantic Surface Colors */
--bg: #f1f5f9; /* Page background */
--surface: #ffffff; /* Card backgrounds */
--text: #0f172a; /* Primary text */
--text-secondary: #475569; /* Secondary text */
--text-muted: #94a3b8; /* Muted/disabled text */
--border: #e2e8f0; /* Border color */
/* Elevation (Shadow Scale) */
--shadow-sm through --shadow-lg
/* Spacing & Shape */
--radius-sm: 8px; --radius: 12px; --radius-lg: 16px;
/* Motion */
--transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
--transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
/* Layout Constants */
--header-height: 72px;
--sidebar-width: 340px;
}""",
title="Design Tokens (Light Theme)"
)
pdf.subsection("6.2 Dark Theme Override")
pdf.body_text(
"Dark mode overrides every surface, text, border, and shadow variable. "
"The subtle color variants use rgba() with low opacity for a natural dark-mode feel."
)
pdf.code_block(
"""[data-theme="dark"] {
--bg: #0f172a; /* Slate-900 */
--surface: #1e293b; /* Slate-800 */
--text: #f1f5f9; /* Slate-100 */
--text-secondary: #94a3b8; /* Slate-400 */
--border: #334155; /* Slate-700 */
--primary-subtle: rgba(99, 102, 241, 0.15); /* Translucent */
--success-subtle: rgba(16, 185, 129, 0.15);
/* ... shadows get heavier opacity ... */
}""",
title="Dark Theme Overrides"
)
pdf.subsection("6.3 Layout System")
pdf.subsubsection("Desktop Layout (> 1024px)")
pdf.code_block(
""".app-layout {
display: grid;
grid-template-columns: 340px 1fr; /* Fixed sidebar + fluid main */
gap: 28px;
align-items: start; /* Sidebar sticks to top */
}
.sidebar {
position: sticky;
top: calc(var(--header-height) + 28px); /* Below sticky header */
}""",
title="Desktop Grid"
)
pdf.subsubsection("Tablet Layout (768px - 1024px)")
pdf.code_block(
"""@media (max-width: 1024px) {
.app-layout { grid-template-columns: 1fr; } /* Single column */
.sidebar {
position: static; /* Not sticky */
display: grid;
grid-template-columns: 1fr 1fr; /* Charts side by side */
}
.circle-card, .stats-row { grid-column: 1/-1; } /* Full width */
}""",
title="Tablet Breakpoint"
)
pdf.subsubsection("Mobile Layout (< 768px)")
pdf.body_text(
"On mobile, everything stacks vertically. The add button becomes icon-only, "
"the toolbar stacks, delete buttons are always visible (no hover on touch), "
"and the circular progress bar shrinks to 150px."
)
pdf.subsection("6.4 Circular Progress Bar (CSS)")
pdf.code_block(
""".circle-svg {
width: 180px; height: 180px;
transform: rotate(-90deg); /* Start from 12 o'clock */
}
.circle-fg {
fill: none;
stroke: url(#progress-gradient); /* SVG gradient reference */
stroke-width: 8;
stroke-linecap: round; /* Rounded endpoints */
stroke-dasharray: 471.24; /* Circumference = 2 * PI * 75 */
stroke-dashoffset: 471.24; /* 100% hidden initially */
transition: stroke-dashoffset 1s cubic-bezier(0.4, 0, 0.2, 1);
}""",
title="SVG Circle Technique"
)
pdf.info_box(
"Math: circumference = 2 * PI * radius = 2 * 3.14159 * 75 = 471.24. "
"To show N% progress: stroke-dashoffset = 471.24 * (1 - N/100). "
"At 0%: offset = 471.24 (fully hidden). At 100%: offset = 0 (fully visible).",
color=pdf.ACCENT
)
# ===================== 7. JAVASCRIPT ARCHITECTURE =====================
pdf.add_page()
pdf.section_title("7", "JavaScript Architecture (app.js)")
pdf.body_text(
"The JavaScript layer is 512 lines of vanilla ES6+ code organized into 12 logical "
"sections. It manages application state, DOM rendering, chart integration, theme "
"switching, and all user interactions."
)
pdf.subsection("7.1 State Management")
pdf.code_block(
"""// Global state
let todos = []; // Array of todo objects (source of truth)
let weeklyChart = null; // Chart.js bar chart instance
let statusChart = null; // Chart.js doughnut chart instance
// DOM element cache (queried once at load time)
const el = {
addForm: $("#add-form"),
taskInput: $("#task-input"),
tasksList: $("#tasks-list"),
circleProgress: $("#circle-progress"),
// ... 14 more cached references
};""",
title="State & DOM Cache"
)
pdf.body_text(
"The 'todos' array is the single source of truth. The UI is always derived from it. "
"DOM references are cached in the 'el' object at load time to avoid repeated "
"querySelector calls during renders."
)
pdf.subsection("7.2 Todo Data Model")
pdf.code_block(
"""{
id: "m2abc1234xyz", // Unique ID (timestamp + random base36)
text: "Buy groceries", // Task description (user input, escaped)
completed: false, // Boolean completion state
priority: "medium", // "low" | "medium" | "high"
createdAt: "2026-02-08T...", // ISO 8601 creation timestamp
completedAt: null // ISO 8601 completion timestamp (or null)
}""",
title="Todo Object Schema"
)
pdf.body_text(
"The completedAt timestamp is critical for the weekly activity chart. When a task is "
"toggled complete, the current timestamp is stored. When uncompleted, it's set back to "
"null. This enables accurate historical tracking of completion activity."
)
pdf.subsection("7.3 CRUD Operations")
pdf.subsubsection("addTodo(text, priority)")
pdf.body_text(
"Creates a new todo object with a generated ID and current timestamps, prepends it "
"to the todos array (unshift for newest-first ordering), saves to localStorage, "
"and triggers a full re-render."
)
pdf.subsubsection("toggleTodo(id)")
pdf.body_text(
"Finds the todo by ID, flips the completed boolean, sets or clears the completedAt "
"timestamp, saves, and re-renders. The completedAt timestamp feeds the weekly chart."
)
pdf.subsubsection("deleteTodo(id)")
pdf.body_text(
"Filters the todo out of the array and saves. The re-render is handled by the "
"caller after the slide-out animation completes (via animationend event)."
)
pdf.subsubsection("clearCompleted()")
pdf.body_text(
"Adds the 'slide-out' CSS class to all completed task DOM elements, waits 350ms for "
"the animation, then bulk-removes completed todos from state and re-renders."
)
pdf.subsection("7.4 Rendering Pipeline")
pdf.code_block(
"""function render() {
renderTasks(); // 1. Rebuild task list from filtered state
updateStats(); // 2. Update stat cards + circle progress
updateCharts(); // 3. Push new data to Chart.js instances
}
function renderTasks() {
const filtered = getFilteredTodos(); // Apply search + filters
el.tasksList.innerHTML = ""; // Clear current DOM
filtered.forEach(todo => {
el.tasksList.appendChild(createTaskElement(todo));
});
el.emptyState.classList.toggle("visible", filtered.length === 0);
}
function updateStats() {
// Calculate totals
const total = todos.length;
const done = todos.filter(t => t.completed).length;
const percent = total ? Math.round((done / total) * 100) : 0;
// Update DOM text
el.statTotal.textContent = total;
el.statDone.textContent = done;
el.statPending.textContent = total - done;
// Update circular progress bar
const circumference = 2 * Math.PI * 75;
const offset = circumference * (1 - percent / 100);
el.circleProgress.style.strokeDashoffset = offset;
el.circlePercent.textContent = percent + "%";
}""",
title="Render Pipeline"
)
pdf.subsection("7.5 Filtering System")
pdf.code_block(
"""function getFilteredTodos() {
const search = el.searchInput.value.toLowerCase().trim();
const status = el.filterStatus.value; // "all"|"active"|"completed"
const priority = el.filterPriority.value; // "all"|"low"|"medium"|"high"
return todos.filter(todo => {
const matchSearch = !search || todo.text.toLowerCase().includes(search);
const matchStatus = status === "all" ||
(status === "active" && !todo.completed) ||
(status === "completed" && todo.completed);
const matchPriority = priority === "all" || todo.priority === priority;
return matchSearch && matchStatus && matchPriority;
});
}""",
title="Multi-criteria Filtering"
)
pdf.body_text(
"Filters compose cleanly: each criterion returns true if 'all' is selected, or checks "
"the specific match. The search input triggers renderTasks on every keystroke (input event) "
"for real-time feedback. The dropdown filters trigger on the change event."
)
pdf.subsection("7.6 Event Delegation")
pdf.body_text(
"Instead of attaching event listeners to every task button, a single listener on the "
"task list container uses event delegation with Element.closest() to determine what "
"was clicked. This is more performant and automatically handles dynamically added tasks."
)
pdf.code_block(
"""function handleTaskClick(e) {
const deleteBtn = e.target.closest(".task-delete");
const checkBtn = e.target.closest(".task-check");
const taskItem = e.target.closest(".task-item");
if (!taskItem) return;
if (deleteBtn) {
taskItem.classList.add("slide-out"); // Trigger CSS animation
taskItem.addEventListener("animationend", () => {
deleteTodo(taskItem.dataset.id); // Remove from state
render(); // Re-render
});
} else if (checkBtn) {
toggleTodo(taskItem.dataset.id); // Toggle + re-render
}
}
// Single listener for all tasks
el.tasksList.addEventListener("click", handleTaskClick);""",
title="Event Delegation Pattern"
)
# ===================== 8. DATA MODEL & STORAGE =====================
pdf.add_page()
pdf.section_title("8", "Data Model & Storage")
pdf.subsection("8.1 localStorage Schema")
pdf.code_block(
"""Key: "taskflow_todos"
Value: JSON array of todo objects
Example:
[
{
"id": "m2abc1234xyz",
"text": "Finish quarterly report",
"completed": true,
"priority": "high",
"createdAt": "2026-02-07T09:30:00.000Z",
"completedAt": "2026-02-08T14:22:00.000Z"
},
{
"id": "m2def5678abc",
"text": "Buy milk",
"completed": false,
"priority": "low",
"createdAt": "2026-02-08T08:00:00.000Z",
"completedAt": null
}
]
Key: "taskflow_theme"
Value: "light" or "dark" """,
title="localStorage Keys"
)
pdf.subsection("8.2 Legacy Data Migration")
pdf.body_text(
"The previous version of the app stored todos as a simple array of strings under the "
"key 'todos'. The loadTodos() function automatically detects and migrates this format:"
)
pdf.code_block(
"""function loadTodos() {
// 1. Try new format first
const data = localStorage.getItem(STORAGE_KEY);
if (data) return JSON.parse(data);
// 2. Check for legacy format
const legacy = localStorage.getItem("todos");
if (legacy) {
const items = JSON.parse(legacy);
const migrated = items.map(text => ({
id: generateId(),
text: typeof text === "string" ? text : String(text),
completed: false,
priority: "medium",
createdAt: new Date().toISOString(),
completedAt: null,
}));
saveTodos(migrated); // Save in new format
localStorage.removeItem("todos"); // Clean up legacy key
return migrated;
}
return []; // Fresh start
}""",
title="Migration Logic"
)
pdf.info_box(
"The migration is transparent to the user. On first load after upgrade, legacy tasks "
"appear with 'Medium' priority and today's date. The old 'todos' key is removed.",
color=pdf.SUCCESS
)
pdf.subsection("8.3 ID Generation")
pdf.code_block(
"""function generateId() {
return Date.now().toString(36) + Math.random().toString(36).substr(2, 9);
}
// Example output: "m2k7f3a1x" + "abc123def" = "m2k7f3a1xabc123def" """,
title="Unique ID Strategy"
)
pdf.body_text(
"IDs combine a base-36 timestamp with random characters, ensuring uniqueness even "
"if multiple tasks are created in the same millisecond."
)
# ===================== 9. CIRCULAR PROGRESS BAR =====================
pdf.add_page()
pdf.section_title("9", "Circular Progress Bar")
pdf.body_text(
"The circular progress bar is one of the most visually prominent features. It's built "
"entirely with SVG and CSS - no canvas, no library."
)
pdf.subsection("9.1 How It Works")
pdf.body_text("The technique uses three SVG/CSS properties working together:")
pdf.bullet("stroke-dasharray: Sets the total length of the dash pattern (= circumference)")
pdf.bullet("stroke-dashoffset: Controls how much of the stroke is hidden")
pdf.bullet("transform: rotate(-90deg): Rotates the circle so 0% starts at 12 o'clock")
pdf.ln(2)
pdf.body_text("The math is simple:")
pdf.code_block(
"""Circumference = 2 * PI * radius = 2 * 3.14159 * 75 = 471.24
For a given completion percentage:
offset = circumference * (1 - percent / 100)
Examples:
0% complete -> offset = 471.24 * (1 - 0) = 471.24 (circle hidden)
25% complete -> offset = 471.24 * (1 - 0.25) = 353.43
50% complete -> offset = 471.24 * (1 - 0.50) = 235.62
75% complete -> offset = 471.24 * (1 - 0.75) = 117.81
100% complete -> offset = 471.24 * (1 - 1.0) = 0 (full circle)""",
title="Offset Calculation"
)
pdf.subsection("9.2 Gradient Effect")
pdf.body_text(
"The stroke uses an SVG <linearGradient> that transitions from Indigo (#6366f1) "
"to Cyan (#06b6d4). This gradient is defined in the <defs> section of the SVG and "
"referenced via stroke: url(#progress-gradient) in CSS."
)
pdf.subsection("9.3 Animation")
pdf.body_text(
"The CSS transition property on stroke-dashoffset provides smooth animation whenever "
"the value changes. The 1-second cubic-bezier easing creates a satisfying deceleration "
"effect as the progress ring fills or empties."
)
# ===================== 10. CHART.JS INTEGRATION =====================
pdf.add_page()
pdf.section_title("10", "Chart.js Integration")
pdf.subsection("10.1 Weekly Activity Bar Chart")
pdf.body_text(
"The bar chart shows the number of tasks completed per day over the last 7 days. "
"Data is computed from the completedAt timestamps in the todos array."
)