# lgaxd/pathmed-api-java architecture

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

- Interactive diagram: https://gitdiagram.com/lgaxd/pathmed-api-java
- Repository: https://github.com/lgaxd/pathmed-api-java

## Overview

##### Project Type and Purpose
- This is a standalone RESTful backend API written in Java 17 for managing medical appointments and patient records in the PathMed system. It exposes HTTP endpoints, applies business logic, persists data in an Oracle Database, and uses GSON for JSON processing.

##### File Structure Analysis
- Top-level directories:
- src/br/com/pathmed/controller – HTTP request handlers (API layer)
- src/br/com/pathmed/service    – Business logic layer
- src/br/com/pathmed/dao        – Data access layer (DAO)
- src/br/com/pathmed/model      – Domain/data models
- src/br/com/pathmed/util       – Utilities (DB connection, JSON config)
- lib/                          – External JAR dependencies (GSON, OracleJDBC)
- bin/, out/                    – Compiled class files
- PathmedAPI/                   – API documentation scripts
- Configuration/build:
- DatabaseConnection.java holds the JDBC URL/credentials
- Main.java starts the native Java HTTP server (ApiServer)

##### README Insights
- Confirms Java 17, Oracle DB, GSON, native HTTP server
- Describes core features: authentication, patient management, consultations, specialties, professionals
- Lists all REST endpoints and DB tables
- Specifies project architecture overview

##### Key Components
a. API Server Layer
- ApiServer (HTTP listener)
- Controllers (AuthController, PacienteController, ConsultaController, etc.)
b. Service Layer
- AuthService, PacienteService, ConsultaService, DisponibilidadeService, EspecialidadeService, ProfissionalService
c. Data Access Layer
- DAOs (AuthDAO, PacienteDAO, ConsultaDAO, DisponibilidadeDAO, EspecialidadeDAO, ProfissionalDAO)
d. Persistence
- Oracle Database (tables: Pacientes, Consultas, Especialidades, Profissionais, Disponibilidade)
- JDBC Driver (ojdbc17.jar)
e. Utilities
- DatabaseConnection
- GsonConfig
f. External Dependencies
- GSON library for JSON serialization/deserialization

##### Relationships and Data Flow
1. Client (e.g., frontend app or API consumer) sends HTTP request →
2. ApiServer routes it to the appropriate Controller →
3. Controller validates and transforms input, calls Service →
4. Service enforces business rules, calls DAO →
5. DAO executes SQL via DatabaseConnection → Oracle DB → returns data →
6. Service processes results → Controller serializes response with GSON →
7. ApiServer returns HTTP response to client

##### Architectural Patterns & Principles
- Layered (n-tier) Architecture: clear separation of concerns (API, business logic, persistence)
- MVC-like flow (Controllers as “C”, Services+Models as “M”, though no view)
- Dependency inversion via utility classes (DatabaseConnection, GsonConfig)
- Single responsibility in each package

##### Technologies and Frameworks
- Java 17 (language/runtime)
- Native Java HTTP server (com.sun.net.httpserver)
- OracleJDBC driver for DB connectivity
- GSON for JSON handling
- Directory structure follows package naming conventions

##### Essential Elements to Capture
- All Controllers with their main endpoints
- Service classes and the business operations they perform
- DAO classes and the tables they access
- DatabaseConnection as the single source of DB connectivity
- GSONConfig for JSON serialization
- External libraries (GSON, OracleJDBC)

## Diagram (Mermaid)

