# evt/rest-api-example architecture

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

- Interactive diagram: https://gitdiagram.com/evt/rest-api-example
- Repository: https://github.com/evt/rest-api-example

## Overview

##### Main Components

a) Client Layer:
- External clients (Postman, other API consumers)
- HTTP/REST interface entry point

b) API Layer:
- Echo Framework as the web server
- Controllers (/controller directory)
- Request/Response handling

c) Service Layer:
- Business logic services (/service directory)
- File content service
- File meta service
- User service

d) Storage Layer:
- Multiple storage implementations:
- PostgreSQL (/store/pg)
- MySQL (/store/mysql)
- Google Cloud Storage (/store/gcloud)
- Local storage option (/store/local)

**[External Clients]**
- ↓
**[API Layer (Echo Framework)]**
- ↓
**[Controllers]**
- ↓
**[Services]**
- ↓
**[Repository Interface]**
- ↓
**[Storage Implementations]**

##### Specific Implementation Details

**a) Controller Layer:**
- FileController
- UserController
- → Connected to their respective services

**b) Service Layer:**
- FileContentService
- FileMetaService
- UserService
- → Connected to repository interfaces

**c) Storage Layer (show parallel implementations):**
- PostgreSQL
- MySQL
- Google Cloud Storage
- Local Storage

##### Additional Elements

- Configuration management (config package)
- Error handling flow (lib/error)
- Validation components (lib/validator)
- Logging system (logger package)

##### Important Notes

- Clean Architecture layers with clear boundaries
- How the repository pattern allows for multiple storage implementations
- Where mocks are used for testing
- Migration handling for databases
- How environment configuration flows through the system

##### Technical Details to Highlight

- Echo framework as the main HTTP server
- Database migrations system
- Authentication flow (if present)
- File handling capabilities (both metadata and content)
- Testing boundaries using mocks

This system design should clearly communicate how the application handles both user management and file operations while maintaining flexibility in storage solutions through the repository pattern.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph Clients
        Client["External Clients"]:::client
        Postman["Postman Collection"]:::client
    end
    click Postman "https://github.com/evt/rest-api-example/blob/main/postman/REST API Example.postman_collection.json"

    %% API Layer
    subgraph API
        MainAPI["API Entry Point"]:::api
        Echo["Echo Framework"]:::api
    end
    click MainAPI "https://github.com/evt/rest-api-example/blob/main/cmd/api/main.go"

    %% Controller Layer
    subgraph Controllers
        FileController["File Controller"]:::controller
        UserController["User Controller"]:::controller
    end
    click FileController "https://github.com/evt/rest-api-example/blob/main/controller/file.go"
    click UserController "https://github.com/evt/rest-api-example/blob/main/controller/users.go"

    %% Service Layer
    subgraph Services
        ServiceManager["Service Manager"]:::service
        FileContentSvc["File Content Service"]:::service
        FileMetaSvc["File Meta Service"]:::service
        UserSvc["User Service"]:::service
    end
    click ServiceManager "https://github.com/evt/rest-api-example/blob/main/service/manager.go"
    click FileContentSvc "https://github.com/evt/rest-api-example/blob/main/service/file_content.go"
    click FileMetaSvc "https://github.com/evt/rest-api-example/blob/main/service/file_meta.go"
    click UserSvc "https://github.com/evt/rest-api-example/blob/main/service/user.go"

    %% Repository Interface
    RepoInterface["Repository Interfaces"]:::repo
    click RepoInterface "https://github.com/evt/rest-api-example/blob/main/store/repositories.go"

    %% Storage Layer
    subgraph Storage
        direction TB
        PostgreSQL["PostgreSQL"]:::storage
        MySQL["MySQL"]:::storage
        GCloud["Google Cloud Storage"]:::storage
        Local["Local Storage"]:::storage
    end
    click PostgreSQL "https://github.com/evt/rest-api-example/tree/main/store/pg"
    click MySQL "https://github.com/evt/rest-api-example/tree/main/store/mysql"
    click GCloud "https://github.com/evt/rest-api-example/tree/main/store/gcloud"
    click Local "https://github.com/evt/rest-api-example/tree/main/store/local"

    %% Supporting Components
    subgraph Support
        Config["Configuration"]:::support
        ErrorHandler["Error Handling"]:::support
        Validator["Validation"]:::support
        Logger["Logging System"]:::support
    end
    click Config "https://github.com/evt/rest-api-example/blob/main/config/config.go"
    click ErrorHandler "https://github.com/evt/rest-api-example/blob/main/lib/error/error.go"
    click Validator "https://github.com/evt/rest-api-example/blob/main/lib/validator/validator.go"
    click Logger "https://github.com/evt/rest-api-example/blob/main/logger/logger.go"

    %% Domain Models
    subgraph Models
        FileModel["File Model"]:::model
        UserModel["User Model"]:::model
    end
    click FileModel "https://github.com/evt/rest-api-example/blob/main/model/file.go"
    click UserModel "https://github.com/evt/rest-api-example/blob/main/model/user.go"

    %% Testing Components
    subgraph Testing
        ServiceMocks["Service Mocks"]:::testing
        StoreMocks["Store Mocks"]:::testing
    end
    click ServiceMocks "https://github.com/evt/rest-api-example/tree/main/service/mocks"
    click StoreMocks "https://github.com/evt/rest-api-example/tree/main/store/mocks"

    %% Relationships
    Client --> MainAPI
    Postman --> MainAPI
    MainAPI --> Echo
    Echo --> FileController & UserController
    FileController --> ServiceManager
    UserController --> ServiceManager
    ServiceManager --> FileContentSvc & FileMetaSvc & UserSvc
    FileContentSvc & FileMetaSvc & UserSvc --> RepoInterface
    RepoInterface --> PostgreSQL & MySQL & GCloud & Local

    %% Styling
    classDef client fill:#2374ab
    classDef api fill:#48a9a6
    classDef controller fill:#4ad66d
    classDef service fill:#4ad66d
    classDef repo fill:#e4cc37
    classDef storage fill:#9381ff
    classDef support fill:#f06449
    classDef model fill:#06d6a0
    classDef testing fill:#ef767a

    %% Legend
    subgraph Legend
        L1["Client Layer"]:::client
        L2["API Layer"]:::api
        L3["Application Layer"]:::controller
        L4["Repository Layer"]:::repo
        L5["Storage Layer"]:::storage
        L6["Support Components"]:::support
        L7["Domain Models"]:::model
        L8["Testing Components"]:::testing
    end
```
