How vercel/og-image works
Project Type and Purpose
• The project is oriented toward dynamic OG image generation for social cards. It is a serverless application built primarily for Vercel deployments. Although the README warns that the repo is outdated (only working with Node.js 14), its architectural distinction still provides valuable insight.
• The README hints that newer projects should use @vercel/og, but for this legacy repo, it shows a structure characteristic of a service layer (API) that dynamically produces images.
File Structure
• Two main directories are clearly visible:
• The “api” directory: Contains the core logic for the image generation. Inside, apart from an "index.ts" (likely the entry point for the API requests), you have an "_lib" folder that organizes internal modules (chromium integration, options configuration, parsing, sanitization, templating, and type definitions). This indicates a clear separation of concerns within the backend.
• The “web” directory: Contains at least one file (archive.ts) suggesting a frontend route or additional web-based functionality.
• Additional directories/files:
• “public”: Contains static assets used by the front-end component (e.g., archive.html, style.css, robots.txt).
• Configuration files (package.json, tsconfig.json files in “api” and “web”, vercel.json, .yarnrc) provide hints about development and deployment processes.
• GitHub and contribution tools indicate open-source collaboration.
Key System Components
• API Component: Core service handling OG image generation:
• Entry point: api/index.ts
• Supporting libraries/modules: Located in api/_lib (such as template, parser, sanitizer, chromium integration).
• Assets: Fonts in api/_fonts (e.g., Inter-License.txt and Vera-License.txt), implicating the usage of specific typography in image generation.
• Web Component:
• Likely handling additional routes or administrative views (web/archive.ts) that integrate with the API.
• Public/Static Assets:
• Serve static HTML, CSS, and other files as required.
• External Services/Platforms:
• Vercel is used as the deployment platform (as indicated by vercel.json, .vercelignore, and the README mentioning Vercel support).
Relationships and Architectural Patterns
• The API server acts as the backend service that accepts requests, processes them using a set of modular libraries within the “api/_lib” directory, and produces an OG image as output.
• The web component likely interacts with or augments the API, offering archive or auxiliary functionality.
• Dependency and data flow:
• Incoming HTTP requests → routed to the API endpoint (api/index.ts) → internally use modules (parser, templating, etc.) for processing → font assets for image rendering → response returned.
• This design shows a clear separation of concerns, a modular file structure (for reusability and clarity), and a typical serverless design pattern when deployed on Vercel.