# joppedc/spacexstats architecture

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

- Interactive diagram: https://gitdiagram.com/joppedc/spacexstats
- Repository: https://github.com/joppedc/spacexstats

## Overview

##### Main Components
- Frontend (Presentation Layer):
– Templates: The “templates” directory contains Twig files used to render views such as overview and detailed pages for Crew, Rockets, Landing Pads, and Ships.
– Public Assets: In the “public” folder, assets like CSS, JavaScript, images, fonts, etc., provide styling and interactivity through frameworks (e.g., Bootstrap and a custom Argon theme).
- Backend (Application Layer):
– Controllers: Located in the “src/Controller” directory (e.g., CrewController, RocketController), these handle user requests, route them via Symfony’s routing system (configured in “config/routes.yaml” and additional routing files) and determine which view to render.
– Services: In “src/Service/Client”, the SpaceXClient acts as a middle-layer to fetch data from the external API. This service may use Symfony’s HTTP client, caching (configured in “config/packages”), and serializer components.
– Repositories: Found in “src/Repository”, these components (like RocketRepository, CrewRepository, etc.) organize data retrieval logic. They likely instantiate or use the API client and abstract the data mapping for the controllers.
– Client/Response Components: The “src/Client/Response” directory contains dedicated PHP classes for parsing API responses into domain-specific objects (e.g., Company, Crew, LandingPad, Rocket, Ship). This enforces a clear separation between API data and application logic.
- External API Integration:
- Configuration and Environment:
– Environment variables (.env, .env.test) play a role in defining runtime settings.
- Testing & CI/CD:
– The “tests” directory along with configuration files like “phpunit.xml.dist” indicate automated testing.
– GitHub workflows under “.github/workflows” illustrate continuous integration steps.

##### Relationships and Data Flow
– End-User interaction begins with a web browser making an HTTP request to the Symfony web server (public/index.php).
– The Symfony Kernel routes the request to the appropriate Controller (e.g., CrewController or RocketController) based on defined routes.
– Controllers call methods in their corresponding Repository/Service to fetch data.
– The Service layer (using SpaceXClient) contacts the external SpaceX API, retrieves the data, and (if applicable) passes it through caching and serialization components.
– The Repository handles any additional business logic or mapping of API responses to domain models.
– Finally, the Controller sends the data to a Twig template from the “templates” directory for rendering a complete web page back to the user.
– Optionally, testing components and CI/CD pipelines ensure code quality by running tests via PHPUnit (from “bin/phpunit” and “tests”).

##### Architectural Patterns & Principles
– MVC Pattern is evident with Controllers, Views (Twig templates), and the separation of business logic in Services/Repositories.
– Service-Oriented architecture is used for external API consumption, reinforcing single-responsibility through the dedicated SpaceXClient.
– Use of Dependency Injection (configured in “config/services.yaml”) decouples components.
– Client-Repository pattern: The API client encapsulates the way external data is fetched, and repository classes handle transformation and business domain mapping.
– Use of caching and serialization components (as mentioned in the README) is crucial for performance and data integrity.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction Layer
    U["Browser"]:::user

    %% Frontend Layer
    subgraph "Frontend Layer"
        WS["Web Server (public/index.php)"]:::server
        TT["Twig Templates"]:::template
        PA["Public Assets"]:::assets
    end

    %% Backend Layer
    subgraph "Backend Layer"
        SK["Symfony Kernel"]:::kernel
        CT["Controllers"]:::controller
        CT1["CrewController"]:::controller
        CT2["RocketController"]:::controller
        CT3["LandingPadController"]:::controller
        CT4["ShipController"]:::controller
        SV["Service: SpaceXClient"]:::service
        RP["Repositories"]:::repository
        CR["Client/Response Components"]:::clientResponse
    end

    %% External & Supporting Services
    subgraph "External & Supporting"
        EX["r-spacex API"]:::external
        CF["Configuration & Environment"]:::config
        TC["Testing & CI/CD"]:::testing
    end

    %% Data Flow and Relationships
    U -->|"HTTP_Request"| WS
    WS -->|"Routes_to"| SK
    SK -->|"Dispatches_to"| CT
    CT -->|"Invokes"| CT1
    CT -->|"Invokes"| CT2
    CT -->|"Invokes"| CT3
    CT -->|"Invokes"| CT4
    CT1 -->|"Calls"| SV
    CT1 -->|"Uses"| RP
    CT1 -->|"Renders_view"| TT
    CT2 -->|"Calls"| SV
    CT3 -->|"Calls"| SV
    CT4 -->|"Calls"| SV
    SV -->|"Fetches_data_from"| EX
    EX -->|"Returns_Response_to"| SV
    TT -->|"Delivers_HTML_to"| U

    %% Supporting relationships
    CF --- SK
    CF --- CT
    TC --- SK

    %% Click Events for Component Mapping
    click TT "https://github.com/joppedc/spacexstats/tree/master/templates/"
    click PA "https://github.com/joppedc/spacexstats/tree/master/public/"
    click CT "https://github.com/joppedc/spacexstats/tree/master/src/Controller/"
    click SV "https://github.com/joppedc/spacexstats/blob/master/src/Service/Client/SpaceXClient.php"
    click RP "https://github.com/joppedc/spacexstats/tree/master/src/Repository/"
    click CR "https://github.com/joppedc/spacexstats/tree/master/src/Client/Response/"
    click CF "https://github.com/joppedc/spacexstats/tree/master/config/"
    click TC "https://github.com/joppedc/spacexstats/tree/master/.github/workflows/"

    %% Styles
    classDef user fill:#fef3bd,stroke:#e8c547,stroke-width:2px;
    classDef server fill:#d0e6f7,stroke:#76a9e0,stroke-width:2px;
    classDef template fill:#d1f7c4,stroke:#6abf69,stroke-width:2px;
    classDef assets fill:#ffd6a5,stroke:#ff9f1c,stroke-width:2px;
    classDef kernel fill:#f9d5e5,stroke:#e56a86,stroke-width:2px;
    classDef controller fill:#cddafd,stroke:#5a77f0,stroke-width:2px;
    classDef service fill:#f3e1f3,stroke:#c56dcc,stroke-width:2px;
    classDef repository fill:#e0f7fa,stroke:#26c6da,stroke-width:2px;
    classDef clientResponse fill:#ffe0b2,stroke:#fb8c00,stroke-width:2px;
    classDef external fill:#ffd1dc,stroke:#e91e63,stroke-width:2px;
    classDef config fill:#e8eaf6,stroke:#3f51b5,stroke-width:2px;
    classDef testing fill:#e0f2f1,stroke:#009688,stroke-width:2px;
```
