# fazeelbhatti/dawn-news-api architecture

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

- Interactive diagram: https://gitdiagram.com/fazeelbhatti/dawn-news-api
- Repository: https://github.com/fazeelbhatti/dawn-news-api

## Overview

##### Project type and purpose
- This is a Go-based HTTP API service (“Dawn News Web Scraper API”) built with the Gin framework. It exposes endpoints for “latest news” and “article by ID,” scraping Dawn.com on demand via the Colly library. It’s packaged in Docker, with a Cloud Build config for CI/CD and Swagger for docs.

##### File structure
- Top-level artifacts
- main.go – application entrypoint, Gin router setup
- controllers/ – HTTP handlers for “latest-news” and “article/:id”
- models/ – data structures for articles and article details
- docs/ – Swagger spec (swagger.json/yaml), auto-generated docs.go
- Dockerfile & cloudbuild.yaml – containerization & CI/CD
- go.mod/go.sum – dependency management
- No explicit database directory, so scraping and in-memory models serve responses.
- The MVC-ish separation: controllers → models → response JSON; docs plugged via Swagger middleware.

##### Insights from README
- Two endpoints under /api/v1/ serve JSON payloads.
- Uses Gin for routing, Colly for scraping Dawn.com.
- Docker image built and run; Cloud Build handles build/push/deploy.
- Swagger UI hosted under /swagger/index.html.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External systems
    Client["Client (cURL/Postman)"]:::external
    DawnCom["Dawn.com"]:::external

    %% API Service Layer
    subgraph "API Service" 
        direction TB
        GinRouter["Gin Router\n(main.go)"]:::runtime
        subgraph "Controllers" 
            direction TB
            LatestNews["Latest News Handler\n(controllers/articles.go)"]:::runtime
            ArticleByID["Article-by-ID Handler\n(controllers/article_details.go)"]:::runtime
            Scraper["Colly Scraper\n(controllers/)"]:::runtime
        end
        subgraph "Models"
            direction TB
            ModelArticle["Article Struct\n(models/article.go)"]:::runtime
            ModelDetails["Article Details Struct\n(models/article_details.go)"]:::runtime
        end
        subgraph "Swagger Docs"
            direction TB
            SwaggerMiddleware["Swagger Middleware\n(docs/docs.go)"]:::runtime
            SwaggerSpecJSON["swagger.json"]:::runtime
            SwaggerSpecYAML["swagger.yaml"]:::runtime
        end
    end

    %% Infrastructure
    subgraph "Docker Host"
        direction TB
        DockerContainer["Docker Container\nDockerfile"]:::infrastructure
    end

    subgraph "CI/CD Pipeline"
        direction TB
        CloudBuild["Cloud Build\n(cloudbuild.yaml)"]:::infrastructure
    end

    %% Data flows
    Client -->|"HTTP Request\n/api/v1/latest-news"| GinRouter
    Client -->|"HTTP Request\n/api/v1/article/:id"| GinRouter
    GinRouter -->|"routes to"| LatestNews
    GinRouter -->|"routes to"| ArticleByID
    LatestNews -->|"uses"| Scraper
    ArticleByID -->|"uses"| Scraper
    Scraper -->|"scrapes"| DawnCom
    LatestNews -->|"maps to"| ModelArticle
    ArticleByID -->|"maps to"| ModelDetails
    GinRouter -->|"serves docs"| SwaggerMiddleware
    SwaggerMiddleware --> SwaggerSpecJSON
    SwaggerMiddleware --> SwaggerSpecYAML

    %% Deployment flows
    CloudBuild -->|"builds image"| DockerContainer
    DockerContainer -->|"runs API Service"| GinRouter

    %% Click Events
    click GinRouter "https://github.com/fazeelbhatti/dawn-news-api/blob/main/main.go"
    click LatestNews "https://github.com/fazeelbhatti/dawn-news-api/blob/main/controllers/articles.go"
    click ArticleByID "https://github.com/fazeelbhatti/dawn-news-api/blob/main/controllers/article_details.go"
    click Scraper "https://github.com/fazeelbhatti/dawn-news-api/tree/main/controllers/"
    click ModelArticle "https://github.com/fazeelbhatti/dawn-news-api/blob/main/models/article.go"
    click ModelDetails "https://github.com/fazeelbhatti/dawn-news-api/blob/main/models/article_details.go"
    click SwaggerMiddleware "https://github.com/fazeelbhatti/dawn-news-api/blob/main/docs/docs.go"
    click SwaggerSpecJSON "https://github.com/fazeelbhatti/dawn-news-api/blob/main/docs/swagger.json"
    click SwaggerSpecYAML "https://github.com/fazeelbhatti/dawn-news-api/blob/main/docs/swagger.yaml"
    click DockerContainer "https://github.com/fazeelbhatti/dawn-news-api/tree/main/Dockerfile"
    click CloudBuild "https://github.com/fazeelbhatti/dawn-news-api/blob/main/cloudbuild.yaml"

    %% Styles
    classDef runtime fill:#e6ffed,stroke:#2ca02c,stroke-width:2px
    classDef infrastructure fill:#e7f1ff,stroke:#1f77b4,stroke-width:2px
    classDef external fill:#fff4e6,stroke:#ff7f0e,stroke-width:2px
```
