# tomiok/news architecture

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

- Interactive diagram: https://gitdiagram.com/tomiok/news
- Repository: https://github.com/tomiok/news

## Overview

- API Server: Represented by the code in the cmd/api directory. This is the entry point of the application (main.go, server.go) where the HTTP server is initialized.
- Feed Processing Module: Found under internal/feed. This includes the collector (collector.go), feed logic (feed.go), various handlers (handler folder), jobs (job.go and job_test.go), sanitization (sanitizer.go), and storage components (storage package). This subsystem is responsible for fetching, processing, storing, and handling RSS feeds.
- Web Presentation Layer: Under platform with subdirectories for templates (HTML files) and web logic (platform/web). This part renders the views using the provided base, login, home, news, and token pages.
- Static Assets: Located in the static folder (CSS, JS, manifest). Emphasize that these are served to the client to support frontend interactivity.
- Database: Although not explicitly detailed in the file tree, the presence of migration files (migrations folder) implies a SQL database is used for data persistence. Illustrate the DB as a separate component that the API (and indirectly the feed module) interacts with.
- External RSS Sources: Represent external feeds (many RSS endpoints) that are consumed by the feed collector.

##### Interactions and Data Flow
- Feed Processing Module to the Database, showing storage (user_storage.go, storage.go) and possibly retrieval of stored feed data.
- How the API Server interacts with the Web Presentation Layer; for example, after processing feeds, the server may render pages via platform/web using data and templates.

##### Architectural Patterns and Technical Details
- Modularity: The internal/feed folder is structured into submodules (collector, handler, job, storage), which suggests a modular design. Mark these submodules within the broader “Feed Processing Module.”
- Service Coordination: Optionally include a note or a separate component if there is any kind of scheduler (hinted by the job files) managing when to fetch/update feeds.

## Diagram (Mermaid)

```mermaid
graph TD
    G["Docker Container"]:::docker

    subgraph "Backend Layer"
        A["API Server"]:::api
        B["Feed Processing Module"]:::feed
        C["Database"]:::db
        D["External RSS Feeds"]:::external
    end

    subgraph "Frontend Layer"
        E["Web Presentation Layer"]:::frontend
        F["Static Assets"]:::static
    end

    G -->|"runs"| A
    G -->|"runs"| B
    G -->|"runs"| C
    G -->|"runs"| E
    G -->|"runs"| F

    A -->|"triggerFeed"| B
    B -->|"storeFeeds"| C
    D -->|"fetchFeeds"| B
    A -->|"renderPages"| E
    E -->|"includeAssets"| F

    click A "https://github.com/tomiok/news/tree/master/cmd/api/"
    click B "https://github.com/tomiok/news/tree/master/internal/feed/"
    click C "https://github.com/tomiok/news/tree/master/migrations/"
    click D "https://github.com/tomiok/news/blob/master/internal/feed/collector.go"
    click E "https://github.com/tomiok/news/tree/master/platform/"
    click F "https://github.com/tomiok/news/tree/master/static/"

    classDef api fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef feed fill:#a2d2ff,stroke:#000,stroke-width:2px;
    classDef db fill:#ccffcc,stroke:#000,stroke-width:2px;
    classDef frontend fill:#f0f0f0,stroke:#000,stroke-width:2px;
    classDef static fill:#f0f0f0,stroke:#000,stroke-width:2px;
    classDef external fill:#ffd6a5,stroke:#000,stroke-width:2px;
    classDef docker fill:#ffadad,stroke:#000,stroke-width:2px;
```
