# crefax/bazaar-api architecture

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

- Interactive diagram: https://gitdiagram.com/crefax/bazaar-api
- Repository: https://github.com/crefax/bazaar-api

## Overview

##### Project Type and Purpose
- This is a backend‐only, Rust-based REST API service (“Bazaar API”) whose sole purpose is to track, store, and serve Hypixel SkyBlock Bazaar price data.
- There is no user-facing frontend; instead you have:
- A “tracker” component that polls or receives Bazaar data from Hypixel’s external service
- A MongoDB database for persistence
- A set of HTTP API endpoints for clients to query current and historical data

##### File Structure
- src/main.rs
- Bootstraps the whole service, wires together the API server, tracker, and database layer
- src/api
- api.rs / mod.rs define HTTP routes (GET /api/skyblock/bazaar/{product_id} and history)
- src/db
- db.rs / mod.rs hold MongoDB connection logic and CRUD methods
- src/tracker
- tracker.rs / mod.rs contain logic that periodically fetches Bazaar data from Hypixel and writes it to MongoDB
- src/models
- models.rs / mod.rs define the BazaarData struct (product_id, buy_price, etc.) used by both tracker and API

##### README for Additional Insights
- Confirms tech stack: Rust, MongoDB
- Describes the two main feature sets: “latest data” and “historical data” endpoints

##### Main Components & Their Interactions
a. External Hypixel Bazaar Data Source
- The public Hypixel API or data feed that the tracker polls
b. Tracker Component
- Periodically issues REST calls to the external service, transforms the JSON into BazaarData models, and writes to MongoDB
c. MongoDB Database
- Stores each BazaarData record, indexed by product_id and timestamp
d. API Server Component
- Exposes two endpoints under /api/skyblock/bazaar
- On request, reads from MongoDB via the db module and returns JSON
e. Clients
- Any external consumer (web app, analytics tool, cron job) that calls the API

##### Architectural Patterns & Design Principles
- Layered Architecture (also known as the 3-tier pattern):
- Data layer (src/db)
- Business logic / service layer (src/tracker + any future domain logic)
- Presentation / API layer (src/api)
- Single binary composed of modules: no microservices, but clear separation of concerns
- Asynchronous I/O (presumably using Tokio or async-std under the hood) for non-blocking tracker and HTTP server

##### Detail Without Over-Complication
- External interactions (Hypixel and clients)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Systems"
        Hyp["Hypixel Bazaar Data API"]:::external
        Client["Client"]:::external
    end

    subgraph "Internal Services"
        Main["Orchestrator\n(src/main.rs)"]:::orchestrator
        Tracker["Tracker\n(src/tracker)"]:::service
        API["API Server\n(src/api)"]:::service
        Models["Models\n(src/models)"]:::shared
        DB["MongoDB\n(src/db)"]:::db
    end

    Hyp -->|"HTTP GET /bazaar (JSON)"| Tracker
    Tracker -->|"Insert BSON record"| DB
    API -->|"Query BSON"| DB
    Client -->|"HTTP GET /api/... (JSON)"| API

    Main --> Tracker
    Main --> API

    Tracker --- Models
    API --- Models

    click Tracker "https://github.com/crefax/bazaar-api/tree/main/src/tracker"
    click API "https://github.com/crefax/bazaar-api/tree/main/src/api"
    click DB "https://github.com/crefax/bazaar-api/tree/main/src/db"
    click Models "https://github.com/crefax/bazaar-api/tree/main/src/models"
    click Main "https://github.com/crefax/bazaar-api/blob/main/src/main.rs"

    classDef external fill:#f2f2f2,stroke:#333,stroke-width:1px;
    classDef service fill:#cce5ff,stroke:#004085,stroke-width:1px;
    classDef db fill:#d4edda,stroke:#155724,stroke-width:1px;
    classDef shared fill:#fff3cd,stroke:#856404,stroke-width:1px;
    classDef orchestrator fill:#e2e3e5,stroke:#383d41,stroke-width:1px;
```
