# deontaljaard/http4s-mongo architecture

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

- Interactive diagram: https://gitdiagram.com/deontaljaard/http4s-mongo
- Repository: https://github.com/deontaljaard/http4s-mongo

## Overview

##### Component Breakdown

API Layer (Http4sMongoServer):
- HelloRs
- PersonRs
- FileRs
- AuthRs
- Use rounded rectangles for the endpoints
- Routes (/hello, /persons, /files, /login)

Service Layer:
- Create two main service components:
- PersonService
- FileService
- Validation components:
- PersonValidatorNel
- ValidationError

Data Access Layer:
- Split into two main sections:
1. MongoDB Components:
- AsyncMongoClient
- ReactiveMongoClient
- PersonRepository
2. File Storage Components:
- S3Client
- FileRepository
- FileMetadata

##### Additional Elements

- Configuration (AppConfig)
- Common utilities
- Authentication components
- Validation components

##### Technical Details

Annotations showing:
- HTTP4S server configuration
- MongoDB connection details
- S3 client configuration
- Authentication flow

##### Specific Implementation Details

Notes for:
- Scala-specific features
- Functional programming patterns
- Error handling flow
- Validation chains

##### Infrastructure Notes

A small section showing:
- Docker container relationship
- MongoDB connection string variations
- Java 9+ compatibility notes

Remember to emphasize:
- The purely functional nature of HTTP4S
- The async/reactive MongoDB client usage
- The file handling flow with S3
- The authentication mechanism
- The validation patterns

This will give other engineers a clear understanding of both the overall architecture and the specific implementation patterns used in this reference project.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Client1[HTTP/REST Client]
    end

    subgraph API["API Layer"]
        HTTP[HTTP4S Server]:::server
        click HTTP "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/server/Http4sMongoServer.scala"
        
        subgraph Endpoints
            Hello["/hello - HelloRs"]:::endpoint
            Person["/persons - PersonRs"]:::endpoint
            File["/files - FileRs"]:::endpoint
            Auth["/login - AuthRs"]:::endpoint
            
            click Hello "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/services/hello/HelloRs.scala"
            click Person "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/services/person/PersonRs.scala"
            click File "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/services/file/FileRs.scala"
            click Auth "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/services/auth/AuthRs.scala"
        end
    end

    subgraph Services["Service Layer"]
        PS[Person Service]:::service
        FS[File Service]:::service
        
        click PS "https://github.com/deontaljaard/http4s-mongo/blob/master/core/src/main/scala/core/person/PersonService.scala"
        click FS "https://github.com/deontaljaard/http4s-mongo/blob/master/core/src/main/scala/core/file/FileService.scala"
        
        subgraph Validation
            PV[Person Validator]:::validator
            VE[Validation Error]:::validator
            
            click PV "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/person/validation/PersonValidatorNel.scala"
            click VE "https://github.com/deontaljaard/http4s-mongo/blob/master/service/src/main/scala/services/validation/ValidationError.scala"
        end
    end

    subgraph Data["Data Access Layer"]
        subgraph MongoDB
            AMC[Async Mongo Client]:::db
            RMC[Reactive Mongo Client]:::db
            PR[Person Repository]:::repo
            
            click AMC "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/mongodb/clients/async/AsyncMongoClientFactory.scala"
            click RMC "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/mongodb/clients/reactive/ReactiveMongoClientFactory.scala"
            click PR "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/person/PersonRepository.scala"
        end
        
        subgraph Storage
            S3[S3 Client]:::storage
            FR[File Repository]:::repo
            FM[File Metadata]:::data
            
            click S3 "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/file/storage/clients/s3/S3ClientFactory.scala"
            click FR "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/file/FileRepository.scala"
            click FM "https://github.com/deontaljaard/http4s-mongo/blob/master/model/src/main/scala/model/file/FileMetaData.scala"
        end
    end

    subgraph Config
        AC[App Config]:::config
        click AC "https://github.com/deontaljaard/http4s-mongo/blob/master/common/src/main/scala/common/AppConfig.scala"
    end

    %% Connections
    Client1 --> HTTP
    HTTP --> Hello & Person & File & Auth
    Hello & Person & File & Auth --> PS & FS
    PS --> PV
    PV --> VE
    PS --> PR
    FS --> FR
    PR -.-> AMC & RMC
    FR -.-> S3
    AC --> HTTP & AMC & RMC & S3

    %% Styles
    classDef endpoint fill:#3498db,stroke:#2980b9,color:white
    classDef service fill:#2ecc71,stroke:#27ae60,color:white
    classDef validator fill:#e74c3c,stroke:#c0392b,color:white
    classDef db fill:#9b59b6,stroke:#8e44ad,color:white
    classDef storage fill:#e67e22,stroke:#d35400,color:white
    classDef repo fill:#f1c40f,stroke:#f39c12,color:black
    classDef config fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef server fill:#34495e,stroke:#2c3e50,color:white
    classDef data fill:#1abc9c,stroke:#16a085,color:white

    %% Legend
    subgraph Legend
        L1[API Endpoint]:::endpoint
        L2[Service]:::service
        L3[Validator]:::validator
        L4[Database]:::db
        L5[Storage]:::storage
        L6[Repository]:::repo
        L7[Configuration]:::config
        L8[Server]:::server
        L9[Data Model]:::data
    end
```
