# gbmatheus/schedule-service architecture

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

- Interactive diagram: https://gitdiagram.com/gbmatheus/schedule-service
- Repository: https://github.com/gbmatheus/schedule-service

## Overview

##### Project type and purpose
- This is a backend RESTful API for a “Medical Appointments” system. It exposes endpoints for doctors, patients, user authentication, and session management. It uses Node.js with Express, Sequelize ORM, JWT‐based authentication, and a relational database (e.g., PostgreSQL).

##### File structure
- Top-level artifacts:
- docker-compose.yaml & Procfile for containerization/deployment
- .env.example for environment variables
- package.json for dependencies & scripts
- src/config: holds database and auth configuration
- src/routes: defines HTTP routes by domain (doctor, patient, user, session)
- src/controllers: maps routes to actions
- src/services: business logic (CreateDoctorService, AuthenticationUserService, etc.)
- src/models & src/database (migrations): Sequelize models and DB setup
- src/middlewares: JWT verification middleware

##### Extract additional insights from README
- JWT for authentication/authorization
- Sequelize for DB migrations & ORM
- Typical MVC‐style layering (Routes → Controllers → Services → Models)

##### Main components
a. External Clients
- Web/Mobile clients or API consumers (e.g., front‐end apps, Postman)
b. API Layer (Node.js/Express)
- Entry point: server.js (Express app)
- Routes → Middlewares (verifyAuth) → Controllers → Services → ORM
c. Database
- PostgreSQL (via Sequelize)
- Migration scripts & connection pooling
d. Configuration / Environment
- JWT secret, DB connection strings (from .env)
e. Deployment & Infrastructure
- Docker container, docker‐compose orchestration or Heroku Procfile setup

##### Relationships & data flow
- Client sends HTTP request → Load Balancer (if present) → Dockerized Express server
- Express router matches route → verifyAuth middleware (if protected) → relevant Controller
- Controller invokes Service to implement business logic → Service interacts with Sequelize Models
- Sequelize communicates with the Database, returning data to the Service → Controller formats response → Express returns JSON to Client

##### Architectural patterns & design principles
- Layered architecture (Router → Controller → Service → Model)
- Separation of concerns:
- Authentication isolated in auth config & middleware
- Business logic in “services” dir
- Data access in “models” & “database”
- Configurable via environment variables for 12-factor compliance

