# javierbalcazarcruz/sistemaveterinario architecture

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

- Interactive diagram: https://gitdiagram.com/javierbalcazarcruz/sistemaveterinario
- Repository: https://github.com/javierbalcazarcruz/sistemaveterinario

## Overview

##### File Structure Analysis
- Top‑level:
- README.md
- backend/
- backend/:
- config/ (database configuration)
- controllers/ (request handlers for Pacientes, Veterinarios)
- helpers/ (ID and JWT generation)
- middleware/ (authentication)
- routes/ (Express routers mapping URLs to controllers)
- index.js (entry point, Express setup)
- .env, package.json, package-lock.json
- Pattern: Monolithic, layered architecture (Routes → Controllers → Helpers/Services → DB).

##### README Insights
- Core features (multi‑role auth, CRUD for pets/owners/appointments, notifications).
- Tech stack: Node.js, Express, MySQL, JWT, Bcrypt.

a. Main Components
1. Clients (Web UI or Mobile App)
2. API Gateway / Load Balancer (optional)
3. Express Backend
- Routes Layer
- Controllers Layer
- Helpers/Services Layer
- Auth Middleware
4. MySQL Database
5. External Services (e.g., Email/SMS gateway for notifications)
b. Relationships & Interactions
- Client → HTTP(S) → API Gateway (if used) → Express Routes
- Routes → Controllers → Helpers generate IDs, issue JWTs, hash passwords
- Controllers execute queries via config/db.js to MySQL
- Auth Middleware intercepts protected routes, verifies JWT
- Notification service invoked by Controllers/Helpers for reminders
c. Architectural Patterns
- Layered (routing, controller, service/helper, persistence)
- Token‑based authentication (JWT)
- Separation of concerns: config, middleware, controllers, routes
d. Technologies & Frameworks
- Node.js & Express for HTTP API
- MySQL 8.0+ (db.js config, connection pooling)
- JWT (generarJWT.js) for stateless auth
- Bcrypt for password hashing
- dotenv (.env) for environment config

##### Detailed Elements
- Component names matching folder/file names (e.g., “pacienteRoutes.js → Paciente Routes”).
- Middleware “authMiddleware” as a filtering step before Controllers.
- Helpers “generarJWT.js” and “generarId.js” under a “Utility” subcomponent.
- Database connection object from config/db.js.
- Environment variables loaded from .env.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% UI Layer
    Client["Web Browser / Mobile Client"]:::ui

    %% API Gateway
    APIGateway["API Gateway / Load Balancer"]:::gateway

    %% Express Backend Entry Point
    ExpressApp["Express Application\n(entry: index.js)"]:::server
    click ExpressApp "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/index.js"

    %% Routes Layer
    subgraph "Routes Layer"
        direction TB
        PacienteRoutes["Paciente Routes\n(pacienteRoutes.js)"]:::routes
        VeterinarioRoutes["Veterinario Routes\n(veterinarioRoutes.js)"]:::routes
        click PacienteRoutes "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/routes/pacienteRoutes.js"
        click VeterinarioRoutes "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/routes/veterinarioRoutes.js"
    end

    %% Middleware Layer
    AuthMiddleware["Authentication Middleware\n(authMiddleware.js)"]:::middleware
    click AuthMiddleware "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/middleware/authMiddleware.js"

    %% Controllers Layer
    subgraph "Controllers Layer"
        direction TB
        PacienteController["Paciente Controller\n(pacienteController.js)"]:::controllers
        VeterinarioController["Veterinario Controller\n(veterinarioController.js)"]:::controllers
        click PacienteController "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/controllers/pacienteController.js"
        click VeterinarioController "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/controllers/veterinarioController.js"
    end

    %% Helpers/Services Layer
    subgraph "Helpers / Utility Layer"
        direction TB
        IDUtil["ID Generation Utility\n(generarId.js)"]:::helpers
        JWTUtil["JWT Generation Utility\n(generarJWT.js)"]:::helpers
        click IDUtil "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/helpers/generarId.js"
        click JWTUtil "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/helpers/generarJWT.js"
    end

    %% Database Configuration
    DBConfig["MySQL Connection\n(config/db.js)"]:::database
    click DBConfig "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/config/db.js"

    %% Environment Config
    EnvConfig["Environment Variables\n(.env)"]:::config
    click EnvConfig "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/.env"

    %% Dependency Management
    PackageJson["Project Manifest\n(package.json)"]:::config
    click PackageJson "https://github.com/javierbalcazarcruz/sistemaveterinario/blob/main/backend/package.json"

    %% External Services
    NotificationService["Notification Service\n(Email/SMS)"]:::external

    %% Flow Connections
    Client -->|"HTTPS Request"| APIGateway
    APIGateway --> ExpressApp

    ExpressApp --> PacienteRoutes
    ExpressApp --> VeterinarioRoutes

    PacienteRoutes -->|"auth required"| AuthMiddleware
    VeterinarioRoutes -->|"auth required"| AuthMiddleware

    AuthMiddleware --> PacienteController
    AuthMiddleware --> VeterinarioController

    PacienteController -->|"uses"| IDUtil
    PacienteController -->|"uses"| JWTUtil
    VeterinarioController -->|"uses"| IDUtil
    VeterinarioController -->|"uses"| JWTUtil

    PacienteController -->|"SQL Query"| DBConfig
    VeterinarioController -->|"SQL Query"| DBConfig

    PacienteController --> NotificationService
    VeterinarioController --> NotificationService

    ExpressApp --> EnvConfig
    ExpressApp --> PackageJson

    %% Styling
    classDef ui fill:#E0F7FA,stroke:#006064,color:#004D40
    classDef gateway fill:#CFD8DC,stroke:#37474F,color:#263238
    classDef server fill:#C8E6C9,stroke:#2E7D32,color:#1B5E20
    classDef routes fill:#AED581,stroke:#558B2F,color:#33691E
    classDef middleware fill:#FFF59D,stroke:#F9A825,color:#F57F17
    classDef controllers fill:#A5D6A7,stroke:#388E3C,color:#1B5E20
    classDef helpers fill:#DCEDC8,stroke:#558B2F,color:#33691E
    classDef database fill:#FFE0B2,stroke:#EF6C00,color:#E65100
    classDef config fill:#E1BEE7,stroke:#8E24AA,color:#6A1B9A
    classDef external fill:#E1BEE7,stroke:#6A1B9A,color:#4A148C
```
