How andresvillamil/api-centro-medico-taller works
Main Components
• API Server (Node.js/Express) – This is the core of your application that receives client requests.
• Controllers – Located in the “src/controllers” directory, these handle the business logic for each domain (patients, doctors, appointments).
• Models – Found in “src/models”, these define the data structures (citas, doctores, pacientes) and interface with the database.
• Routes – Under “src/routes”, these map HTTP endpoints (URLs) to their corresponding controller actions.
• Database Access & Configuration – In “src/DB/config.ts”, your database connection details and perhaps initial Sequelize setup are stored.
• API Documentation – The “src/swagger.json” and the documented images and endpoints in the README indicate Swagger is used for API documentation.
• Additional Components, such as Nodemon, Dotenv, and Cors, which are part of your project’s middleware stack and deployment configuration.
Relationships and Interactions
• Clients (e.g., Postman or any REST client) make HTTP requests to your API hosted at the specified URL.
• API Server: Incoming requests are processed by the Express server. The requests hit specific Route modules (e.g., citas.routes.ts, doctores.routes.ts, pacientes.routes.ts).
• Each Route forwards the request to the matching Controller (e.g., citas.controller.ts, doctores.controller.ts, pacientes.controller.ts) which contains the logic.
• Controllers interact with Models (e.g., citas.model.ts, doctores.model.ts, pacientes.model.ts) that use Sequelize for database operations.
• The DB configuration (in src/DB/config.ts) handles establishing and managing the MySQL connection.
• Swagger: Acts as external documentation, exposing the API structure and endpoints.
Architectural Patterns and Design Principles
• The project follows an MVC-like pattern where controllers provide the logic, models encapsulate data operations, and routes act as the entry points.
• Separation of concerns is maintained by clearly dividing routes, controllers, and models.
• The use of external configuration (through a .env file) and middleware (e.g., Cors, Dotenv) demonstrates good practices for environment management and security.
• Emphasis on RESTful design principles since each entity (Patient, Doctor, Appointment) has full CRUD operations.
Relevant Technologies and Frameworks
• Node.js and Express for server and routing.
• MySQL as the database with Sequelize ORM.
• Swagger for API documentation.
• Nodemon for live development.
• Dotenv for managing configuration via environment variables.
• Cors for handling cross-origin resource sharing.
Elements
• Use clear labels to denote each component (API Server, Routes, Controllers, Models, DB, and Documentation).