The Architecture Behind amarjyoti.dev
I built amarjyoti.dev to serve three audiences from a single static codebase: human visitors reading a portfolio and technical notes, search engines and AI systems parsing structured metadata, and automated quality gates verifying every build before deployment.
Rather than adopting a single-page application framework, Tailwind, or an external CMS, the codebase runs on static Astro, strict TypeScript, and layered plain CSS, separating data, transformations, presentation, styling, and client enhancements cleanly.
Core Architectural Constraints
Every engineering decision in amarjyoti.dev stems from explicit boundaries configured in astro.config.ts and tsconfig.json:
- Static-first output: Astro compiles every HTML route and machine-readable endpoint into
dist/at build time (output: 'static',trailingSlash: 'never',build.format: 'directory', and Astro’s defaultcompressHTML: true). - Strict TypeScript contracts: Extending
astro/tsconfigs/strictwith strict indexing and explicit module syntax catches data drift and missing fields at compile time. - Plain CSS with zero runtime styling frameworks: Styles live in layered CSS files (
inlineStylesheets: 'never') backed by custom-property tokens rather than utility classes or CSS-in-JS. - Selective vanilla TypeScript enhancements: Astro
<ClientRouter />view transitions with opt-in hover prefetching (prefetchAll: false) pair with lightweight, event-delegated client modules insrc/scripts/. - Strict Content Security Policy (CSP): Zero inline
<style>or<script>blocks are emitted indist/;script-srcandstyle-srcrequire no'unsafe-inline'or SHA-256 hashes, andscripts/check-csp.tsverifies exact meta CSP parity plusfirebase.jsonanddist/_headersCSP text without mutating that file.
Directory Layout & Module Separation
Keeping data, transformations, presentation, styling, and verification in separate folders prevents copy edits from entangling layout code or SEO generators:
.agents/ Task-routing guide (GUIDE.md), domain guides, and progressive skills (skills/)
.devcontainer/ Reproducible Node 24 + Playwright Chromium headless-shell container config (devcontainer.json)
.github/ Composite setup action (actions/setup-project/), CI workflows (workflows/pipeline.yml, workflows/deploy.yml), and grouped Dependabot config (dependabot.yml)
src/
assets/ Author portrait (profile-photo.png), subsetted Inter/JetBrains Mono fonts, Markdown articles (articles/)
components/ Domain-grouped Astro components (ui/, layout/, portfolio/, articles/, contact/)
data/ Canonical static profile data & loaders (portfolio.ts, profile.ts, skills.ts, career.ts, pages/*.ts, loader.ts)
core/ Pure TypeScript: types/, constants/, utils/, articles/, media/, portfolio/, resume/, seo/
layouts/ Root document shell (BaseLayout.astro, ArticleArchiveLayout.astro)
pages/ File-based routes & static endpoints (pages, RSS feeds, llms.txt, llms-full.txt, .well-known/security.txt)
scripts/ Vanilla TypeScript modules (main.ts, dom.ts, lifecycle.ts, clipboard.ts, navigation.ts, mobile-nav.ts, theme-toggle.ts, photo-loader.ts, seo-inspector.ts, analytics/, articles/, contact/)
styles/ Layered plain CSS via global.css (fonts.css, tokens.css, base.css, typography.css, components/*.css, layout/*.css), layered prose.css, and media="print" print.css (print/{resume,article,page,components}.css)
scripts/ Validation & integration tools (lib/{build-config,cli,csp,csp-sync,dist,firebase,html,media-assets,pdf,pdf-cmap,sitemap}.ts, lib/cloudflare/, integrations.ts, check-hygiene/{index,boundaries,comments,astro-comments,docs,naming}.ts, check-output/{index,assets,endpoints,headers,html,json-ld,pdf,security,sitemap,theme-init}.ts, check-csp.ts)
tests/ Test configs (tests/config/{vitest,playwright}.config.ts), Vitest unit suites (tests/unit/{core,scripts,verifiers}/), and Playwright browser E2E suites (tests/e2e/{a11y,articles,contact,csp,layout,navigation,theme}.spec.ts)
Two rules keep imports clean across the repository:
- Public vs. local contracts: Cross-directory types (
ArticleFrontmatter,PortfolioData,PageMetaProps,TimelineEntry,ContactItem,SiteEndpoints,ArticleArchivePage,Theme) live insrc/core/types/, while module-specific interfaces (LoadedArticle,PageMetadata) stay inside their owning files. - Acyclic layers & domain entry points:
scripts/check-hygiene/boundaries.tsenforces one-way dependencies (core->data/scripts->components->layouts->pages) and zero cycles insrc/core/andsrc/data/, while domain entry points (src/core/{seo/head,seo/json-ld,seo/llms,seo/card,portfolio,resume,articles/rss}/index.tsandsrc/scripts/contact/contact-form/index.ts) expose stable interfaces.
Single-Source Data Flow
All structured portfolio and resume data originate in src/data/portfolio.ts, while long-form technical writing lives in src/assets/articles/*.md. From those two inputs, the build pipeline derives every output:
- Source validation:
src/core/types/portfolio/index.tsenforces schema structure onportfolio.ts, while the sharedarticleFrontmatterSchemainsrc/core/articles/frontmatter.tsis consumed bysrc/content.config.tsandscripts/lib/sitemap.ts, andsrc/core/articles/loader.tsnormalizes each entry once at build time. - Pure transformations: Helpers in
src/core/portfolio/,src/core/resume/pdf-data.ts,src/core/articles/archive.ts,src/core/utils/text/markdown.ts, andsrc/core/utils/datetime/build timeline entries, card grids, structured PDF payloads, excerpts, word counts, reading times (~200 wpm viaformatReadTimeFromWords()), ISO-8601timeRequireddurations, and IST (Asia/Kolkata, UTC+05:30) datetimes. - Canonical routing & pagination:
src/core/constants/routes.tsdefines every route (/,/resume,/projects,/articles,/contact), article reader URL (/articles/<slug>), and paginated archive URL (/articles/<page>). Both archive routes usebuildArticleArchivePage(), numeric-only article slugs are rejected, andscripts/lib/sitemap.tsowns YAML parsing plus full frontmatter validation beforeparseArticleSitemapDates()resolves sitemap dates. - Page assembly: Route templates in
src/pages/composeBaseLayout.astro,<Toolbar>,<PageSheet>, and domain components insrc/components/using derived view models without hardcoding profile or editorial copy inside UI markup.
Swiss Grid CSS Layers & Pre-Paint Theme
Visual styling follows explicit cascade layers in src/styles/global.css (@layer tokens, base, components, layout):
tokens.css: Light and dark palettes (src/core/constants/theme.ts), spacing, typography scales, and print tokens (--print-bg,--print-surface).base.css&typography.css: Element resets, accessible focus rings, typography defaults, and link underlines.components/*.css: Reusable buttons, action rows, bullet lists, status dots, contact form controls, topic chips, eyebrow leads, endpoint rows, pagination, timelines, and media frames.layout/*.css: Page and section shells, sticky header chrome (--z-header) and mobile drawer layering (--z-overlay), Swiss grid containers (with CSSsubgridrow alignment), and responsive breakpoints, paired withprefers-reduced-motionsafeguards inglobal.css.prose.css&print.css: Article reader prose styles (prose.css) and unlayered A4 print styles (print.css) loaded viamedia="print"inHead.astroso print layout rules stay out of screen CSS.
Typography relies on locally bundled Inter (--font-sans) and JetBrains Mono (--font-mono) WOFF2 subsets declared in src/styles/fonts.css and preloaded in Head.astro, avoiding external font requests and inline <style> tags at runtime.
To apply the persisted or OS-preferred theme before first paint without an inline script or an unsafe CSP policy, Head.astro loads the static /theme-init.js endpoint (src/pages/theme-init.js.ts, generated from buildThemeInitScript() in src/core/utils/theme.ts), while theme-toggle.ts calls the same helpers after hydration so stored, OS, and default precedence cannot drift between the two phases.
Progressive Client Scripting
Because every page renders as static HTML first, src/scripts/main.ts focuses strictly on progressive enhancement across Astro View Transitions:
- Theme & navigation lifecycle:
theme-toggle.tsupdatesdata-themeand polite live-region announcements,ProfileCard.astrorenders an inline CSS-token SVG with PNG download, andnavigation.ts+mobile-nav.tscoordinate active link state and accessible mobile menu focus management through pure helpers insrc/core/utils/navigation.tsandsrc/core/utils/card-grid.ts. - Article prose & clipboard controls:
clipboard.tsandmain.tsdelegatedata-copyanddata-printclicks, whilearticle-prose.tsloads lazily when code blocks, tables, or section headings exist to add copy buttons, keyboard-scrollable table wrappers, and#heading deep-link anchors. Both modules build announcements and accessible labels from the shared helpers insrc/core/constants/ui.ts. - Localized timestamps & live status clock:
relative-time.tsuses client-safe relative-time helpers fromsrc/core/utils/datetime/to format<time[datetime]>elements,clock.tsruns lazily on/contact, andphoto-loader.tscoordinates portrait loading. - Contact draft persistence & telemetry: On
/contact,main.tsloadscontact/contact-form/index.tswhenform[data-contact-form]exists, preserving drafts insessionStorageacross navigation, whileanalytics/{index,events,interactions,metrics,observers,vitals}.tsload on browser idle or first interaction, defergtag.jsinjection whenPUBLIC_GA_IDis configured, and emit privacy-safeanalytics:actionevents and Web Vitals (LCP,CLS,INP) with query/fragment strings stripped.
Machine-Readable Endpoints
src/core/constants/routes.ts (ENDPOINT_PATHS) exposes static machine-readable outputs alongside human routes:
| Endpoint | Generator | Purpose |
|---|---|---|
/llms.txt & /llms-full.txt |
src/core/seo/llms/index.ts |
Concise Markdown index and detailed knowledge base for LLMs |
/rss.xml & /articles/rss.xml |
src/core/articles/rss/index.ts |
Chronologically sorted RSS 2.0 feeds with xmlns:media article covers |
/sitemap-index.xml |
@astrojs/sitemap + scripts/lib/sitemap.ts |
XML sitemap honoring article updated/datetime frontmatter |
/robots.txt & /.well-known/security.txt |
src/core/seo/metadata.ts |
Crawler directives and RFC 9116 security contact metadata |
/card.svg & /card.png |
src/core/seo/card/index.ts -> src/core/seo/card/{data,render,article-render}.ts |
Build-time 1200x630 profile Open Graph card |
/articles/<slug>/og.png |
src/pages/articles/[slug]/og.png.ts |
Per-article Open Graph PNG verified by check:output |
/photo.webp |
src/pages/photo.webp.ts -> src/core/media/profile-photo.ts |
Sharp-optimized author portrait |
/favicon.* & /site.webmanifest |
src/pages/[icon].ts, src/pages/site.webmanifest.ts -> src/core/media/favicon.ts, src/core/seo/metadata.ts |
Brand favicons and web app manifest |
Every indexable page also embeds a Schema.org JSON-LD @graph (src/core/seo/json-ld/index.ts) and speakable metadata (src/core/constants/seo.ts), emitting full Person entities (hasCredential, worksFor, and alumniOf) on / and /resume, ItemList collections on /projects and /articles, wordCount and timeRequired on TechArticles, and lightweight @id stubs on secondary routes. Reader pages use ARTICLE_READER_SPEAKABLE_SELECTORS instead of archive selectors, and check:output verifies every emitted selector against built ids and classes.
Build-Time PDF Resume & Security Gates
Running npm run build executes two synchronized steps after astro.config.ts loads all build inputs through loadBuildConfig() in scripts/lib/build-config.ts:
astro buildcompiles static pages and endpoints todist/, including/resume.pdfviasrc/pages/resume.pdf.tsandbuildResumePdfData()insrc/core/resume/pdf-data.ts, while Cloudflare files are written only todist/andfirebase.jsonis never mutated by a build.src/core/resume/index.tsrendersdist/resume.pdfdirectly with PDFKit from that typed payload, guaranteeing selectable text, clickable links, embedded fonts, and a deterministic 2-page A4 layout synchronized withsrc/data/portfolio.ts.
On Firebase Hosting (firebase.json), responses carry strict security headers:
- Transport & framing:
Strict-Transport-Security,X-Frame-Options: DENY, andX-Content-Type-Options: nosniff. - Origin isolation & permissions:
Cross-Origin-Opener-Policy: same-origin,Cross-Origin-Resource-Policy: same-origin,Referrer-Policy, andPermissions-Policy. - Strict CSP: No
'unsafe-inline', no inline<style>or<script>blocks,object-src 'none',frame-src 'none',style-src-attr 'none', andframe-ancestors 'none', verified byscripts/check-csp.tsagainst every HTML file indist/under a hashless policy and tested against Playwright’s locally served build (tests/e2e/csp.spec.ts). - Cloudflare mirror & header parity:
scripts/lib/cloudflare/index.ts(backed byscripts/lib/cloudflare/patterns.ts) converts Firebase rules intodist/_headerswith! Headerdetach lines before narrower overrides, since Cloudflare accumulates every matching rule and joins duplicate values. The samedist/output is mirrored to Cloudflare Pages atmirror.amarjyoti.dev, whilestatus.amarjyoti.devtracks uptime across both hosts.check:outputverifies detach directives,_redirectsparity, exact endpoint headers and RSS self links, security headers, shared cache constants, articleog.pngfiles, and that no article date exceedsSITE_LASTMOD.
Automated Verification Pipeline
Quality checks run in GitHub Actions (.github/workflows/pipeline.yml on dev) inside the same Node.js 24 (.node-version) and Playwright Chromium headless-shell baseline defined in .devcontainer/devcontainer.json, alongside weekly grouped updates targeting dev via .github/dependabot.yml. Both workflows call the shared .github/actions/setup-project/ composite action. Verification concurrency is scoped per job by PR or ref, ~/.cache/ms-playwright is cached by @playwright/test version so cache hits install only OS dependencies and skip browser archive downloads, verified pushes to dev serialize fast-forward promotion of the exact verified commit SHA to main and dispatch .github/workflows/deploy.yml with commit_sha, which deploy checks against origin/main before building the detached verified SHA, and push or workflow_dispatch runs on main verify secrets.PUBLIC_GA_ID, run the full quality gate, and deploy dist/ to the live Firebase Hosting channel without cancelling an in-flight production deploy:
- Fast pre-finish gate (
npm run verify:fast): Executesastro check,npm run check:hygiene(Knip for zero unused files, dependencies, exports, or types, plus zero code comments, zero em dashes, zero named view transitions, zero repo-name prose in articles, valid doc links/paths andSKILL.mdfrontmatter, zero empty dirs, consistent file naming),npm run build,scripts/check-output/index.ts(exact endpoint bodies, RSS XML and self links, endpoint headers, Cloudflare_headersdetach directives and_redirectsparity, security headers, per-articleog.png, built pre-paint theme-init script behavior, speakable selectors,404.html, 301 redirects,security.txt, JSON-LD@idgraph integrity, sitemap contracts againstSITE_LASTMOD, anchor checks, asset budgets, and decoded 2-page PDF text and URIs viascripts/lib/pdf.ts), andscripts/check-csp.ts(zero-inline hashless CSP plus exact meta CSP parity). - Full CI gate (
npm run verify): Addsformat:check(Prettier),npm test(Vitest unit and client tests intests/unit/),verify:fast, andnpm run test:e2e(Playwright E2E suites intests/e2e/*.spec.ts, including CSP header injection, exact meta CSP parity, and dual-theme WCAG AA accessibility checks against the locally served build).
This is a living architecture document. Whenever routes, endpoints, build scripts, security headers, or module boundaries change on amarjyoti.dev, this article and its updated timestamp are updated alongside the codebase.