How bit1creative/mevn-covid19-backend works
Project Overview and Key Purpose
• The project is a MEVN (MongoDB, Express, Vue, Node.js) stack application.
• Its primary purpose is to provide a backend service for a website that displays Covid-19 statistics. The frontend (built in Vue) is maintained in a separate repository.
• It interacts with an external COVID-19 API (https://api.covid19api.com) and uses MongoDB as its persistent datastore, as indicated by the provided environment variables in the README.
Main Components
a. Frontend (Client):
• Represented by the "client" directory that points to a separate Vue project repository.
• Although not included in the current file tree, it communicates with the backend via REST API endpoints.
b. Backend Server:
• Found in the “server” directory, which contains the main application server logic.
• The server entry point is “server/index.js”, establishing the Express server.
• A component for static file serving – the “server/public” folder contains the deployed static assets (HTML, CSS, JS). This likely supports client-side resources possibly for fallback or local testing.
c. Database Layer:
• Located in “server/database”. The “connection.js” file indicates management of the MongoDB connection.
• Use the provided environment variables (MONGO_URL, MONGO_DB_USER, MONGO_DB_PASSWORD) to show how the system authenticates and connects to the database.
d. API Endpoints:
• The “server/routes/api” directory holds API routes such as “covid19data.js” and “ip.js”.
• These endpoints likely handle incoming requests from the frontend and act as a bridge between client queries and data retrieval (either fetching from MongoDB or directly consuming the external API).
e. Scheduler/Updater:
• The “server/scheduler” directory includes “updateData.js”, which is the component or service that periodically updates Covid-19 data.
• This service likely fetches data from the external COVID-19 API and updates the MongoDB database.
Relationships, Interactions, and Data Flow
• The frontend (Vue client) sends HTTP requests to the backend API endpoints to retrieve or update Covid-19 statistics.
• The backend (Express server) receives these requests, performs necessary operations (such as querying MongoDB or calling external APIs), and responds with data.
• The scheduler runs periodically (or via cron jobs) to fetch the latest data from the external COVID-19 API and update the database.
• The database serves both the immediate API responses and the data maintained by the scheduler, ensuring that the latest Covid-19 stats are displayed to the end-users.
Architectural Patterns and Design Principles
• The project separates concerns by clearly distinguishing between the stateless API endpoints, scheduled data processing, and static file serving.
• The routing structure hints at a modular design using Express routing.
• The separation between backend and frontend (even though they’re part of the same overall MEVN stack) is clearly maintained, emphasizing an API-first approach.
• The presence of a scheduler indicates a background job or worker pattern for periodic data updates.