API Overview
Relevant source files
The following files were used as context for generating this wiki page:
The CyberPath application utilizes a set of server-side generated JSON API endpoints, built with Astro, to provide data for its frontend components. These endpoints serve information about cybersecurity certifications, which are managed as a content collection within the project. The primary purpose of this API is to feed data to dynamic, client-side components like the searchable certification database, enabling fast filtering and searching without requiring a traditional backend server or database.
The API provides both the raw certification data and pre-computed search indexes using Fuse.js. This architecture optimizes performance by offloading the indexing process to build time and delivering a ready-to-use index to the client. The endpoints are structured to serve either the complete dataset or a subset filtered by a specific career path.
Data Source and Schema
The single source of truth for all certification data is the Astro content collection named certifications. The schema for this collection is defined using zod and dictates the structure and data types for each certification entry.
Sources: src/content.config.ts:4-21
Certification Schema
The following diagram illustrates the schema for the certifications collection.
Sources: src/content.config.ts:8-19
Career Paths
The career_paths field in the schema is an array of strings constrained by a predefined list of valid career paths. This list is maintained in a central file to ensure consistency across the application.
Sources: src/lib/career-paths.ts:18-30, src/content.config.ts:16
API Endpoints
The application exposes several JSON endpoints to deliver certification data and search indexes. These are implemented as Astro API routes.
| Method | Endpoint | Description |
|---|---|---|
GET | /database/data.json | Returns a JSON array of all non-draft certification metadata. |
GET | /database/data-index.json | Returns a pre-computed Fuse.js search index for all certifications. |
GET|/career-paths/{path}/data.json| Returns a JSON array of certifications filtered by the specified career path (e.g.,penetration-tester). |
|GET|/career-paths/{path}/data-index.json| Returns a pre-computed Fuse.js search index for certifications within a specific career path. |
|GET|/robots.txt| Generates therobots.txtfile for search engine crawlers, including a sitemap link. |
Sources: src/pages/database/data.json.ts:28-30, src/pages/database/data-index.json.ts:10-16, src/pages/career-paths/[path]/data.json.ts:40-44, src/pages/career-paths/[path]/data-index.json.ts:15-22, src/pages/robots.txt.ts:11-14
Data Processing and Flow
The API endpoints retrieve data from the certifications content collection, process it, and then serialize it as a JSON response.
This diagram shows the general flow of data from the source files to the client.
getCertificationMetadata
This core function is responsible for fetching and transforming the certification data.
- It calls Astro's
getCollection("certifications")to retrieve all entries. - It filters out any entries where
data.draftistrue. - An optional filter function can be passed to further narrow down the results, as seen in the career path-specific endpoints.
- It maps over the remaining entries to transform the data into the final
CertificationMetadataformat. This includes:- Omitting the
draftproperty. - Extracting the image source URL (
image.src). - Deriving the
providername from the file path. - Adding a
slugbased on the collection entry's ID.
- Omitting the
Sources: src/pages/database/data.json.ts:8-26
Career Path Endpoints
The dynamic endpoints under /career-paths/[path]/ provide data filtered for a specific career path.
- Static Path Generation: The
getStaticPathsfunction generates all possible URL paths at build time by converting theCareerPathsListinto kebab-case format (e.g., "Penetration Tester" becomespenetration-tester). - Data Filtering: The
GEThandler uses alookup_tableto map the URL parameter (e.g.,penetration-tester) back to its full name ("Penetration Tester"). It then callsgetCertificationMetadatawith a filter predicate that checks if the certification'scareer_pathsarray includes the requested path.
Sources: src/pages/career-paths/[path]/data.json.ts:11-25, src/pages/career-paths/[path]/data.json.ts:40-44
Search and Indexing
To enable fast client-side searching, the API provides pre-computed search indexes generated by Fuse.js.
Index Generation
The /data-index.json endpoints use the Fuse.createIndex method. This function takes the list of keys to be indexed and the full dataset. It produces a compact index structure that can be loaded by the Fuse.js client library, avoiding the need for the client to build the index from raw data on every page load.
Sources: src/pages/database/data-index.json.ts:11-15, src/pages/career-paths/[path]/data-index.json.ts:16-21
Client-Side Consumption
The ReactiveDatatable component demonstrates how these endpoints are consumed.
The following sequence diagram illustrates the interaction between the client and the API.
Conclusion
The API layer of CyberPath is a lean and effective system for serving content-driven data to the frontend. By leveraging Astro's API routes and content collections, it provides a performant, statically-generated set of JSON endpoints. The pre-computation of search indexes via Fuse.js is a key feature that enhances the user experience by enabling fast, client-side search capabilities without the overhead of a traditional backend infrastructure.