# abdulkarim1422/bloodsapp architecture

> Architecture diagram of the GitHub repository abdulkarim1422/bloodsapp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdulkarim1422/bloodsapp
- Repository: https://github.com/abdulkarim1422/bloodsapp

## Overview

##### Main Components

a. Client Layer:
- HTML Templates (from /templates directory)
- Static Assets (CSS/JS)
- Client-side JavaScript for form handling and interactions

b. API/Web Layer:
- Gin Web Framework
- Router Layer (/routers)
- Middleware Layer (/middlewares)
- Handler Layer (/handlers)

c. Service Layer (/services):
- Authentication Service
- Donation Service
- Matching Service
- Email Service
- Location Service
- HTML Rendering Service

d. Repository Layer (/repositories):
- Auth Repository
- Donor Repository
- Patient Repository
- Request Repository

e. Data Layer:
- PostgreSQL Database
- GORM ORM
- Models (/models)

f. External Services:
- Email System
- Location Services

**[Client Layer] → [API Layer] → [Service Layer] → [Repository Layer] → [Data Layer]**
- ↑               ↕               ↓
- [Middleware]    [External Services]  [Models]

##### Specific Component Details

a. Client Layer:
- Main templates (dashboard, forms, match results)
- Static asset management
- JavaScript modules for form handling and matching

b. API Layer:
- Route groups (auth, donate, donor, patient, match)
- Middleware integration (auth, methods)
- Handler flow

c. Service Layer:
- Related services (auth, donation, matching)
- Email and feedback service integration
- Location services

d. Repository Layer:
- CRUD operations for each entity
- Relationship with models
- Database interactions

e. Data Layer:
- Database schema relationships
- Model structures
- GORM integration

##### Authentication Flow
**Login Template → Auth Handler → Auth Service → Auth Repository → Database**

##### Donation Matching Flow
**Match Form → Match Handler → Match Service →**
**Donor/Patient Repositories → Database**

##### Feedback Flow
**Service Layer → Feedback Service → Email Service → External Email Provider**

##### Technical Stack Callouts

