# sahooashis/hackernewsproject architecture

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

- Interactive diagram: https://gitdiagram.com/sahooashis/hackernewsproject
- Repository: https://github.com/sahooashis/hackernewsproject

## Overview

##### Project type and purpose
- This is a command-line Python 2.7 data-ingestion tool that fetches “new” and “top” stories from the HackerNews API and outputs them as CSV files or stores them in a SQLite database.
- The README spells out the use case: query the HN API, retrieve stories, then persist them in CSV or SQLite.

##### File structure
- Top-level files
- run.py – entry point
- README.md
- Packages
- utility/ – bootstrapping, user choice handling (ChoiceUtility.py, Main.py)
- functionality/ – core logic for fetching and dispatching data (HackerNews.py, HackerNewsCSV.py, HackerNewsSqlite.py, StoryFetch.py)
- connection/ – I/O abstractions (WebConnection.py for HTTP, DBConnection.py for SQLite)
- models/ – domain model (StoryClass.py)
- files/ – output artifacts (CSV and .db files)

##### README for additional insights
- It lists the four main packages and their responsibilities.
- Dependencies: urllib2 (HTTP), csv, sqlite3.

##### Detailed Capturing of Architectural Elements
- That run.py does not itself fetch or persist, but delegates to utility.Main
- How ChoiceUtility abstracts user input from the rest of the system
- That StoryFetch is the orchestrator for invoking HackerNews and persistence adapters
- Model StoryClass as the data carrier between fetch and persist

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Systems
    API["HackerNews REST API"]:::external

    %% CLI Layer
    subgraph "CLI Layer"
        RUN["run.py"]:::cli
    end

    %% Utility Layer
    subgraph "Utility Layer"
        MAIN["Main (utility/Main.py)"]:::orchestrator
        CHOICE["ChoiceUtility (utility/ChoiceUtility.py)"]:::orchestrator
    end

    %% Core Functionality Layer
    subgraph "Core Functionality"
        FETCH["StoryFetch (functionality/StoryFetch.py)"]:::core
        HNAPI["HackerNews (functionality/HackerNews.py)"]:::core
    end

    %% Adapter / I/O Layer
    subgraph "Adapter Layer"
        WEB["WebConnection (connection/WebConnection.py)"]:::io
        DBCON["DBConnection (connection/DBConnection.py)"]:::io
        CSVADPT["HackerNewsCSV (functionality/HackerNewsCSV.py)"]:::io
        SQLADPT["HackerNewsSqlite (functionality/HackerNewsSqlite.py)"]:::io
    end

    %% Model Layer
    subgraph "Model Layer"
        STORY["StoryClass (models/StoryClass.py)"]:::core
    end

    %% Storage Layer
    subgraph "Storage"
        CSVS["NewStories.csv / TopStories.csv"]:::io
        DBS["database.db"]:::io
    end

    %% Flow
    RUN -->|invokes| MAIN
    MAIN -->|select mode| CHOICE
    MAIN -->|invoke fetch| FETCH
    CHOICE -->|provides options| MAIN

    FETCH -->|fetch IDs/details| HNAPI
    HNAPI -->|uses HTTP| WEB
    WEB -->|GET/POST| API

    FETCH -->|instantiate| STORY

    FETCH -->|persist CSV| CSVADPT
    CSVADPT -->|write CSV| CSVS

    FETCH -->|persist SQLite| SQLADPT
    SQLADPT -->|uses DB| DBCON
    DBCON -->|write to file| DBS

    %% Click events
    click RUN "https://github.com/sahooashis/hackernewsproject/blob/master/run.py"
    click MAIN "https://github.com/sahooashis/hackernewsproject/blob/master/utility/Main.py"
    click CHOICE "https://github.com/sahooashis/hackernewsproject/blob/master/utility/ChoiceUtility.py"
    click FETCH "https://github.com/sahooashis/hackernewsproject/blob/master/functionality/StoryFetch.py"
    click HNAPI "https://github.com/sahooashis/hackernewsproject/blob/master/functionality/HackerNews.py"
    click CSVADPT "https://github.com/sahooashis/hackernewsproject/blob/master/functionality/HackerNewsCSV.py"
    click SQLADPT "https://github.com/sahooashis/hackernewsproject/blob/master/functionality/HackerNewsSqlite.py"
    click WEB "https://github.com/sahooashis/hackernewsproject/blob/master/connection/WebConnection.py"
    click DBCON "https://github.com/sahooashis/hackernewsproject/blob/master/connection/DBConnection.py"
    click STORY "https://github.com/sahooashis/hackernewsproject/blob/master/models/StoryClass.py"
    click CSVS "https://github.com/sahooashis/hackernewsproject/blob/master/files/NewStories.csv"
    click DBS "https://github.com/sahooashis/hackernewsproject/blob/master/files/database.db"

    %% Styles
    classDef cli fill:#9f6,stroke:#333,stroke-width:1px
    classDef orchestrator fill:#6cf,stroke:#333,stroke-width:1px
    classDef core fill:#fc6,stroke:#333,stroke-width:1px
    classDef io fill:#f96,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
```
