# khantminkyi/blood_donation_management_system architecture

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

- Interactive diagram: https://gitdiagram.com/khantminkyi/blood_donation_management_system
- Repository: https://github.com/khantminkyi/blood_donation_management_system

## Overview

##### Main Components
- Frontend: Represented mainly by the views in the “resources/views” directory (with specific subfolders for Admin, Donor, and Patient) along with the public assets (CSS, JavaScript, images). This layer manages the user interface.
- Backend (Application Layer): This consists of the Laravel framework’s Controllers (in app/Http/Controllers), Middleware (e.g., for authentication and role-based access), Requests (for handling form validation), and Services (like DistanceCalculatorServices) that encapsulate business logic.
- Models and Data Layer: Organized in the “app/Models” directory, these represent the domain entities (Admin, Donor, Patient, BloodType, City, Township, etc.), which are linked to the database via Eloquent ORM. The “database” directory contains migrations, factories, and seeders which help define and populate the underlying database schema.
- Routing and API Layer: The routes defined in “routes/web.php” and “routes/api.php” set up the endpoints that tie the HTTP requests to the appropriate controllers.
- Configuration and Environment: The “config” directory, along with environment files (.env), configures application settings like database connections, caching, session handling, etc.
- Supporting Infrastructure: Laravel’s service providers (app/Providers) and other support files (like the Bootstrap folder) show how the application bootstraps and manages its dependencies.

##### Relationships and Interactions
- The flow starts with a user request hitting routes (API or web routes), which then invokes the appropriate Controllers. These controllers enforce business logic, often utilizing Middleware for pre-processing (authentication, role checks such as Admin or Donor), and then interact with Models to perform CRUD operations.
- The Models interact with the database, which is structured through Laravel’s migration files. Database Seeders and Factories support both development and testing loops.
- Views render dynamic content for the user interface based on the data provided by the controllers.
- Services (e.g., DistanceCalculatorServices) encapsulate specialized business logic that can be reused across different controllers.

##### Architectural Patterns and Design Principles
- Model-View-Controller (MVC): The project clearly uses MVC, where Controllers handle the request logic, the Models manage data and business logic, and the Views provide the UI.
- Middleware usage: It is significant in Laravel architecture for managing cross-cutting concerns such as authentication, logging, and request sanitization.
- Service Layer Abstraction: Any business logic (e.g., distance calculations) is abstracted into dedicated service classes which allow for cleaner controllers and easier testing.
- Separation of Concerns: Different user roles (Admin, Donor, Patient) have segregated controllers and views to tailor the user experience and logic specific to each role.

##### Technology/Framework Details
- Laravel Framework: Core of the backend application.
- Blade templating: Used in “resources/views”.
- Eloquent ORM: For database interactions.
- JavaScript and CSS assets in “public” and “resources” folders.
- Composer and npm: For dependency management (composer.json and package.json).

##### Additional Elements
- Considering that this application uses role-based access control, consider a separate node or annotation to indicate authentication and authorization flows.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External entry point
    U("User Request"):::external

    %% Routing Layer
    subgraph "Routing Layer"
        WR("Web Routes"):::backend
        AR("API Routes"):::backend
    end

    %% Application Layer (Backend)
    subgraph "Application Layer"
        M("Middleware (Auth/RoleChecks)"):::backend
        C("Controllers (Admin,Donor,Patient)"):::backend
        S("Distance Calculator Service"):::backend
    end

    %% Data Layer
    subgraph "Data Layer"
        MD("Models (EloquentORM)"):::data
        D("Database (Migrations/Seeds)"):::data
    end

    %% User Interface Layer (Frontend)
    subgraph "User Interface"
        V("Views (BladeTemplates)"):::frontend
        PA("Public Assets"):::frontend
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        P("Service Providers"):::infra
        CF("Configuration Files"):::infra
        ENV("Environment File"):::infra
        T("Tests"):::infra
    end

    %% Connections: Request Flow
    U -->|"initiates"| WR
    U -->|"initiates"| AR
    WR --> M
    AR --> M
    M --> C
    C -->|"calls"| S
    C -->|"accesses"| MD
    MD --> D
    C -->|"renders"| V
    V --> PA

    %% Supporting Infrastructure Connections
    C -->|"bootstrappedBy"| P
    P --> CF
    P --> ENV

    %% Tests (side note)
    U --- T

    %% Styles
    classDef external fill:#f8f9fa,stroke:#343a40,stroke-width:2px;
    classDef frontend fill:#cce5ff,stroke:#007bff,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#28a745,stroke-width:2px;
    classDef data fill:#fff3cd,stroke:#ffc107,stroke-width:2px;
    classDef infra fill:#f8d7da,stroke:#dc3545,stroke-width:2px;

    %% Click Events
    click V "https://github.com/khantminkyi/blood_donation_management_system/tree/master/resources/views"
    click PA "https://github.com/khantminkyi/blood_donation_management_system/tree/master/public"
    click C "https://github.com/khantminkyi/blood_donation_management_system/tree/master/app/Http/Controllers"
    click M "https://github.com/khantminkyi/blood_donation_management_system/tree/master/app/Http/Middleware"
    click S "https://github.com/khantminkyi/blood_donation_management_system/blob/master/app/Services/DistanceCalculatorServices.php"
    click MD "https://github.com/khantminkyi/blood_donation_management_system/tree/master/app/Models"
    click D "https://github.com/khantminkyi/blood_donation_management_system/tree/master/database"
    click WR "https://github.com/khantminkyi/blood_donation_management_system/blob/master/routes/web.php"
    click AR "https://github.com/khantminkyi/blood_donation_management_system/blob/master/routes/api.php"
    click CF "https://github.com/khantminkyi/blood_donation_management_system/tree/master/config"
    click ENV "https://github.com/khantminkyi/blood_donation_management_system/blob/master/.env"
    click P "https://github.com/khantminkyi/blood_donation_management_system/tree/master/app/Providers"
    click T "https://github.com/khantminkyi/blood_donation_management_system/tree/master/tests"
```