- Gin framework integration
- PostgreSQL and GORM interaction
- Template rendering system
- External service integration points

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Templates["HTML Templates"]:::client
        StaticCSS["Static CSS"]:::client
        StaticJS["Static JavaScript"]:::client
        LocationData["Location Data"]:::client
    end

    subgraph API
        Router["Router Layer"]:::api
        Handlers["Handler Layer"]:::api
        Middleware["Middleware Layer"]:::api
        APIDoc["API Documentation"]:::api
    end

    subgraph Services
        AuthService["Authentication Service"]:::service
        DonationService["Donation Service"]:::service
        MatchingService["Matching Service"]:::service
        EmailService["Email Service"]:::service
        LocationService["Location Service"]:::service
        HTMLService["HTML Rendering Service"]:::service
        FeedbackService["Feedback Service"]:::service
    end

    subgraph Repositories
        AuthRepo["Auth Repository"]:::repo
        DonorRepo["Donor Repository"]:::repo
        PatientRepo["Patient Repository"]:::repo
        RequestRepo["Request Repository"]:::repo
    end

    subgraph Data
        DB["PostgreSQL Database"]:::data
        DBConfig["Database Configuration"]:::data
        DBSchema["Database Schema"]:::data
        DBInit["Database Initializer"]:::data
        
        subgraph Models
            UserModel["User Model"]:::model
            DonorModel["Donor Model"]:::model
            PatientModel["Patient Model"]:::model
            RequestModel["Request Model"]:::model
            AddressModel["Address Model"]:::model
        end
    end

    subgraph Config
        EnvConfig["Environment Config"]:::config
        EnvLoader["Environment Loader"]:::config
        Logger["Logger"]:::config
        DBMigration["Database Migration"]:::config
    end

    subgraph External
        EmailProvider["Email Provider"]:::external
        LocationProvider["Location Provider"]:::external
    end

    %% Relationships
    Templates --> Router
    StaticCSS --> Templates
    StaticJS --> Templates
    LocationData --> LocationService

    Router --> Handlers
    Middleware --> Handlers
    Handlers --> AuthService
    Handlers --> DonationService
    Handlers --> MatchingService
    Handlers --> HTMLService

    AuthService --> AuthRepo
    DonationService --> DonorRepo
    DonationService --> RequestRepo
    MatchingService --> DonorRepo
    MatchingService --> PatientRepo
    EmailService --> EmailProvider
    LocationService --> LocationProvider
    FeedbackService --> EmailService

    AuthRepo --> DB
    DonorRepo --> DB
    PatientRepo --> DB
    RequestRepo --> DB

    DB --> Models
    DBConfig --> DB
    DBSchema --> DB
    DBInit --> DB

    EnvConfig --> EnvLoader
    Logger --> Services
    DBMigration --> DB

    %% Click Events
    click Templates "https://github.com/abdulkarim1422/BloodsApp/blob/main/templates/*.html"
    click StaticCSS "https://github.com/abdulkarim1422/BloodsApp/tree/main/templates/css/"
    click StaticJS "https://github.com/abdulkarim1422/BloodsApp/tree/main/templates/js/"
    click LocationData "https://github.com/abdulkarim1422/BloodsApp/blob/main/templates/cities.json"
    click Router "https://github.com/abdulkarim1422/BloodsApp/tree/main/routers/"
    click Handlers "https://github.com/abdulkarim1422/BloodsApp/tree/main/handlers/"
    click Middleware "https://github.com/abdulkarim1422/BloodsApp/tree/main/middlewares/"
    click APIDoc "https://github.com/abdulkarim1422/BloodsApp/tree/main/docs/"
    click AuthService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/auth.go"
    click DonationService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/donate.go"
    click MatchingService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/match.go"
    click EmailService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/mail.go"
    click LocationService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/location.go"
    click HTMLService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/html.go"
    click FeedbackService "https://github.com/abdulkarim1422/BloodsApp/blob/main/services/feedback.go"
    click AuthRepo "https://github.com/abdulkarim1422/BloodsApp/blob/main/repositories/auth.go"
    click DonorRepo "https://github.com/abdulkarim1422/BloodsApp/blob/main/repositories/donor.go"
    click PatientRepo "https://github.com/abdulkarim1422/BloodsApp/blob/main/repositories/patient.go"
    click RequestRepo "https://github.com/abdulkarim1422/BloodsApp/blob/main/repositories/request.go"
    click DBConfig "https://github.com/abdulkarim1422/BloodsApp/blob/main/db/db.go"
    click DBSchema "https://github.com/abdulkarim1422/BloodsApp/blob/main/db/db.sql"
    click DBInit "https://github.com/abdulkarim1422/BloodsApp/blob/main/initializers/database.go"
    click UserModel "https://github.com/abdulkarim1422/BloodsApp/blob/main/models/user.go"
    click DonorModel "https://github.com/abdulkarim1422/BloodsApp/blob/main/models/donor.go"
    click PatientModel "https://github.com/abdulkarim1422/BloodsApp/blob/main/models/patient.go"
    click RequestModel "https://github.com/abdulkarim1422/BloodsApp/blob/main/models/request.go"
    click AddressModel "https://github.com/abdulkarim1422/BloodsApp/blob/main/models/addresses.go"
    click EnvConfig "https://github.com/abdulkarim1422/BloodsApp/blob/main/.env.example"
    click EnvLoader "https://github.com/abdulkarim1422/BloodsApp/blob/main/initializers/loadEnv.go"
    click Logger "https://github.com/abdulkarim1422/BloodsApp/blob/main/lib/logger.go"
    click DBMigration "https://github.com/abdulkarim1422/BloodsApp/blob/main/migrate/migrate.go"

    %% Styles
    classDef client fill:#2196F3,stroke:#1565C0,color:white
    classDef api fill:#4CAF50,stroke:#2E7D32,color:white
    classDef service fill:#FFC107,stroke:#FFA000,color:black
    classDef repo fill:#FF9800,stroke:#F57C00,color:white
    classDef data fill:#F44336,stroke:#D32F2F,color:white
    classDef model fill:#E91E63,stroke:#C2185B,color:white
    classDef config fill:#9C27B0,stroke:#7B1FA2,color:white
    classDef external fill:#673AB7,stroke:#512DA8,color:white
```
