Endpoint: /database
Relevant source files
The following files were used as context for generating this wiki page:
The /database endpoint and its associated API routes are central to the CyberPath application, providing the data foundation for the public cybersecurity certification database. These endpoints are built using Astro and serve statically generated JSON files containing all certification metadata and a pre-computed search index. This architecture ensures fast data retrieval for the frontend, which is consumed by a reactive data table to provide users with a searchable and paginated view of the certifications.
The system is designed for performance by offloading the search index generation to the build process. The frontend client fetches the complete dataset and the search index, enabling fast, client-side searching without additional server requests. This approach is also used for career-path-specific pages, which filter the data accordingly.
API Endpoints
The /database path serves as a base for two key data endpoints that power the certification listing and search functionality.
GET /database/data.json
This endpoint returns a JSON array containing the complete metadata for every certification in the database. The data is sourced from the Astro content collection named certifications.
The following diagram illustrates the data flow for generating data.json.
The getCertificationMetadata function retrieves all entries from the certifications collection, filters out any marked as draft, and maps them to the CertificationMetadata structure. A similar process is used for career-path-specific pages, which apply an additional filter based on the career_paths array in the certification's frontmatter.
Sources: src/pages/database/data.json.ts:10-14, src/pages/career-paths/[path]/data.json.ts:41-43
GET /database/data-index.json
To enable efficient client-side searching, this endpoint provides a pre-computed search index generated by Fuse.js. Instead of building the index in the browser, the frontend can load this static file directly.
The process involves:
- Fetching the full list of certification metadata, identical to the
data.jsonendpoint. - Using
Fuse.createIndex()to build the index based on the keys and weights defined infuse.config.ts. - Serializing the index to a JSON object and serving it.
Sources: src/pages/database/data-index.json.ts:8-14, src/pages/database/fuse.config.ts
Data Schema & Source
The source of truth for all certification data is a collection of Markdown (.md) and MDX (.mdx) files located in src/content/certifications/. The schema for the frontmatter of these files is defined in src/content.config.ts using Zod.
Sources: src/content.config.ts:6-7
Certification Schema
The following table details the fields defined for the certifications collection.
| Field | Type | Description | Required |
|---|---|---|---|
title | string | The full title of the certification. | Yes |
acronym | string | The acronym for the certification. | Yes |
last_updated_at | date | The date the certification information was last updated. | Yes |
image | image() | An optimized image for the certification. | Yes |
reference | string | A URL to the official certification page. | Yes |
aliases | array(string) | Optional array of alternative names or acronyms. | No |
draft | boolean | If true, the certification is excluded from the build. Defaults to false. | No |
career_paths | array(enum) | An array of associated career paths from CareerPathsList. | Yes |
price | string | The price of the certification. | Yes |
currency | string | The currency for the price. | Yes |
Sources: src/content.config.ts:8-20
CertificationMetadata Type
When the data is processed by the API endpoints, it is transformed into the CertificationMetadata object, which is then used by the frontend.
| Field | Type | Description |
|---|---|---|
image | string | Path to the certification image. |
provider | string | The organization providing the certification. |
title | string | The title of the certification. |
acronym | string | The acronym for the certification. |
last_updated_at | Date | The date of the last update. |
reference | string | A URL to the official certification page. |
aliases | string[] | Optional alternative names. |
career_paths | string[] | Associated career paths. |
price | string | The price of the certification. |
currency | string | The currency for the price. |
slug | string | The URL-friendly slug for the certification page. |
Sources: src/types/certification-metadata.ts:1-14
Frontend Consumption
The ReactiveDatatable component, a React component used within an Astro page, is the primary consumer of the /database endpoints.
On initial load, the component's useEffect hook triggers two parallel fetch requests to get both the full dataset (/data.json) and the pre-computed Fuse.js index (/data-index.json).
The following sequence diagram shows the client-side data loading and search process.
Once the data and index are loaded, Fuse.js is instantiated. All subsequent search operations are performed entirely on the client by calling all_data.search(query), which is extremely fast. The component manages pagination and displays the relevant slice of the (potentially filtered) data.
Sources: src/components/astro/database/reactive-datatable.tsx:156-170, src/components/astro/database/reactive-datatable.tsx:231-235
Search Configuration
The search behavior is controlled by src/pages/database/fuse.config.ts. This file exports a FuseConfig object that specifies which fields to index and their relative importance (weight). Higher weights mean matches in that field contribute more to the result's score.
| Key | Weight |
|---|---|
title | 0.7 |
acronym | 0.6 |
aliases | 0.5 |
provider | 0.4 |
career_paths | 0.3 |
Sources: src/pages/database/fuse.config.ts:4-23
This configuration ensures that searches prioritize matches in the certification's title and acronym over its provider or associated career paths.
Summary
The /database endpoints form a robust and performant data delivery system for the CertDb project. By leveraging Astro's static site generation for content collections and pre-building a Fuse.js search index, the application provides a fast and responsive user experience for browsing and searching a large set of cybersecurity certifications. The clear separation of data sourcing, API generation, and frontend consumption creates a maintainable and scalable architecture.