# aymanamkassou/distributed-systems-project architecture

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

- Interactive diagram: https://gitdiagram.com/aymanamkassou/distributed-systems-project
- Repository: https://github.com/aymanamkassou/distributed-systems-project

## Overview

##### Project Type and Purpose
- The project is a dockerized full-stack application consisting of three primary services. Two of the services (Frontend Service and Gallery Service) are built with Next.js to provide responsive user interfaces, while the Image Service is a Node.js/Express backend that interacts with the Unsplash API and MongoDB.
- The purpose of the project is to fetch and display images from Unsplash: the Frontend Service presents images acquired via the Image Service and the Gallery Service displays and syncs images stored in MongoDB.

##### File Structure and Key Architectural Insights
- The top-level file structure shows:
- A single .env file and docker-compose.yml in the root, indicating that Docker Compose is used to orchestrate the microservices.
- Three primary directories for services: "frontend", "gallery-service", and "image-service".
- Inside each service folder:
- Frontend: Contains Next.js specific files, API routes, components, and configurations.
- Gallery Service: Similar to Frontend in structure but includes components like SyncButton, and services like imageService indicating actions to trigger fetching/syncing of images.
- Image Service: Uses Node.js/Express with a “src” folder organizing configuration, models, routes, and services for handling communication with Unsplash API and MongoDB.
- The README confirms the role and port assignments for each service:
- Frontend on port 3000,
- Image Service on port 3001,
- Gallery Service on port 3002.

##### Elements to be Included
- Each component must be clearly labeled:
- “Frontend Service (Next.js) – Port 3000”
- “Gallery Service (Next.js) – Port 3002”
- “Image Service (Node.js/Express) – Port 3001”
- “MongoDB Database”
- “Unsplash API”
- “Docker Compose” as a container manager.
- From Frontend Service → Image Service (indicating API calls to fetch images).
- From Gallery Service → Image Service and/or MongoDB (for image syncing and retrieval).
- From Image Service → Unsplash API (data fetching process).
- From Image Service → MongoDB (CRUD operations for image storage).
- Incorporate annotations:
- Port assignments and any critical operations (e.g., “Sync images”, “Fetch from Unsplash”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    D["Docker Compose"]:::docker
    C["Configuration (.env)"]:::config

    subgraph "Frontend Service (Next.js) – Port 3000"
        FE["Frontend Service (Next.js)"]
        FE1["page.tsx"]:::file
        FE2["unsplash route"]:::file
        FE3["ClientImageGallery"]:::file
        FE4["ImageGallery"]:::file
        FE --> FE1
        FE --> FE2
        FE --> FE3
        FE --> FE4
    end

    subgraph "Gallery Service (Next.js) – Port 3002"
        GS["Gallery Service (Next.js)"]
        GS1["page.tsx"]:::file
        GS2["ImageGallery"]:::file
        GS3["SyncButton"]:::file
        GS4["imageService"]:::file
        GS --> GS1
        GS --> GS2
        GS --> GS3
        GS --> GS4
    end

    subgraph "Image Service (Node.js/Express) – Port 3001"
        IS["Image Service (Node.js/Express)"]
        IS1["index.ts"]:::file
        IS2["imageRoutes"]:::file
        IS3["unsplashService"]:::file
        IS4["imageDbService"]:::file
        IS5["ImageModel"]:::file
        IS --> IS1
        IS --> IS2
        IS --> IS3
        IS --> IS4
        IS --> IS5
    end

    DB["MongoDB Database"]:::database
    US["Unsplash API"]:::external

    %% Docker Compose manages services
    C -->|"configures"| D
    D -->|"managed_container"| FE
    D -->|"managed_container"| GS
    D -->|"managed_container"| IS

    %% Service Interactions
    FE -->|"Fetch_images"| IS
    GS -->|"Sync_images"| IS
    GS -->|"Retrieve_images"| DB
    IS -->|"CRUD_operations"| DB
    IS -->|"Fetch_from_Unsplash"| US

    %% Click Events for Frontend Service
    click FE "https://github.com/aymanamkassou/distributed-systems-project/tree/main/frontend"
    click FE1 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/frontend/app/page.tsx"
    click FE2 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/frontend/app/api/unsplash/route.ts"
    click FE3 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/frontend/app/components/ClientImageGallery.tsx"
    click FE4 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/frontend/app/components/ImageGallery.tsx"

    %% Click Events for Gallery Service
    click GS "https://github.com/aymanamkassou/distributed-systems-project/tree/main/gallery-service"
    click GS1 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/gallery-service/app/page.tsx"
    click GS2 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/gallery-service/app/components/ImageGallery.tsx"
    click GS3 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/gallery-service/app/components/SyncButton.tsx"
    click GS4 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/gallery-service/app/services/imageService.ts"

    %% Click Events for Image Service
    click IS "https://github.com/aymanamkassou/distributed-systems-project/tree/main/image-service"
    click IS1 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/image-service/src/index.ts"
    click IS2 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/image-service/src/routes/imageRoutes.ts"
    click IS3 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/image-service/src/services/unsplashService.ts"
    click IS4 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/image-service/src/services/imageDbService.ts"
    click IS5 "https://github.com/aymanamkassou/distributed-systems-project/blob/main/image-service/src/models/ImageModel.ts"

    %% Click Events for Docker Compose and Config
    click D "https://github.com/aymanamkassou/distributed-systems-project/blob/main/docker-compose.yml"
    click C "https://github.com/aymanamkassou/distributed-systems-project/blob/main/.env"

classDef docker fill:#FFA500,stroke:#333,stroke-width:2px;
classDef config fill:#D3D3D3,stroke:#333,stroke-width:2px;
classDef nextjs fill:#ADD8E6,stroke:#333,stroke-width:2px;
classDef nodejs fill:#90EE90,stroke:#333,stroke-width:2px;
classDef database fill:#FDFD96,stroke:#333,stroke-width:2px;
classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px;
classDef file fill:#E0E0E0,stroke:#333,stroke-width:1px, font-size:10px;

class FE,GS nextjs;
class IS nodejs;
```
