How waffensultan/ph-emergency-hotlines-api works
Project Overview and Purpose
• The project is a RESTful API designed to serve emergency hotline information for the Philippines. Clients (or a frontend application) make HTTP API calls to retrieve hotline details. The backend processes these requests and fetches the relevant JSON data organized by region, province, and city/municipality.
• It uses modular JSON files for efficient data retrieval, and there are utility scripts to automate the generation and updating of these source files.
Analyzing the File Structure (Main Components)
• Entry Point – src/server.ts: This is the main file that boots up the API server.
• Routing – src/routes/api_router.ts: This file defines the API endpoints (e.g., /api/{region}/{province}/{city_or_municipality}) and directs incoming requests.
• Controllers – src/controllers/api_handler.ts: The controller handles incoming API requests, performs any necessary logic, and prepares responses.
• Data Models – src/models/data: Contains hierarchical JSON data files structured by region, province, and cities/municipalities (for example, calabarzon > cavite > alfonso). There is also a central source.json at multiple levels.
• Utility Scripts – src/scripts: Contains scripts like generate-source-files.ts for splitting and updating the data files, ensuring scalability and faster data retrieval.
• Configuration – Package files (package.json, tsconfig.json, etc.) which set up the Node/TypeScript environment.
Main Components
a. Clients:
b. API Server:
• The Entry Point (server.ts)
• Router (api_router.ts) that directs HTTP requests.
• Controller (api_handler.ts) that processes requests and invokes the business logic.
c. Data Layer:
d. Utility Scripts:
Relationships and Data Flow
• Outgoing response travelling from Controller back to the Client.
Architectural Patterns and Design Principles
• Separation of Concerns: Different layers (routing, controllers, data models, and utility scripts) handle specific responsibilities.
• File-based Data Storage: Instead of a traditional database, the system uses a hierarchical file structure (by region, province, city) for storing data. This supports scalability by reducing response times.
• Modularity: The project is split into clear functional components (server, routes, controllers, data models, and scripts) making maintenance and future contributions (like adding new hotline fields) straightforward.
Relevant Technologies and Frameworks
• Node.js and TypeScript: Indicated by the package.json, tsconfig.json, and .ts file extensions.
• The project likely leverages a web framework (such as Express) for routing and request handling (even if indirectly inferred).
• JSON as the data format for emergency hotline information.