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 default compressHTML: true).
  • Strict TypeScript contracts: Extending astro/tsconfigs/strict with 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 in src/scripts/.
  • Strict Content Security Policy (CSP): Zero inline <style> or <script> blocks are emitted in dist/; script-src and style-src require no 'unsafe-inline' or SHA-256 hashes, and scripts/check-csp.ts verifies exact meta CSP parity plus firebase.json and dist/_headers CSP 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:

  1. Public vs. local contracts: Cross-directory types (ArticleFrontmatter, PortfolioData, PageMetaProps, TimelineEntry, ContactItem, SiteEndpoints, ArticleArchivePage, Theme) live in src/core/types/, while module-specific interfaces (LoadedArticle, PageMetadata) stay inside their owning files.
  2. Acyclic layers & domain entry points: scripts/check-hygiene/boundaries.ts enforces one-way dependencies (core -> data/scripts -> components -> layouts -> pages) and zero cycles in src/core/ and src/data/, while domain entry points (src/core/{seo/head,seo/json-ld,seo/llms,seo/card,portfolio,resume,articles/rss}/index.ts and src/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:

  1. Source validation: src/core/types/portfolio/index.ts enforces schema structure on portfolio.ts, while the shared articleFrontmatterSchema in src/core/articles/frontmatter.ts is consumed by src/content.config.ts and scripts/lib/sitemap.ts, and src/core/articles/loader.ts normalizes each entry once at build time.
  2. Pure transformations: Helpers in src/core/portfolio/, src/core/resume/pdf-data.ts, src/core/articles/archive.ts, src/core/utils/text/markdown.ts, and src/core/utils/datetime/ build timeline entries, card grids, structured PDF payloads, excerpts, word counts, reading times (~200 wpm via formatReadTimeFromWords()), ISO-8601 timeRequired durations, and IST (Asia/Kolkata, UTC+05:30) datetimes.
  3. Canonical routing & pagination: src/core/constants/routes.ts defines every route (/, /resume, /projects, /articles, /contact), article reader URL (/articles/<slug>), and paginated archive URL (/articles/<page>). Both archive routes use buildArticleArchivePage(), numeric-only article slugs are rejected, and scripts/lib/sitemap.ts owns YAML parsing plus full frontmatter validation before parseArticleSitemapDates() resolves sitemap dates.
  4. Page assembly: Route templates in src/pages/ compose BaseLayout.astro, <Toolbar>, <PageSheet>, and domain components in src/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):

  1. tokens.css: Light and dark palettes (src/core/constants/theme.ts), spacing, typography scales, and print tokens (--print-bg, --print-surface).
  2. base.css & typography.css: Element resets, accessible focus rings, typography defaults, and link underlines.
  3. components/*.css: Reusable buttons, action rows, bullet lists, status dots, contact form controls, topic chips, eyebrow leads, endpoint rows, pagination, timelines, and media frames.
  4. layout/*.css: Page and section shells, sticky header chrome (--z-header) and mobile drawer layering (--z-overlay), Swiss grid containers (with CSS subgrid row alignment), and responsive breakpoints, paired with prefers-reduced-motion safeguards in global.css.
  5. prose.css & print.css: Article reader prose styles (prose.css) and unlayered A4 print styles (print.css) loaded via media="print" in Head.astro so 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.ts updates data-theme and polite live-region announcements, ProfileCard.astro renders an inline CSS-token SVG with PNG download, and navigation.ts + mobile-nav.ts coordinate active link state and accessible mobile menu focus management through pure helpers in src/core/utils/navigation.ts and src/core/utils/card-grid.ts.
  • Article prose & clipboard controls: clipboard.ts and main.ts delegate data-copy and data-print clicks, while article-prose.ts loads 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 in src/core/constants/ui.ts.
  • Localized timestamps & live status clock: relative-time.ts uses client-safe relative-time helpers from src/core/utils/datetime/ to format <time[datetime]> elements, clock.ts runs lazily on /contact, and photo-loader.ts coordinates portrait loading.
  • Contact draft persistence & telemetry: On /contact, main.ts loads contact/contact-form/index.ts when form[data-contact-form] exists, preserving drafts in sessionStorage across navigation, while analytics/{index,events,interactions,metrics,observers,vitals}.ts load on browser idle or first interaction, defer gtag.js injection when PUBLIC_GA_ID is configured, and emit privacy-safe analytics:action events 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:

  1. astro build compiles static pages and endpoints to dist/, including /resume.pdf via src/pages/resume.pdf.ts and buildResumePdfData() in src/core/resume/pdf-data.ts, while Cloudflare files are written only to dist/ and firebase.json is never mutated by a build.
  2. src/core/resume/index.ts renders dist/resume.pdf directly with PDFKit from that typed payload, guaranteeing selectable text, clickable links, embedded fonts, and a deterministic 2-page A4 layout synchronized with src/data/portfolio.ts.

On Firebase Hosting (firebase.json), responses carry strict security headers:

  • Transport & framing: Strict-Transport-Security, X-Frame-Options: DENY, and X-Content-Type-Options: nosniff.
  • Origin isolation & permissions: Cross-Origin-Opener-Policy: same-origin, Cross-Origin-Resource-Policy: same-origin, Referrer-Policy, and Permissions-Policy.
  • Strict CSP: No 'unsafe-inline', no inline <style> or <script> blocks, object-src 'none', frame-src 'none', style-src-attr 'none', and frame-ancestors 'none', verified by scripts/check-csp.ts against every HTML file in dist/ 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 by scripts/lib/cloudflare/patterns.ts) converts Firebase rules into dist/_headers with ! Header detach lines before narrower overrides, since Cloudflare accumulates every matching rule and joins duplicate values. The same dist/ output is mirrored to Cloudflare Pages at mirror.amarjyoti.dev, while status.amarjyoti.dev tracks uptime across both hosts. check:output verifies detach directives, _redirects parity, exact endpoint headers and RSS self links, security headers, shared cache constants, article og.png files, and that no article date exceeds SITE_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): Executes astro 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 and SKILL.md frontmatter, 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 _headers detach directives and _redirects parity, security headers, per-article og.png, built pre-paint theme-init script behavior, speakable selectors, 404.html, 301 redirects, security.txt, JSON-LD @id graph integrity, sitemap contracts against SITE_LASTMOD, anchor checks, asset budgets, and decoded 2-page PDF text and URIs via scripts/lib/pdf.ts), and scripts/check-csp.ts (zero-inline hashless CSP plus exact meta CSP parity).
  • Full CI gate (npm run verify): Adds format:check (Prettier), npm test (Vitest unit and client tests in tests/unit/), verify:fast, and npm run test:e2e (Playwright E2E suites in tests/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.