# andresvillamil/api-centro-medico-taller architecture

> Architecture diagram of the GitHub repository andresvillamil/api-centro-medico-taller, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andresvillamil/api-centro-medico-taller
- Repository: https://github.com/andresvillamil/api-centro-medico-taller

## Overview

##### 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).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("REST Client/Postman"):::client
    App("API Server (Express)"):::server
    Middleware("Middleware: Nodemon, Dotenv, Cors"):::middleware

    subgraph "Routes"
        P_R("Patient Routes"):::route
        D_R("Doctor Routes"):::route
        A_R("Appointment Routes"):::route
    end

    subgraph "Controllers"
        P_C("Patient Controller"):::controller
        D_C("Doctor Controller"):::controller
        A_C("Appointment Controller"):::controller
    end

    subgraph "Models"
        P_M("Patient Model"):::model
        D_M("Doctor Model"):::model
        A_M("Appointment Model"):::model
    end

    DB("MySQL Database"):::database
    Swagger("Swagger Documentation"):::documentation

    Client -->|"sendsRequest"| App
    App -->|"initializes"| Middleware
    App -->|"delegatesTo"| P_R
    App -->|"delegatesTo"| D_R
    App -->|"delegatesTo"| A_R

    P_R -->|"calls"| P_C
    D_R -->|"calls"| D_C
    A_R -->|"calls"| A_C

    P_C -->|"uses"| P_M
    D_C -->|"uses"| D_M
    A_C -->|"uses"| A_M

    P_M -->|"queries"| DB
    D_M -->|"queries"| DB
    A_M -->|"queries"| DB

    App -->|"exposesDocs"| Swagger

    click App "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/app.ts"
    click P_R "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/routes/pacientes.routes.ts"
    click D_R "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/routes/doctores.routes.ts"
    click A_R "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/routes/citas.routes.ts"
    click P_C "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/controllers/pacientes.controller.ts"
    click D_C "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/controllers/doctores.controller.ts"
    click A_C "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/controllers/citas.controller.ts"
    click P_M "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/models/pacientes.model.ts"
    click D_M "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/models/doctores.model.ts"
    click A_M "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/models/citas.model.ts"
    click DB "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/DB/config.ts"
    click Swagger "https://github.com/andresvillamil/api-centro-medico-taller/blob/main/src/swagger.json"

    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef server fill:#bbf,stroke:#333,stroke-width:2px;
    classDef middleware fill:#cff,stroke:#333,stroke-width:2px;
    classDef route fill:#fcf,stroke:#333,stroke-width:2px;
    classDef controller fill:#cfc,stroke:#333,stroke-width:2px;
    classDef model fill:#fff,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef database fill:#fdd,stroke:#333,stroke-width:2px,stroke-dasharray: 2 2;
    classDef documentation fill:#ffd,stroke:#333,stroke-width:2px;
```
