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.mjs 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 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: <ClientRouter fallback="none" /> with opt-in hover prefetching (prefetchAll: false) coordinates lightweight, event-delegated client modules in src/scripts/.
  • Strict Content Security Policy (CSP): Every inline <style> block emitted in dist/ must match its SHA-256 hash inside firebase.json style-src, checked automatically after every build.

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/        CI pipeline workflow (workflows/pipeline.yml) and grouped Dependabot config (dependabot.yml)
src/
  assets/       Author portrait (profile-photo.png), subsetted Inter/JetBrains Mono fonts, Markdown articles (articles/)
  constants/    Canonical routes, endpoints, DOM selectors, site config, HTTP headers, SEO, theme, UI tokens/labels (ui.ts), and Wikipedia entities (wikipedia-entities.ts)
  types/        Public readonly TypeScript contracts (article.ts, portfolio.ts, portfolio/, theme.ts, view.ts, pdfkit.d.ts)
  data/         Canonical static profile data (portfolio.ts + portfolio/{profile,skills,career,pages,resume-sections}.ts)
  utils/        Pure view-model builders & loaders (portfolio/), article helpers (articles/), IST datetimes (datetime/), SEO (seo/), JSON-LD (json-ld/), LLM context (llms/), RSS (rss/), media & font helpers (media/), endpoint generators (endpoints/), social cards (card/), resume PDF payload (resume/), routing helpers (route-paths.ts), Firebase config parsing (cloudflare-files.ts)
  layouts/      Root document shell (BaseLayout.astro)
  components/   Domain-grouped Astro components (common, layout, portfolio, resume, projects, articles, contact)
  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, theme-toggle.ts, navigation.ts, mobile-nav.ts, clipboard.ts, article-prose.ts, contact-form/{index,draft}.ts, photo-loader.ts, relative-time.ts, clock.ts, analytics/{index,events,interactions,vitals}.ts)
  styles/       Layered plain CSS via global.css (tokens.css, base.css, components/*.css, layout/*.css), layered prose.css, and media="print" print.css (print/{resume,article,page}.css)
scripts/        Validation tools (lib/{cli,dist,firebase,html,pdf}.mjs, check-hygiene.mjs + hygiene/{comments,docs,naming}.mjs, check-output/{index,assets,html,json-ld,pdf,sitemap}.mjs, check-csp.mjs)
tests/          Test configs (tests/config/{vitest,playwright}.config.ts), Vitest unit suites (tests/unit/{scripts,utils}/), 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/types/, while module-specific interfaces (LoadedArticle, PageMetadata) stay inside their owning files.
  2. Domain entry points over deep imports: Server utilities (src/utils/{seo,json-ld,llms,card,articles,resume,portfolio,datetime,rss}/index.ts) and client feature folders (src/scripts/{contact-form,analytics}/index.ts) expose stable entry points while keeping internal helpers inside their respective subdirectories.

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/types/portfolio.ts enforces schema structure on portfolio.ts, and src/utils/articles/loader.ts validates Markdown frontmatter at build time.
  2. Pure transformations: Helpers in src/utils/portfolio/, src/utils/resume/pdf-data.ts, src/utils/articles/index.ts, src/utils/markdown.ts, and src/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/constants/routes.ts defines every route (/, /resume, /projects, /articles, /contact), article reader URL (/articles/<slug>), and paginated archive URL (/articles/<page>). Numeric-only article slugs are rejected so pagination paths never collide.
  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/constants/theme.ts), spacing, typography scales, and print tokens (--print-bg, --print-surface).
  2. base.css: Element resets, accessible focus rings, typography defaults, and link underlines.
  3. components/*.css: Reusable buttons, action rows, 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 loaded through Astro’s local fontProviders API in astro.config.mjs, avoiding external font requests at runtime.

To apply the persisted or OS-preferred theme before first paint without triggering a CSP inline-script violation, src/pages/theme-init.js.ts prerenders /theme-init.js from src/utils/endpoints/theme-init.ts and loads it synchronously in <head>.

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 <ClientRouter /> active link state, progress feedback (#nav-progress-bar), and accessible mobile menu focus management.
  • 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.
  • Localized timestamps & live status clock: relative-time.ts uses client-safe relative-time helpers from src/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-form/index.ts when form[data-contact-form] exists, preserving drafts in sessionStorage across navigation, while analytics/{index,events,interactions,vitals}.ts load on browser idle or first interaction, defer gtag.js injection, and emit privacy-safe analytics:action events and Web Vitals (LCP, CLS, INP) with query/fragment strings stripped.

Machine-Readable Endpoints

src/constants/routes.ts (ENDPOINT_PATHS) exposes static machine-readable outputs alongside human routes:

Endpoint Generator Purpose
/llms.txt & /llms-full.txt src/utils/llms/index.ts Concise Markdown index and detailed knowledge base for LLMs
/rss.xml & /articles/rss.xml src/utils/rss/index.ts Chronologically sorted RSS 2.0 feeds with xmlns:media article covers
/sitemap-index.xml @astrojs/sitemap + src/utils/endpoints/sitemap.ts XML sitemap honoring article updated/datetime frontmatter
/robots.txt & /.well-known/security.txt src/utils/endpoints/robots.ts, src/utils/endpoints/security.ts Crawler directives and RFC 9116 security contact metadata
/card.svg & /card.png src/utils/card/index.ts → src/utils/card/{data,render}.ts Build-time 1200×630 profile Open Graph card
/photo.webp src/pages/photo.webp.ts → src/utils/media/profile-photo.ts Sharp-optimized author portrait
/favicon.*, /icon-*.png & /site.webmanifest src/pages/[icon].ts, src/pages/site.webmanifest.ts → src/utils/favicon.ts, src/utils/endpoints/manifest.ts Brand favicons and web app manifest

Every indexable page also embeds a Schema.org JSON-LD @graph (src/utils/json-ld/index.ts) and speakable metadata (src/utils/seo/index.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.

Build-Time PDF Resume & Security Gates

Running npm run build executes two synchronized steps:

  1. astro build compiles static pages and endpoints to dist/, including /resume.pdf via src/pages/resume.pdf.ts and buildResumePdfData() in src/utils/resume/index.ts.
  2. src/utils/resume/render.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', object-src 'none', frame-src 'none', style-src-attr 'none', frame-ancestors 'none', and SHA-256 hashed <style> blocks verified by scripts/check-csp.mjs against every HTML file in dist/ and tested live in Playwright (tests/e2e/csp.spec.ts).

Automated Verification Pipeline

Quality checks run in GitHub Actions (.github/workflows/pipeline.yml) 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. Verification concurrency is scoped per job by PR or ref (cancelling superseded runs except on main), ~/.cache/ms-playwright is cached by exact lockfile hash so cache hits install only OS dependencies and skip browser archive downloads, and verified pushes to dev serialize fast-forward promotion of the exact verified commit SHA to main:

  • 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.mjs (endpoints, RSS namespaces, firebase.json headers, 404.html, security.txt, JSON-LD @id graph integrity, sitemap contracts, anchor checks, asset budgets, and decoded 2-page PDF text and URIs via scripts/lib/pdf.mjs), and scripts/check-csp.mjs.
  • 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 live CSP injection and dual-theme WCAG AA accessibility checks).

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.