# vonhumbolt/cinevisionmicroserviceproject architecture

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

- Interactive diagram: https://gitdiagram.com/vonhumbolt/cinevisionmicroserviceproject
- Repository: https://github.com/vonhumbolt/cinevisionmicroserviceproject

## Overview

##### Main Components
- API Gateway: Acts as a front door for all client requests; it manages routing, security, and load balancing.
- Eureka Server: The service discovery component (using Netflix Eureka) where all services (API Gateway, Movie Service, User Service, and Email Service) register.
- Movie Service: Handles functionalities related to movies, including CRUD operations, movie scheduling, payments, and caching (with Redis). It uses PostgreSQL for persistence and WebFlux for inter-service communication.
- User Service: Manages user accounts including registration, authentication (utilizing JWT), and user-related operations. It uses MongoDB and Spring Security.
- Email Service: Responsible for asynchronous email notifications (triggered by movie-related actions) using Apache Kafka and Java Mail Sender along with FreeMarker for templating.
- Frontend Application: A React-based web app that interfaces with the backend via Axios, Redux for state management, and Bootstrap for styling.
- Docker & Supporting Infrastructure: Docker Compose is used to containerize dependencies (PostgreSQL, MongoDB, Kafka, Zipkin, etc.).

##### Relationships and Interactions
- The Client (web browser) communicates with the Frontend, which in turn sends REST API calls to the API Gateway.
- API Gateway forwards requests to the appropriate backend service (Movie, User, Email) based on route configurations.
- All backend services are registered with the Eureka Server for service discovery.
- Communication between services uses Spring Cloud (for direct REST or reactive WebFlux) and asynchronous messaging through Apache Kafka (for example, Movie Service sends a message to Email Service).
- Resilience4j is integrated in Movie Service (and possibly in others) to handle circuit breaking and fallback strategies.
- Zipkin and Sleuth are used across services to trace distributed operations.
- JWT-based authentication and Spring Security in the User Service protect endpoints and manage token verification across services.

##### Important Infrastructure and Patterns
- Microservices Architecture: Separate services for movies, users, email, and a centralized API gateway ensure loose coupling and scalability.
- N-Layered Architecture: Each microservice is organized using domain, service, data access, and presentation layers.
- Service Discovery and Routing: Eureka for discovery and Spring Cloud Gateway for request routing.
- Asynchronous Communication: Apache Kafka is used to decouple services (especially for sending emails from the Movie Service).
- Externalized Configuration & Containerization: Docker Compose is used to manage and run infrastructure components like databases, Kafka, and Zipkin.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend
    FE["Frontend (React, Axios, Redux, Bootstrap)"]:::frontend

    %% Backend Microservices Subgraph
    subgraph "Backend Microservices"
        APIG["API Gateway (Spring Cloud Gateway)"]:::backend
        Eureka["Eureka Server (Netflix Eureka)"]:::backend
        Movie["Movie Service (Spring Boot, WebFlux, Resilience4j, Redis, PostgreSQL)"]:::backend
        User["User Service (Spring Boot, Spring Security, JWT, MongoDB)"]:::backend
        Email["Email Service (Spring Boot, Kafka, JavaMail, FreeMarker)"]:::backend
    end

    %% Databases and Infrastructure Subgraph
    subgraph "Databases & Infrastructure"
        Postgres["PostgreSQL"]:::database
        Mongo["MongoDB"]:::database
        Redis["Redis"]:::database
        Kafka["Apache Kafka"]:::infra
        Zipkin["Zipkin & Sleuth"]:::infra
        Docker["Docker Compose"]:::infra
    end

    %% Interactions: Frontend to API Gateway
    FE -->|"REST_API_Calls"| APIG

    %% API Gateway routes requests to backend services
    APIG -->|"Route_to_Movie"| Movie
    APIG -->|"Route_to_User"| User
    APIG -->|"Route_to_Email"| Email

    %% Service Discovery (bidirectional)
    APIG <-->|"Service_Registration"| Eureka
    Movie <-->|"Service_Registration"| Eureka
    User <-->|"Service_Registration"| Eureka
    Email <-->|"Service_Registration"| Eureka

    %% Asynchronous Communication using Kafka: Movie Service to Email Service
    Movie -.->|"Kafka_Message"| Kafka
    Kafka -.->|"Delivers_Message"| Email

    %% Database interaction for Movie Service and User Service
    Movie -->|"DB_Query"| Postgres
    Movie -->|"Cache_Operation"| Redis
    User -->|"DB_Query"| Mongo

    %% Tracing for all services
    APIG -->|"Tracing"| Zipkin
    Movie -->|"Tracing"| Zipkin
    User -->|"Tracing"| Zipkin
    Email -->|"Tracing"| Zipkin

    %% Docker manages infrastructure components
    Docker ---|"Manages"| Postgres
    Docker ---|"Manages"| Mongo
    Docker ---|"Manages"| Redis
    Docker ---|"Manages"| Kafka
    Docker ---|"Manages"| Zipkin

    %% Styling classes
    classDef frontend fill:#ffefcc,stroke:#fbbc04,stroke-width:2px;
    classDef backend fill:#d1e8ff,stroke:#1a73e8,stroke-width:2px;
    classDef database fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef infra fill:#fce4ec,stroke:#d81b60,stroke-width:2px;

    %% Click Events
    click FE "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/frontend/"
    click APIG "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/api-gateway/"
    click Eureka "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/eureka-server/"
    click Movie "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/movieService/"
    click User "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/userService/"
    click Email "https://github.com/vonhumbolt/cinevisionmicroserviceproject/tree/main/emailService/"
    click Docker "https://github.com/vonhumbolt/cinevisionmicroserviceproject/blob/main/docker-compose.yml"
```
