# shek-a/membership-app architecture

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

- Interactive diagram: https://gitdiagram.com/shek-a/membership-app
- Repository: https://github.com/shek-a/membership-app

## Overview

##### Main Components

A. External Layer (Client Interface)
- REST API Endpoints (/member endpoints)
- Supported HTTP methods (GET, POST, PUT, DELETE)

B. Application Layers (following the clean architecture pattern):
1. Handler Layer (Controllers)
- Located in pkg/handler
- Handles HTTP requests/responses
- Input validation and response formatting

2. Service Layer (Business Logic)
- Located in pkg/service
- Contains core business logic
- Member operations implementation

3. Repository Layer (Data Access)
- Located in pkg/repository
- Database operations
- MongoDB interactions

C. Database Layer
- MongoDB instance
- Connection and data flow

D. Supporting Components
- Utils package (pkg/utils)
- Models package (pkg/models)

**[Client Requests] → [REST API Layer]**
- ↓
**[Handler Layer (pkg/handler)]**
- ↓
**[Service Layer (pkg/service)]**
- ↓
**[Repository Layer (pkg/repository)]**
- ↓
**[MongoDB Database]**

##### Important Details

A. Component Responsibilities:
- Handler: Request/Response handling, routing (routes.go)
- Service: Business logic, member operations
- Repository: Data persistence operations
- Utils: Support functions (date, email, ID generation)

B. Data Flow:
- How member data flows through the system
- Request/response transformations
- Validation points

C. Infrastructure:
- Docker container boundaries
- Network ports (8080 for API, 27017 for MongoDB)

##### Specific Implementation Notes

- The application follows a clear separation of concerns
- Each layer has its own test files
- Utility functions are separated into specific domains (date, email, ID generation)
- Docker composition manages service orchestration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Layer
    Client(["Client Requests"])
    subgraph API["REST API Layer"]
        direction TB
        GET["/member GET"]:::api
        POST["/member POST"]:::api
        PUT["/member PUT"]:::api
        DELETE["/member DELETE"]:::api
    end

    %% Application Layers
    subgraph AppLayers["Application Layers"]
        direction TB
        subgraph Handler["Handler Layer"]
            direction TB
            MH["Member Handler"]:::handler
            Routes["Routes"]:::handler
        end

        subgraph Service["Service Layer"]
            direction TB
            MS["Member Service"]:::service
        end

        subgraph Repository["Repository Layer"]
            direction TB
            MR["Member Repository"]:::repository
        end
    end

    %% Database Layer
    DB[(MongoDB)]:::database

    %% Supporting Components
    subgraph Support["Supporting Components"]
        direction TB
        subgraph Models["Models"]
            direction TB
            MM["Member Model"]:::model
            RM["Response Model"]:::model
        end

        subgraph Utils["Utilities"]
            direction TB
            DateUtils["Date Utils"]:::util
            EmailUtils["Email Utils"]:::util
            IDGen["ID Generator"]:::util
        end
    end

    %% Connections
    Client --> API
    GET & POST & PUT & DELETE --> MH
    MH --> MS
    MS --> MR
    MR --> DB
    MS --> Models
    MH --> Utils

    %% Click Events
    click Routes "https://github.com/shek-a/membership-app/blob/main/internal/routes/routes.go"
    click MH "https://github.com/shek-a/membership-app/blob/main/pkg/handler/member.go"
    click MS "https://github.com/shek-a/membership-app/blob/main/pkg/service/member.go"
    click MR "https://github.com/shek-a/membership-app/blob/main/pkg/repository/member.go"
    click MM "https://github.com/shek-a/membership-app/blob/main/pkg/models/member.go"
    click RM "https://github.com/shek-a/membership-app/blob/main/pkg/models/response.go"
    click DateUtils "https://github.com/shek-a/membership-app/blob/main/pkg/utils/date_utils.go"
    click EmailUtils "https://github.com/shek-a/membership-app/blob/main/pkg/utils/email_utils.go"
    click IDGen "https://github.com/shek-a/membership-app/blob/main/pkg/utils/id_generator.go"

    %% Styles
    classDef api fill:#2374ab,color:#fff,stroke:#000
    classDef handler fill:#57a773,color:#fff,stroke:#000
    classDef service fill:#57a773,color:#fff,stroke:#000
    classDef repository fill:#57a773,color:#fff,stroke:#000
    classDef database fill:#ffd166,color:#000,stroke:#000
    classDef model fill:#d3d3d3,color:#000,stroke:#000
    classDef util fill:#d3d3d3,color:#000,stroke:#000

    %% Legend
    subgraph Legend
        direction TB
        API_L["API Endpoint"]:::api
        Handler_L["Application Layer"]:::handler
        DB_L[(Database)]:::database
        Support_L["Supporting Component"]:::util
    end
```
