# pmniko/api-weather architecture

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

- Interactive diagram: https://gitdiagram.com/pmniko/api-weather
- Repository: https://github.com/pmniko/api-weather

## Overview

##### Project type and purpose
- This is a Node.js/TypeScript back‑end API (“Api‑Test”) that follows a Clean Architecture or Domain‑Driven Design style.
- Its sole purpose is to fetch weather data from an external API, transform it through a domain/dto/entity pipeline, and expose two REST endpoints:
- GET /api/weather/home
- GET /api/weather/provincias

##### File structure
- Top‑level:
- app.ts – application entry point that boots the server;
- config/plugins – environment variable loader;
- helpers/errors – custom error types and a handler;
- domain – core business layer: interfaces, entities, DTOs, repositories, datasources;
- infraestructure – concrete implementations: HTTP datasource, repository;
- application – orchestration: use‑cases and a Service that exposes them;
- presentation – HTTP layer: Express routes, controllers, server initialization.
- Patterns:
- Each “domain” concept (weather) has its interface, entity, dto, repository.
- Use‑cases live in application and are glued together by a Service class.
- Controllers call service methods; service calls use‑cases; use‑cases call repository interfaces; repositories call datasources; datasources call external API.

##### Key architecture insights from README
- The README steps describe exactly how to interface the external JSON, define domain abstractions, DTOs, use‑cases, services, controllers, and finally concrete infra implementations.
- The project enforces strict layer separation and dependency inversion: higher layers depend on abstractions, lower layers implement them.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["HTTP Client"]:::external

    subgraph "Presentation Layer"
        AppTS["app.ts"]:::presentation
        Server["server.ts"]:::presentation
        Routes["routes.ts"]:::presentation
        WeatherRoutes["weather/routes.ts"]:::presentation
        Controller["controller.ts"]:::presentation
    end

    subgraph "Application Layer"
        WeatherService["WeatherService.ts"]:::application
        UC_Home["getWeatherHome.use-case.ts"]:::application
        UC_Prov["getWeatherProvincias.use-case.ts"]:::application
    end

    subgraph "Domain Layer"
        RepoInt["weather.repository.ts"]:::domain
        DTO_F["weatherForecast.dto.ts"]:::domain
        DTO_P["weatherProvincia.dto.ts"]:::domain
        Entity_F["weatherForecast.entity.ts"]:::domain
        Entity_P["weatherProvincia.entity.ts"]:::domain
        API_IntF["WeatherForecastRespAPI.ts"]:::domain
        API_IntP["WeatherProvinciasRespAPI.ts"]:::domain
        DSInt["weather.datasource.ts"]:::domain
    end

    subgraph "Infrastructure Layer"
        DSImpl["weather-api.datasource.ts"]:::infrastructure
        RepoImpl["weather-api.repository.ts"]:::infrastructure
    end

    ExternalAPI["Third-party Weather API"]:::external

    subgraph "Config / Helpers"
        Env["env.plugins.ts"]:::config
        EnvIdx["index.ts"]:::config
        ErrC["custom-error.ts"]:::config
        ErrH["handleError.ts"]:::config
    end

    Client -->|"1"| WeatherRoutes
    WeatherRoutes -->|"2"| Controller
    Controller -->|"3"| WeatherService
    WeatherService -->|"4"| UC_Home
    WeatherService -->|"4"| UC_Prov
    UC_Home -->|"5"| RepoInt
    UC_Prov -->|"5"| RepoInt
    RepoInt -->|"6"| RepoImpl
    RepoImpl -->|"7"| DSImpl
    DSImpl -->|"8"| ExternalAPI
    ExternalAPI -->|"8"| DSImpl
    DSImpl -->|"9"| RepoImpl
    RepoImpl -->|"10"| UC_Home
    RepoImpl -->|"10"| UC_Prov
    UC_Home -->|"11"| WeatherService
    UC_Prov -->|"11"| WeatherService
    WeatherService -->|"12"| Controller
    Controller -->|"13"| WeatherRoutes
    WeatherRoutes -->|"14"| Client

    click AppTS "https://github.com/pmniko/api-weather/blob/main/src/app.ts"
    click Server "https://github.com/pmniko/api-weather/blob/main/src/presentation/server.ts"
    click Routes "https://github.com/pmniko/api-weather/blob/main/src/presentation/routes.ts"
    click WeatherRoutes "https://github.com/pmniko/api-weather/blob/main/src/presentation/weather/routes.ts"
    click Controller "https://github.com/pmniko/api-weather/blob/main/src/presentation/weather/controller.ts"
    click WeatherService "https://github.com/pmniko/api-weather/blob/main/src/application/weather/services/WeatherService.ts"
    click UC_Home "https://github.com/pmniko/api-weather/blob/main/src/application/weather/use-cases/getWeatherHome.use-case.ts"
    click UC_Prov "https://github.com/pmniko/api-weather/blob/main/src/application/weather/use-cases/getWeatherProvincias.use-case.ts"
    click RepoInt "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/repository/weather.repository.ts"
    click DTO_F "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/dto/weatherForecast.dto.ts"
    click DTO_P "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/dto/weatherProvincia.dto.ts"
    click Entity_F "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/entity/weatherForecast.entity.ts"
    click Entity_P "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/entity/weatherProvincia.entity.ts"
    click API_IntF "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/interfaces/WeatherForecastRespAPI.ts"
    click API_IntP "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/interfaces/WeatherProvinciasRespAPI.ts"
    click DSInt "https://github.com/pmniko/api-weather/blob/main/src/domain/weather/datasource/weather.datasource.ts"
    click DSImpl "https://github.com/pmniko/api-weather/blob/main/src/infraestructure/weather/datasource/weather-api.datasource.ts"
    click RepoImpl "https://github.com/pmniko/api-weather/blob/main/src/infraestructure/weather/repository/weather-api.repository.ts"
    click Env "https://github.com/pmniko/api-weather/blob/main/src/config/plugins/env.plugins.ts"
    click EnvIdx "https://github.com/pmniko/api-weather/blob/main/src/config/plugins/index.ts"
    click ErrC "https://github.com/pmniko/api-weather/blob/main/src/helpers/errors/custom-error.ts"
    click ErrH "https://github.com/pmniko/api-weather/blob/main/src/helpers/errors/handleError.ts"

    classDef presentation fill:#e2f7e1,stroke:#2d7a2d,color:#2d7a2d
    classDef application fill:#e1eaf7,stroke:#2a4380,color:#2a4380
    classDef domain fill:#f7e4d1,stroke:#a05800,color:#a05800
    classDef infrastructure fill:#eadcf7,stroke:#702d80,color:#702d80
    classDef external fill:#cccccc,stroke:#888888,color:#333333
    classDef config fill:#faf1c0,stroke:#bea800,color:#bea800
```
