# aztfirespell/frogmiearhquake architecture

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

- Interactive diagram: https://gitdiagram.com/aztfirespell/frogmiearhquake
- Repository: https://github.com/aztfirespell/frogmiearhquake

## Overview

##### Project Overview and Type
- This project is a full-stack application made for a technical evaluation. It combines a Ruby on Rails backend with a React frontend.
- The backend (built with RoR) serves as an API provider exposing endpoints to retrieve earthquake data and related comments. It also includes a scheduled task (FetchAndSaveDataJob) to fetch and store earthquake records.
- The frontend (located in the ‘client’ folder) is a React application that consumes these API endpoints, enabling users to view earthquake information and interact with the system.

##### Main Components
a. Frontend Client:
- React-based application (inside the “client” directory).
- Components like AppRoutes and NavBar, along with feature-specific components for listing earthquakes and comments.
- Communication via HTTP calls (fetching data) to the backend API.

b. Backend Server:
- Ruby on Rails application (root and “app” folder) with standard MVC architecture.
- API Controllers (located under app/controllers/api/v1) handling endpoints (features, comments etc.).
- Background jobs such as FetchAndSaveDataJob which fetch external earthquake data and write to the database.
- Models for Earthquake and Comment with associations.
- Additional layers like channels (for ActionCable), initializers, and mailers (if needed).

c. Database:
- SQLite database used for storing earthquake data and comments.
- Schema and migrations (under “db/migrate” and db/schema.rb) that define how data is structured and maintained.

d. External API Integration:
- Although not fully detailed, there is clear functionality to fetch earthquake data from an external API (triggered by the Rails runner command).

e. Containerization & Deployment:
- Docker configuration (Dockerfile, docker-compose.yml, and related files in the “client” and root) are in place to build and run the application in containers.

##### Relationships and Data Flows
- The React frontend interacts with the Rails backend through well-defined API endpoints (documented in the README).
- The backend exposes RESTful endpoints to get a list of earthquakes, single earthquake details, filtered queries, and comment functionality.
- A background job (FetchAndSaveDataJob) periodically (or via manual trigger) fetches data from an external earthquake data service and persists it to the SQLite database.
- The database acts as the persistent store for both earthquakes and user-generated comments.
- The Rails application may also include real-time features via ActionCable (as hinted by the “app/channels” structure).

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller) pattern in the backend.
- Separation of concerns: The client folder exclusively handles the React user interface while the server folder deals with API endpoints and business logic.
- Containerization using Docker to ensure consistency across development and production environments.
- RESTful API design for clear and standardized endpoints.
- Use of job scheduling (or manual trigger) to handle batch processing of external API data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Client Subgraph
    subgraph "Frontend Client"
        FE1["React Application"]:::frontend
        FE2["AppRoutes (Component)"]:::frontend
        FE3["NavBar (Component)"]:::frontend
        FE1 --> FE2
        FE1 --> FE3
    end

    %% Backend Server Subgraph
    subgraph "Backend Server"
        BE1["Rails API Server"]:::backend
        BE2["API Controllers (/api/v1)"]:::backend
        BE3["Background Job: FetchAndSaveDataJob"]:::backend
        BE4["Models: Earthquake & Comments"]:::backend
        BE5["ActionCable Channels"]:::backend
        BE1 --> BE2
        BE1 --> BE3
        BE1 --> BE4
        BE1 --> BE5
    end

    %% Database Node
    DB["SQLite Database"]:::database

    %% External API Node
    EXT["External Earthquake Data API"]:::external

    %% Containerization & Deployment Subgraph
    subgraph "Containerization & Deployment"
        D1["Root Dockerfile"]:::container
        D2["Client Dockerfile"]:::container
        D3["docker-compose.yml"]:::container
    end

    %% Relationships
    FE1 -->|"HTTP_API_calls"| BE1
    BE1 -->|"CRUD_operations"| DB
    BE3 -->|"Fetches_Data"| EXT

    %% Containerization Connections
    D1 -->|"runs_container"| FE1
    D1 -->|"runs_container"| BE1
    D2 -->|"runs_container"| FE1
    D2 -->|"runs_container"| BE1
    D3 -->|"runs_container"| FE1
    D3 -->|"runs_container"| BE1

    %% Click Events for Frontend
    click FE1 "https://github.com/aztfirespell/frogmiearhquake/tree/main/client/"
    click FE2 "https://github.com/aztfirespell/frogmiearhquake/blob/main/client/src/components/AppRoutes.jsx"
    click FE3 "https://github.com/aztfirespell/frogmiearhquake/blob/main/client/src/components/NavBar.jsx"

    %% Click Events for Backend
    click BE1 "https://github.com/aztfirespell/frogmiearhquake/tree/main/app/"
    click BE2 "https://github.com/aztfirespell/frogmiearhquake/tree/main/app/controllers/api/v1"
    click BE3 "https://github.com/aztfirespell/frogmiearhquake/blob/main/app/jobs/fetch_and_save_data_job.rb"
    click BE4 "https://github.com/aztfirespell/frogmiearhquake/tree/main/app/models"
    click BE5 "https://github.com/aztfirespell/frogmiearhquake/tree/main/app/channels"

    %% Click Event for Database
    click DB "https://github.com/aztfirespell/frogmiearhquake/tree/main/db/"

    %% Click Events for Containerization & Deployment
    click D1 "https://github.com/aztfirespell/frogmiearhquake/tree/main/Dockerfile"
    click D2 "https://github.com/aztfirespell/frogmiearhquake/tree/main/client/Dockerfile"
    click D3 "https://github.com/aztfirespell/frogmiearhquake/blob/main/docker-compose.yml"

    %% Styles
    classDef frontend fill:#c7f9cc,stroke:#006400,stroke-width:2px;
    classDef backend fill:#a2d2ff,stroke:#003566,stroke-width:2px;
    classDef database fill:#ffe6a7,stroke:#d35400,stroke-width:2px,stroke-dasharray: 5 5;
    classDef external fill:#e0c3fc,stroke:#6f42c1,stroke-width:2px,stroke-dasharray: 3 3;
    classDef container fill:#fff3b0,stroke:#b58900,stroke-width:2px;
```
