# meesakveld/strapi-swift architecture

> Architecture diagram of the GitHub repository meesakveld/strapi-swift, 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/meesakveld/strapi-swift
- Repository: https://github.com/meesakveld/strapi-swift

## Overview

##### Project Type and Purpose
- StrapiSwift is a Swift package that acts as an API client for interacting with Strapi’s REST APIs. It provides modules for content management, authentication (local provider), media handling, and making HTTP requests. Its goal is to simplify the integration of a Strapi backend into Swift applications.

##### Analyzing the File Structure
- The main logic resides in the Sources/StrapiSwift directory. This directory is cleanly separated into submodules:
- Authentication – offering both general authentication and local strategies.
- ContentManager – handling API operations related to CRUD on collections, documents, query building (e.g., filters, sorts, and pagination).
- MediaLibrary – managing file queries and uploads that interact with media endpoints.
- Requests – providing common utilities for constructing HTTP requests, encoding bodies, managing error responses, and general network layer functionality.
- Alongside these, you have tests organized similarly under the Tests directory to validate functionality.
- Build configuration is managed via Package.swift and continuous integration via GitHub Actions workflows (.github/workflows/swift.yml).

##### Key Components
- API Client (StrapiSwift): The central module that configures and exposes submodules to clients.
- Authentication Module: Contains service classes such as LocalAuth, handling registration, login, update profile, password changes, and “me” endpoints.
- Content Manager Module: Includes classes for multiple HTTP verbs (GET, POST, PUT, DELETE) and supports query construction with CollectionQuery, DocumentQuery, etc.
- Media Library Module: Handles file querying and manipulation, including upload and deletion of images.
- Requests Module: A lower-level component managing the HTTP request lifecycle, error handling (error extraction, custom errors), and request body encoding via AnyCodable and StrapiRequestBody.

##### Component Relationships and Interactions
- The main StrapiSwift Client is the entry point. It first configures base parameters (baseURL, token, etc.) then delegates actions to submodules.
- The Authentication, Content Manager, and Media Library are high-level abstractions that wrap around the generic functionality of the Requests module. Each of these prepares the necessary URL endpoints and request bodies, then passes the request to a central function (MakeRequest) which communicates with the Strapi API.
- ErrorHandler utilities intercept responses and extract any relevant error messages or create custom errors.
- The entire package is designed using Swift’s URLRequest and Codable protocols, ensuring type safety and clear network data flows.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Each function group (auth, content management, media) is encapsulated in its own folder and set of classes.
- Reusability and Modularity: Common logic (Requests, ErrorHandling) is abstracted out allowing modules to reuse functionality.
- Stateless API Interactions: Methods encapsulate HTTP operations without maintaining internal state between requests.
- Consistency in using Swift language features like Codable, directing the design towards a simple and maintainable client API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Subgraph for StrapiSwift Package
    subgraph "StrapiSwift Package"
        A["StrapiSwift Client"]:::client
        B["Authentication Module"]:::module
        C["Content Manager Module"]:::module
        D["Media Library Module"]:::module
        E["Requests & Error Handling Module"]:::requests
    end

    %% External Dependency
    F["Strapi REST API"]:::external

    %% Relationships - Delegation from Client to Modules
    A -->|"delegatesTo"| B
    A -->|"delegatesTo"| C
    A -->|"delegatesTo"| D

    %% Modules calling the Requests module for network operations
    B -->|"calls"| E
    C -->|"calls"| E
    D -->|"calls"| E

    %% Requests module interacts with external API
    E -->|"makesHTTPRequests"| F
    E -->|"handlesErrors"| F

    %% Click Events for Component Mapping
    click A "https://github.com/meesakveld/strapi-swift/blob/main/Sources/StrapiSwift/StrapiSwift.swift"
    click B "https://github.com/meesakveld/strapi-swift/tree/main/Sources/StrapiSwift/Authentication"
    click C "https://github.com/meesakveld/strapi-swift/tree/main/Sources/StrapiSwift/ContentManager"
    click D "https://github.com/meesakveld/strapi-swift/tree/main/Sources/StrapiSwift/MediaLibrary"
    click E "https://github.com/meesakveld/strapi-swift/tree/main/Sources/StrapiSwift/Requests"

    %% Style Definitions
    classDef client fill:#D3E4CD,stroke:#31708E,stroke-width:2px;
    classDef module fill:#F7DAD9,stroke:#A94442,stroke-width:2px;
    classDef requests fill:#D9EDF7,stroke:#31708E,stroke-width:2px;
    classDef external fill:#F2DEDE,stroke:#A94442,stroke-width:2px;
```