##### Technologies & frameworks to annotate
- Node.js + Express (API server)
- Sequelize ORM + PostgreSQL (Data layer)
- JWT (Authentication)
- Docker / docker‐compose (Containerization)
- dotenv (.env management)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    Client["External Clients"]:::external

    %% Deployment
    subgraph "Deployment / Infrastructure"
        direction TB
        DockerCompose["docker-compose.yaml"]:::docs
        Procfile["Procfile"]:::docs
        Docker["Docker Container"]:::infra
    end

    %% Configuration
    subgraph "Configuration"
        direction TB
        Env[".env.example"]:::docs
        AuthConfig["auth.js"]:::config
        DBConfig["database.js"]:::config
    end

    %% API Server
    subgraph "API Server (Node.js/Express)" 
        direction TB
        Server["server.js"]:::api
        Router["Express Router<br/>(routes)"]:::api
        AuthMiddleware["verifyAuth.js"]:::auth
        subgraph "Controllers"
            direction TB
            DocCtrl["DoctorController.js"]:::api
            PatCtrl["PatientController.js"]:::api
            AuthCtrl["AuthController.js"]:::api
            UserCtrl["UserController.js"]:::api
        end
        subgraph "Services"
            direction TB
            CreateDocSvc["CreateDoctorService.js"]:::api
            CreatePatSvc["CreatePatientService.js"]:::api
            AuthUserSvc["AutheticationUserService.js"]:::api
            CreateUserSvc["CreateUserService.js"]:::api
        end
        subgraph "Models"
            direction TB
            DoctorModel["Doctor.js"]:::db
            PatientModel["Patient.js"]:::db
            UserModel["User.js"]:::db
        end
    end

    %% Database
    DB["PostgreSQL Database"]:::db

    %% Data Migrations
    subgraph "Migrations"
        direction TB
        Migration1["20201220015320-create-patients.js"]:::docs
        Migration2["20201220143033-create-doctor.js"]:::docs
    end

    %% Flows
    Client -->|HTTP Request| Docker
    Docker -->|Runs| Server
    Server -->|loads env| Env
    Server -->|uses config| AuthConfig
    Server -->|uses config| DBConfig
    Server --> Router
    Router -->|protected| AuthMiddleware
    AuthMiddleware --> Controllers
    Router -->|public| Controllers
    Controllers --> Services
    Services --> Models
    Models -->|SQL Queries| DB
    DBConfig --> DB
    Migration1 --> DB
    Migration2 --> DB

    %% Click Events
    click Server "https://github.com/gbmatheus/schedule-service/blob/master/src/server.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes/index.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes/doctor.routes.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes/patient.routes.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes/session.routes.js"
    click Router "https://github.com/gbmatheus/schedule-service/blob/master/src/routes/user.routes.js"
    click AuthMiddleware "https://github.com/gbmatheus/schedule-service/blob/master/src/middlewares/verifyAuth.js"
    click DocCtrl "https://github.com/gbmatheus/schedule-service/blob/master/src/controllers/DoctorController.js"
    click PatCtrl "https://github.com/gbmatheus/schedule-service/blob/master/src/controllers/PatientController.js"
    click AuthCtrl "https://github.com/gbmatheus/schedule-service/blob/master/src/controllers/User/AuthController.js"
    click UserCtrl "https://github.com/gbmatheus/schedule-service/blob/master/src/controllers/User/UserController.js"
    click CreateDocSvc "https://github.com/gbmatheus/schedule-service/blob/master/src/services/Doctor/CreateDoctorService.js"
    click CreatePatSvc "https://github.com/gbmatheus/schedule-service/blob/master/src/services/Patient/CreatePatientService.js"
    click AuthUserSvc "https://github.com/gbmatheus/schedule-service/blob/master/src/services/User/AutheticationUserService.js"
    click CreateUserSvc "https://github.com/gbmatheus/schedule-service/blob/master/src/services/User/CreateUserService.js"
    click DoctorModel "https://github.com/gbmatheus/schedule-service/blob/master/src/models/Doctor.js"
    click PatientModel "https://github.com/gbmatheus/schedule-service/blob/master/src/models/Patient.js"
    click UserModel "https://github.com/gbmatheus/schedule-service/blob/master/src/models/User.js"
    click DBConfig "https://github.com/gbmatheus/schedule-service/blob/master/src/config/database.js"
    click Migration1 "https://github.com/gbmatheus/schedule-service/blob/master/src/database/migrations/20201220015320-create-patients.js"
    click Migration2 "https://github.com/gbmatheus/schedule-service/blob/master/src/database/migrations/20201220143033-create-doctor.js"
    click AuthConfig "https://github.com/gbmatheus/schedule-service/blob/master/src/config/auth.js"
    click Env "https://github.com/gbmatheus/schedule-service/blob/master/.env.example"
    click DockerCompose "https://github.com/gbmatheus/schedule-service/blob/master/docker-compose.yaml"
    click Procfile "https://github.com/gbmatheus/schedule-service/tree/master/Procfile"
    click Migration1 "https://github.com/gbmatheus/schedule-service/blob/master/src/database/migrations/20201220015320-create-patients.js"
    click Migration2 "https://github.com/gbmatheus/schedule-service/blob/master/src/database/migrations/20201220143033-create-doctor.js"

    %% Styles
    classDef external fill:#cce5ff,stroke:#3399ff;
    classDef infra fill:#e6ffe6,stroke:#33cc33;
    classDef api fill:#e6f2ff,stroke:#3399ff;
    classDef auth fill:#fff0e6,stroke:#ff9933;
    classDef db fill:#ffffe6,stroke:#cccc00;
    classDef config fill:#f2e6ff,stroke:#9933cc;
    classDef docs fill:#f2f2f2,stroke:#999999;
```
