# fisohan/wikifloraapi architecture

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

## Overview

##### Project Identification
- This is a backend service developed in .NET (using a Visual Studio solution and C#). Its purpose is to serve as the backend API for the WikiFlora project.
- The README mentions it is the “Backend of WikiFlora,” and the structure indicates a RESTful API with controllers, services, data models, and a database.

##### Major Components
a. Web API Layer (Controllers):
– Include separate nodes for each controller found in the WikiFloraAPI/Controllers directory (e.g., FloraController, CommentController, FileController, UserController, WeatherForecastController).
– These represent HTTP endpoints handling client requests.

b. Service Layer:
– Represent the business logic using the various services (FloraService, CommentService, FileService, UserService, and the interfaces for these services).
– Also note the supporting utilities like the BiGram service within the Services folder.

c. Data Access / Persistence Layer:
– Display the DataContext (located in WikiFloraAPI/Data) that manages the interaction with the underlying database.
– Show the migrations as part of the database versioning mechanism.
– Include the Application.db (with its shim files) which is likely an SQLite database.

d. Domain / Models:
– Illustrate the models (such as Flora, Comment, User, etc.) along with the related DTOs present in the corresponding Models/Dtos directory.
– Represent the exception handling mechanism via ExceptionHandler.

e. Authentication / Authorization:
– Highlight the KeycloakClaimsTransformation class which indicates integration for transforming or mapping claims from an external authentication provider (Keycloak).
– Also mention the AuthOption.cs file which likely configures authentication options.

f. Additional Components:
– A “File Storage” or “Media” component for handling FloraPhotos might be shown since there is a dedicated folder for flora photos.
– Optional “Configuration” components for appsettings.json files (both development and production) can be depicted to show environment configuration and settings.

##### Component Relationships and Data Flow
- From services, illustrate calls to the DataContext (or repository layer if applicable) representing database interactions.

##### Architectural Patterns and Design Principles
- The structure follows an MVC-like pattern where controllers mediate incoming requests, services handle business logic, and the data context or models interact with persistent storage.
- Dependency injection: interfaces in services (IFloraService, ICommentService, etc.) indicate a design that supports DI for better testability and loose coupling.
- Separation of concerns: Controllers (request handling), Services (business logic) and Data Access (persisting data).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Client
    Client("External Client"):::client

    %% API Layer
    subgraph "API Layer"
        FloraController("FloraController"):::controller
        CommentController("CommentController"):::controller
        FileController("FileController"):::controller
        UserController("UserController"):::controller
        WeatherForecastController("WeatherForecastController"):::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        FloraService("FloraService + IFloraService"):::service
        CommentService("CommentService + ICommentService"):::service
        FileService("FileService + IFileService"):::service
        UserService("UserService + IUserService"):::service
        BiGram("BiGram Utility Service"):::service
        ClaimService("ClaimService"):::service
    end

    %% Data / Persistence Layer
    subgraph "Data / Persistence Layer"
        DataContext("DataContext"):::database
        Migrations("Migrations"):::database
        Database("SQLite Database (Application.db)"):::database
    end

    %% Domain / Models Layer
    subgraph "Domain / Models"
        Models("Domain Models & DTOs"):::model
        ExceptionHandler("ExceptionHandler"):::model
    end

    %% Authentication / Authorization Layer
    subgraph "Authentication"
        Keycloak("KeycloakClaimsTransformation"):::auth
        AuthOptions("AuthOption"):::auth
    end

    %% Additional Components
    subgraph "Additional Components"
        FileStorage("File Storage (FloraPhotos)"):::storage
        subgraph "Configuration"
            AppSettings("appsettings.json"):::config
            AppSettingsDev("appsettings.Development.json"):::config
        end
    end

    %% Data Flow Relationships
    Client -->|"HTTPRequest"| FloraController
    Client -->|"HTTPRequest"| CommentController
    Client -->|"HTTPRequest"| FileController
    Client -->|"HTTPRequest"| UserController
    Client -->|"HTTPRequest"| WeatherForecastController

    FloraController -->|"calls"| FloraService
    CommentController -->|"calls"| CommentService
    FileController -->|"calls"| FileService
    UserController -->|"calls"| UserService
    WeatherForecastController -->|"calls"| FloraService

    FloraService -->|"accesses"| DataContext
    CommentService -->|"accesses"| DataContext
    FileService -->|"accesses"| DataContext
    UserService -->|"accesses"| DataContext

    FloraService -->|"uses"| BiGram

    FileController -->|"uploads to"| FileStorage

    DataContext -->|"manages"| Database
    DataContext -->|"tracks"| Migrations

    FloraController -->|"handles errors via"| ExceptionHandler
    CommentController -->|"handles errors via"| ExceptionHandler
    UserController -->|"handles errors via"| ExceptionHandler

    Keycloak -->|"transformsClaims"| FloraController
    Keycloak -->|"transformsClaims"| UserController
    AuthOptions -->|"configures"| Keycloak

    AppSettings -->|"configures"| DataContext
    AppSettingsDev -->|"configures"| DataContext

    FloraService -->|"manipulates"| Models
    CommentService -->|"manipulates"| Models
    FileService -->|"manipulates"| Models
    UserService -->|"manipulates"| Models

    %% Style Classes
    classDef client fill:#f9c,stroke:#333,stroke-width:2px;
    classDef controller fill:#ccf,stroke:#333,stroke-width:2px;
    classDef service fill:#cfc,stroke:#333,stroke-width:2px;
    classDef database fill:#fcc,stroke:#333,stroke-width:2px;
    classDef model fill:#fcf,stroke:#333,stroke-width:2px;
    classDef auth fill:#cff,stroke:#333,stroke-width:2px;
    classDef storage fill:#ff9,stroke:#333,stroke-width:2px;
    classDef config fill:#9ff,stroke:#333,stroke-width:2px;

    %% Click Events for API Layer (Controllers)
    click FloraController "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Controllers/FloraController.cs"
    click CommentController "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Controllers/CommentController.cs"
    click FileController "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Controllers/FileController.cs"
    click UserController "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Controllers/UserController.cs"
    click WeatherForecastController "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Controllers/WeatherForecastController.cs"

    %% Click Events for Service Layer
    click FloraService "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/FloraService.cs"
    click CommentService "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/CommentService.cs"
    click FileService "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/FileService.cs"
    click UserService "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/UserService.cs"
    click BiGram "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/BiGram.cs"
    click ClaimService "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Services/ClaimService.cs"

    %% Click Events for Data / Persistence Layer
    click DataContext "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Data/DataContext.cs"
    click Database "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Application.db"
    click Migrations "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Migrations/DataContextModelSnapshot.cs"

    %% Click Events for Domain / Models Layer
    click ExceptionHandler "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/Models/ExceptionHandler.cs"

    %% Click Events for Authentication / Authorization Layer
    click Keycloak "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/KeycloakClaimsTransformation.cs"
    click AuthOptions "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/AuthOption.cs"

    %% Click Events for Additional Components
    click FileStorage "https://github.com/fisohan/wikifloraapi/tree/master/WikiFloraAPI/FloraPhotos"
    click AppSettings "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/appsettings.json"
    click AppSettingsDev "https://github.com/fisohan/wikifloraapi/blob/master/WikiFloraAPI/appsettings.Development.json"
```
