# juan-var-camp/consultafacil-api architecture

> Architecture diagram of the GitHub repository juan-var-camp/consultafacil-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/juan-var-camp/consultafacil-api
- Repository: https://github.com/juan-var-camp/consultafacil-api

## Overview

ConsultaFácil is an Express API for clinic appointment scheduling and administration. The main workflow is: a patient authenticates, checks a clinic’s availability, and books a time; clinic staff manage schedules and appointment status, while users and clinics are administered through separate endpoints. Appointment changes trigger email notifications, and a scheduled job sends reminders for upcoming appointments. Source excerpts establish the main route, scheduling, persistence and email calls; the README is empty, so no additional documented capabilities can be assessed.

Main entry points: [`index.js`](https://github.com/juan-var-camp/consultafacil-api/blob/main/index.js) (Express server), [`routes/citas.js`](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/citas.js) (Appointment management), [`lib/prisma.js`](https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/prisma.js) (Application database), [`routes/consultorios.js`](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/consultorios.js) (Clinic management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API routes"]
  node_authroutes["Authentication<br/>[auth.js]"]
  node_users["User administration<br/>[usuarios.js]"]
  node_clinics["Clinic management<br/>[consultorios.js]"]
  node_appointments["Appointment management<br/>[citas.js]"]
  node_authmw["Token and role checks<br/>[auth.js]"]
end

subgraph group_domain["Scheduling domain"]
  node_schedule["Schedule rules<br/>[horarios.js]"]
end

subgraph group_infra["Persistence and messaging"]
  node_database[("Application database<br/>[prisma.js]")]
  node_templates["Email templates<br/>[plantillas.js]"]
  node_mailer["SMTP mailer<br/>[correo.js]"]
end

subgraph group_background["Background jobs"]
  node_reminders["Appointment reminders<br/>[recordatorios.js]"]
end

node_client(("API client"))
node_server["Express server<br/>[index.js]"]
node_smtp["SMTP service"]

node_client -->|"sends requests"| node_server
node_server -->|"mounts /api/auth"| node_authroutes
node_server -->|"mounts /api/usuarios"| node_users
node_server -->|"mounts /api/consultorios"| node_clinics
node_server -->|"mounts /api/citas"| node_appointments
node_server -->|"checks mail"| node_mailer
node_server -->|"starts scheduler"| node_reminders
node_authroutes -->|"reads and writes users"| node_database
node_users -->|"manages users"| node_database
node_clinics -->|"manages clinics and hours"| node_database
node_clinics -->|"generates availability"| node_schedule
node_appointments -->|"reads and writes appointments"| node_database
node_appointments -->|"validates appointment time"| node_schedule
node_appointments -->|"checks access"| node_authmw
node_authroutes -->|"authenticates profile route"| node_authmw
node_users -->|"checks access"| node_authmw
node_clinics -->|"checks access"| node_authmw
node_appointments -->|"formats notifications"| node_templates
node_appointments -->|"sends notifications"| node_mailer
node_reminders -->|"finds and updates reminders"| node_database
node_reminders -->|"formats reminders"| node_templates
node_reminders -->|"sends reminders"| node_mailer
node_mailer -->|"sends mail"| node_smtp
node_schedule -->|"reads clinic hours"| node_database

click node_server "https://github.com/juan-var-camp/consultafacil-api/blob/main/index.js"
click node_authroutes "https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/auth.js"
click node_users "https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/usuarios.js"
click node_clinics "https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/consultorios.js"
click node_appointments "https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/citas.js"
click node_authmw "https://github.com/juan-var-camp/consultafacil-api/blob/main/middleware/auth.js"
click node_schedule "https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/horarios.js"
click node_database "https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/prisma.js"
click node_templates "https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/plantillas.js"
click node_mailer "https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/correo.js"
click node_reminders "https://github.com/juan-var-camp/consultafacil-api/blob/main/jobs/recordatorios.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_authroutes,node_users,node_clinics,node_appointments,node_authmw,node_client toneBlue
class node_schedule toneAmber
class node_database,node_templates,node_mailer,node_server toneMint
class node_reminders toneRose
class node_smtp toneIndigo
```

## Components

### API routes

- [Authentication](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/auth.js): `routes/auth.js`
- [User administration](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/usuarios.js): `routes/usuarios.js`
- [Clinic management](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/consultorios.js): `routes/consultorios.js`
- [Appointment management](https://github.com/juan-var-camp/consultafacil-api/blob/main/routes/citas.js): `routes/citas.js`
- [Token and role checks](https://github.com/juan-var-camp/consultafacil-api/blob/main/middleware/auth.js): `middleware/auth.js`

### Scheduling domain

- [Schedule rules](https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/horarios.js): `lib/horarios.js`

### Persistence and messaging

- [Application database](https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/prisma.js): `lib/prisma.js`
- [Email templates](https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/plantillas.js): `lib/plantillas.js`
- [SMTP mailer](https://github.com/juan-var-camp/consultafacil-api/blob/main/lib/correo.js): `lib/correo.js`

### Background jobs

- [Appointment reminders](https://github.com/juan-var-camp/consultafacil-api/blob/main/jobs/recordatorios.js): `jobs/recordatorios.js`

### Other components

- **API client**
- [Express server](https://github.com/juan-var-camp/consultafacil-api/blob/main/index.js): `index.js`
- **SMTP service**

## Connections

- API client → Express server: sends requests (evidence: `index.js`)
- Express server → Authentication: mounts /api/auth (evidence: `index.js`)
- Express server → User administration: mounts /api/usuarios (evidence: `index.js`)
- Express server → Clinic management: mounts /api/consultorios (evidence: `index.js`)
- Express server → Appointment management: mounts /api/citas (evidence: `index.js`)
- Express server → SMTP mailer: checks mail (evidence: `index.js`)
- Express server → Appointment reminders: starts scheduler (evidence: `index.js`)
- Authentication → Application database: reads and writes users (evidence: `routes/auth.js`)
- User administration → Application database: manages users (evidence: `routes/usuarios.js`)
- Clinic management → Application database: manages clinics and hours (evidence: `routes/consultorios.js`)
- Clinic management → Schedule rules: generates availability (evidence: `routes/consultorios.js`)
- Appointment management → Application database: reads and writes appointments (evidence: `routes/citas.js`)
- Appointment management → Schedule rules: validates appointment time (evidence: `routes/citas.js`)
- Appointment management → Token and role checks: checks access (evidence: `routes/citas.js`)
- Authentication → Token and role checks: authenticates profile route (evidence: `routes/auth.js`)
- User administration → Token and role checks: checks access (evidence: `routes/usuarios.js`)
- Clinic management → Token and role checks: checks access (evidence: `routes/consultorios.js`)
- Appointment management → Email templates: formats notifications (evidence: `routes/citas.js`)
- Appointment management → SMTP mailer: sends notifications (evidence: `routes/citas.js`)
- Appointment reminders → Application database: finds and updates reminders (evidence: `jobs/recordatorios.js`)
- Appointment reminders → Email templates: formats reminders (evidence: `jobs/recordatorios.js`)
- Appointment reminders → SMTP mailer: sends reminders (evidence: `jobs/recordatorios.js`)
- SMTP mailer → SMTP service: sends mail (evidence: `lib/correo.js`)
- Schedule rules → Application database: reads clinic hours (evidence: `lib/horarios.js`)
