# janchundiaws/backendconsultorio architecture

> Architecture diagram of the GitHub repository janchundiaws/backendconsultorio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/janchundiaws/backendconsultorio
- Repository: https://github.com/janchundiaws/backendconsultorio

## Overview

##### Project type and purpose
- This is a full-stack backend service: a RESTful API built with Node.js and Express.js.
- It uses PostgreSQL as the primary data store and the pg library for database access.
- It exposes CRUD endpoints for users, patients, specialties, inventory, clinical histories, and general configuration.

##### File structure
- Top-level items:
– docker-compose.yml: orchestrates services (app, database).
– database/: SQL scripts for schema and initial data.
– src/: application source code.
– .env / .env.template: environment-specific configuration.
– HEALTH_CHECK.md, README.md: operational and documentation guidelines.
- Inside src/:
– config.js + swagger.js: application configuration and API docs.
– db.js: initializes pg client pool.
– routes/: maps HTTP endpoints to controller functions.
– controllers/: contains business-logic handlers per resource.
– middlewares/: auth and tenant resolution layers.
– helpers/: JWT utilities and token blacklisting.
– index.js: Express app bootstrap, middleware composition, route mounting.

##### README for additional insights
- Confirms: Node.js, Express.js, PostgreSQL stack.
- Outlines core endpoints and environment variables.
- Mentions development script (npm run dev) and linting.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Client["Client (Web/Mobile/Postman)"]:::external

    %% DevOps and Configuration
    dotEnv[".env / .env.template"]:::devops
    dockerCompose["Docker Compose"]:::devops
    healthGuide["HEALTH_CHECK.md"]:::devops
    readme["README.md"]:::devops
    eslintCfg["eslint.config.js"]:::devops

    %% Configuration and Startup
    config["Configuration Module"]:::api
    swagger["Swagger API Documentation"]:::api
    express["Express Server"]:::api

    %% Middleware Layer
    tenantMW["Tenant Resolution Middleware"]:::middleware
    authMW["Authentication Middleware"]:::middleware

    %% Routing Layer
    subgraph "Routing Layer"
        authRoutes["Auth Routes"]:::api
        userRoutes["User Routes"]:::api
        patientRoutes["Patient Routes"]:::api
        specialtyRoutes["Specialty Routes"]:::api
        inventoryRoutes["Inventory Routes"]:::api
        clinicalHistoryRoutes["Clinical History Routes"]:::api
        configRoutes["General Config Routes"]:::api
        healthRoutes["Health Check Route"]:::api
    end

    %% Controller Layer
    subgraph "Controller Layer"
        userCtrl["User Controller"]:::api
        patientCtrl["Patient Controller"]:::api
        specialtyCtrl["Specialty Controller"]:::api
        inventoryCtrl["Inventory Controller"]:::api
        clinicalHistoryCtrl["Clinical History Controller"]:::api
        configCtrl["Config Controller"]:::api
    end

    %% Helpers and Data Access
    dbClient["Database Client (pg Pool)"]:::data
    jwtUtil["JWT Utilities"]:::middleware
    tokenBlk["Token Blacklist Store"]:::data
    subgraph "Database Scripts"
        mainSchema["Main Schema & Seed"]:::data
        inventorySchema["Inventory Schema"]:::data
    end
    postgres["PostgreSQL Database"]:::data

    %% DevOps flows
    dotEnv --> config
    dockerCompose --> express
    dockerCompose --> postgres

    %% Startup & Docs
    express --> swagger
    express --> tenantMW
    tenantMW --> authMW

    %% Auth uses helpers
    authMW --> jwtUtil
    authMW --> tokenBlk

    %% Request Flow
    Client --> express
    authMW --> authRoutes
    authRoutes --> userCtrl
    authRoutes --> patientCtrl
    authRoutes --> specialtyCtrl
    authRoutes --> inventoryCtrl
    authRoutes --> clinicalHistoryCtrl
    authRoutes --> configCtrl
    authRoutes --> healthRoutes

    %% Controllers to DB
    userCtrl --> dbClient
    patientCtrl --> dbClient
    specialtyCtrl --> dbClient
    inventoryCtrl --> dbClient
    clinicalHistoryCtrl --> dbClient
    configCtrl --> dbClient

    dbClient --> postgres
    postgres --> dbClient

    %% Database Scripts reference
    mainSchema --> postgres
    inventorySchema --> postgres

    %% DevOps docs
    express --> readme
    express --> healthGuide
    express --> eslintCfg

    %% Click Events
    click express "https://github.com/janchundiaws/backendconsultorio/blob/master/src/index.js"
    click config "https://github.com/janchundiaws/backendconsultorio/blob/master/src/config.js"
    click swagger "https://github.com/janchundiaws/backendconsultorio/blob/master/src/swagger.js"
    click dbClient "https://github.com/janchundiaws/backendconsultorio/blob/master/src/db.js"
    click authRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/auth.routes.js"
    click userRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/users.routes.js"
    click patientRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/patients.routes.js"
    click specialtyRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/specialty.routes.js"
    click inventoryRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/inventory.routes.js"
    click clinicalHistoryRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/clinicalHistory.routes.js"
    click configRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/config.routes.js"
    click healthRoutes "https://github.com/janchundiaws/backendconsultorio/blob/master/src/routes/health.routes.js"
    click userCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/users.controller.js"
    click patientCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/patients.controller.js"
    click specialtyCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/specialty.controller.js"
    click inventoryCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/inventory.controller.js"
    click clinicalHistoryCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/clinicalHistory.controller.js"
    click configCtrl "https://github.com/janchundiaws/backendconsultorio/blob/master/src/controllers/config.controller.js"
    click tenantMW "https://github.com/janchundiaws/backendconsultorio/blob/master/src/middlewares/tenant.middleware.js"
    click authMW "https://github.com/janchundiaws/backendconsultorio/blob/master/src/middlewares/auth.middleware.js"
    click jwtUtil "https://github.com/janchundiaws/backendconsultorio/blob/master/src/helpers/jwt.js"
    click tokenBlk "https://github.com/janchundiaws/backendconsultorio/blob/master/src/helpers/tokenBlacklist.js"
    click mainSchema "https://github.com/janchundiaws/backendconsultorio/blob/master/database/db.sql"
    click inventorySchema "https://github.com/janchundiaws/backendconsultorio/blob/master/database/inventario_schema.sql"
    click dockerCompose "https://github.com/janchundiaws/backendconsultorio/blob/master/docker-compose.yml"
    click dotEnv "https://github.com/janchundiaws/backendconsultorio/blob/master/.env"
    click healthGuide "https://github.com/janchundiaws/backendconsultorio/blob/master/HEALTH_CHECK.md"
    click readme "https://github.com/janchundiaws/backendconsultorio/blob/master/README.md"
    click eslintCfg "https://github.com/janchundiaws/backendconsultorio/blob/master/eslint.config.js"

    %% Styles
    classDef api fill:#D0E8FF,stroke:#3399FF
    classDef middleware fill:#FFE0B2,stroke:#FF9800
    classDef data fill:#C8E6C9,stroke:#388E3C
    classDef external fill:#E0E0E0,stroke:#9E9E9E
    classDef devops fill:#F5F5F5,stroke:#757575
```