```mermaid
graph TB
    Client["Client\n(API Consumer)"]

    subgraph "API Layer"
        direction TB
        Main["Main\n(App Entry)"]:::api
        ApiServer["ApiServer\n(HTTP Listener)"]:::api
        AuthController["AuthController"]:::api
        PacienteController["PacienteController"]:::api
        ConsultaController["ConsultaController"]:::api
        EspecialidadeController["EspecialidadeController"]:::api
        ProfissionalController["ProfissionalController"]:::api
        AgendaController["AgendaController"]:::api
    end

    subgraph "Business Logic Layer"
        direction TB
        AuthService["AuthService"]:::service
        PacienteService["PacienteService"]:::service
        ConsultaService["ConsultaService"]:::service
        EspecialidadeService["EspecialidadeService"]:::service
        ProfissionalService["ProfissionalService"]:::service
        DisponibilidadeService["DisponibilidadeService"]:::service
    end

    subgraph "Data Access Layer"
        direction TB
        AuthDAO["AuthDAO"]:::dao
        PacienteDAO["PacienteDAO"]:::dao
        ConsultaDAO["ConsultaDAO"]:::dao
        EspecialidadeDAO["EspecialidadeDAO"]:::dao
        ProfissionalDAO["ProfissionalDAO"]:::dao
        DisponibilidadeDAO["DisponibilidadeDAO"]:::dao
    end

    Utilities["Utilities"]:::util
    DatabaseConnection["DatabaseConnection"]:::util
    GsonConfig["GsonConfig"]:::util

    ExternalLibs["External Libraries"]:::util
    GSON["GSON Library"]:::util
    JDBCDriver["Oracle JDBC Driver"]:::util

    Database["Oracle Database"]:::db

    %% Flow
    Client -->|"HTTP Request"| ApiServer
    ApiServer -->|"route to"| AuthController
    ApiServer -->|"route to"| PacienteController
    ApiServer -->|"route to"| ConsultaController
    ApiServer -->|"route to"| EspecialidadeController
    ApiServer -->|"route to"| ProfissionalController
    ApiServer -->|"route to"| AgendaController

    AuthController -->|"calls"| AuthService
    PacienteController -->|"calls"| PacienteService
    ConsultaController -->|"calls"| ConsultaService
    EspecialidadeController -->|"calls"| EspecialidadeService
    ProfissionalController -->|"calls"| ProfissionalService
    AgendaController -->|"calls"| DisponibilidadeService

    AuthService -->|"calls DAO"| AuthDAO
    PacienteService -->|"calls DAO"| PacienteDAO
    ConsultaService -->|"calls DAO"| ConsultaDAO
    EspecialidadeService -->|"calls DAO"| EspecialidadeDAO
    ProfissionalService -->|"calls DAO"| ProfissionalDAO
    DisponibilidadeService -->|"calls DAO"| DisponibilidadeDAO

    AuthDAO -->|"SQL Query"| Database
    PacienteDAO -->|"SQL Query"| Database
    ConsultaDAO -->|"SQL Query"| Database
    EspecialidadeDAO -->|"SQL Query"| Database
    ProfissionalDAO -->|"SQL Query"| Database
    DisponibilidadeDAO -->|"SQL Query"| Database

    AuthController -->|"serializes JSON"| GsonConfig
    PacienteController -->|"serializes JSON"| GsonConfig
    ConsultaController -->|"serializes JSON"| GsonConfig
    EspecialidadeController -->|"serializes JSON"| GsonConfig
    ProfissionalController -->|"serializes JSON"| GsonConfig
    AgendaController -->|"serializes JSON"| GsonConfig

    AuthController -->|"HTTP Response"| ApiServer
    ApiServer -->|"HTTP Response"| Client

    AuthDAO -->|"uses"| DatabaseConnection
    PacienteDAO -->|"uses"| DatabaseConnection
    ConsultaDAO -->|"uses"| DatabaseConnection
    EspecialidadeDAO -->|"uses"| DatabaseConnection
    ProfissionalDAO -->|"uses"| DatabaseConnection
    DisponibilidadeDAO -->|"uses"| DatabaseConnection

    DatabaseConnection -->|"connects via JDBC"| JDBCDriver
    GsonConfig -->|"configures JSON"| GSON

    %% Click Events
    click Main "https://github.com/lgaxd/pathmed-api-java/blob/main/src/Main.java"
    click ApiServer "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/ApiServer.java"
    click AuthController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/AuthController.java"
    click PacienteController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/PacienteController.java"
    click ConsultaController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/ConsultaController.java"
    click EspecialidadeController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/EspecialidadeController.java"
    click ProfissionalController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/ProfissionalController.java"
    click AgendaController "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/controller/AgendaController.java"
    click AuthService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/AuthService.java"
    click PacienteService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/PacienteService.java"
    click ConsultaService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/ConsultaService.java"
    click EspecialidadeService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/EspecialidadeService.java"
    click ProfissionalService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/ProfissionalService.java"
    click DisponibilidadeService "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/service/DisponibilidadeService.java"
    click AuthDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/AuthDAO.java"
    click PacienteDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/PacienteDAO.java"
    click ConsultaDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/ConsultaDAO.java"
    click EspecialidadeDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/EspecialidadeDAO.java"
    click ProfissionalDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/ProfissionalDAO.java"
    click DisponibilidadeDAO "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/dao/DisponibilidadeDAO.java"
    click DatabaseConnection "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/util/DatabaseConnection.java"
    click GsonConfig "https://github.com/lgaxd/pathmed-api-java/blob/main/src/br/com/pathmed/util/GsonConfig.java"
    click GSON "https://github.com/lgaxd/pathmed-api-java/blob/main/lib/gson-2.13.1.jar"
    click JDBCDriver "https://github.com/lgaxd/pathmed-api-java/blob/main/lib/ojdbc17.jar"

    %% Styles
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef service fill:#90EE90,stroke:#000,stroke-width:1px
    classDef dao fill:#FFDAB9,stroke:#000,stroke-width:1px
    classDef db fill:#FFC0CB,stroke:#000,stroke-width:1px
    classDef util fill:#D3D3D3,stroke:#000,stroke-width:1px
```
