# emash90/wama_microservices architecture

> Architecture diagram of the GitHub repository emash90/wama_microservices, 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/emash90/wama_microservices
- Repository: https://github.com/emash90/wama_microservices

## Overview

##### Project Type & Purpose
- This is a containerized microservices architecture aimed at Rental Property Management. It handles tenant management, house management, and payment management.
- The system uses an API Gateway to route external requests to individual backend services. It also leverages RabbitMQ for messaging between services (e.g., for updating house occupancy when tenants are added) and is deployed using container technologies (Docker) on Google Cloud Run.

##### Analyzing the File Structure
- The “backend” directory is subdivided into several microservices:
- API Gateway: Routes incoming API requests, contains middleware and route definitions.
- Tenant, House, Payment, (and User) Services: Each service has its own controllers, models, routes, and a service layer. Each service contains its configuration (including database connection files), utility functions (such as RabbitMQ setups), and Docker configuration.
- There are multiple frontend projects (React-based, Next.js-based, and plain React projects) that suggest different UI implementations to interact with the backend.
- Presence of Dockerfiles, docker-compose.yml, and GitHub workflows indicates containerization, CI/CD practices, and cloud deployment.

##### Key Components
a. Frontend(s):

b. API Gateway:
- A central component that receives incoming requests from the frontends and routes them to the appropriate microservice.

c. Microservices:
- Tenant Service: Handles tenant-related operations.
- House Service: Manages property data, occupancy status, and house details.
- Payment Service: Tracks rental payments and financial reporting.
- User Service: Manages user authentication and authorization (if applicable).
- Each microservice should be noted as having its own internal layers such as controllers, routes, services, and models.
- That each service contains its own database configuration (likely connecting to a dedicated or shared database instance).

d. Message Broker:
- RabbitMQ is used for inter-service messaging to update state changes (for example, updating house occupancy status when tenants change).

e. Deployment & Infrastructure:
- Containerization (Docker) for each service.
- Google Cloud Run which hosts the services for scalability and availability.
- CI/CD pipelines indicated by GitHub workflows (for deployment automation).

##### Relationships and Interactions
- The Frontend sends requests to the API Gateway.
- The API Gateway routes these requests to the appropriate backend microservices (Tenant, House, Payment, User).
- Microservices may communicate with each other asynchronously via RabbitMQ for operations such as updating house occupancy after a tenant event.
- Each microservice interacts with its own database layer (or a designated datastore).
- The deployment layer wraps around these components showing Docker containers orchestrated by Docker Compose and hosted on Google Cloud Run.

##### Architectural Patterns & Design Principles
- Microservices Architecture: Each functional area is independent and containerized.
- API Gateway Pattern: A dedicated gateway that simplifies client communication and abstracts the underlying service structure.
- Event-Driven Communication: Use of RabbitMQ for asynchronous inter-service messaging.
- Containerization & Cloud Deployment: Every service is containerized, ensuring consistency across environments and deployed on a scalable cloud platform.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        FN1["Frontend (React)"]:::frontend
        FN2["Frontend (Next.js)"]:::frontend
        FN3["Frontend (Plain React)"]:::frontend
    end

    %% API Gateway
    API_Gateway["API Gateway"]:::gateway

    %% Backend Microservices
    subgraph "Backend Microservices"
        Tenant_Service["Tenant Service"]:::microservice
        House_Service["House Service"]:::microservice
        Payment_Service["Payment Service"]:::microservice
        User_Service["User Service"]:::microservice
    end

    %% Databases for each service
    subgraph "Databases"
        DB_Tenant["Tenant Database"]:::database
        DB_House["House Database"]:::database
        DB_Payment["Payment Database"]:::database
        DB_User["User Database"]:::database
    end

    %% Message Broker
    subgraph "Message Broker"
        RabbitMQ["RabbitMQ"]:::messaging
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        Docker["Docker Containers"]:::deployment
        CloudRun["Google Cloud Run"]:::deployment
        CI_CD["CI/CD Pipeline"]:::deployment
    end

    %% Data Flow: Frontend to API Gateway
    FN1 -->|"RESTCall"| API_Gateway
    FN2 -->|"RESTCall"| API_Gateway
    FN3 -->|"RESTCall"| API_Gateway

    %% Data Flow: API Gateway to Microservices
    API_Gateway -->|"Routes"| Tenant_Service
    API_Gateway -->|"Routes"| House_Service
    API_Gateway -->|"Routes"| Payment_Service
    API_Gateway -->|"Routes"| User_Service

    %% Service to Database connections
    Tenant_Service -->|"DB Connection"| DB_Tenant
    House_Service -->|"DB Connection"| DB_House
    Payment_Service -->|"DB Connection"| DB_Payment
    User_Service -->|"DB Connection"| DB_User

    %% Asynchronous Messaging via RabbitMQ
    Tenant_Service -->|"Publish"| RabbitMQ
    RabbitMQ -->|"Notify"| House_Service
    Payment_Service -->|"Publish"| RabbitMQ
    RabbitMQ -->|"Acknowledge"| Payment_Service

    %% Deployment: Services packaged in Docker containers
    API_Gateway -->|"Packaged"| Docker
    Tenant_Service -->|"Packaged"| Docker
    House_Service -->|"Packaged"| Docker
    Payment_Service -->|"Packaged"| Docker
    User_Service -->|"Packaged"| Docker
    FN1 -->|"Packaged"| Docker
    FN2 -->|"Packaged"| Docker
    FN3 -->|"Packaged"| Docker

    %% Deployment: Docker containers hosted on Google Cloud Run
    Docker -->|"Deployed to"| CloudRun
    CI_CD -->|"Automates"| Docker

    %% Click Events
    click FN1 "https://github.com/emash90/wama_microservices/tree/main/react-frontend"
    click FN2 "https://github.com/emash90/wama_microservices/tree/main/next-frontend"
    click FN3 "https://github.com/emash90/wama_microservices/tree/main/frontend"
    click API_Gateway "https://github.com/emash90/wama_microservices/tree/main/backend/api-gateway"
    click Tenant_Service "https://github.com/emash90/wama_microservices/tree/main/backend/tenant"
    click House_Service "https://github.com/emash90/wama_microservices/tree/main/backend/house"
    click Payment_Service "https://github.com/emash90/wama_microservices/tree/main/backend/payment"
    click User_Service "https://github.com/emash90/wama_microservices/tree/main/backend/user"
    click RabbitMQ "https://github.com/emash90/wama_microservices/blob/main/backend/tenant/utils/rabbitmq.js"
    click Docker "https://github.com/emash90/wama_microservices/tree/main/backend/api-gateway/Dockerfile"
    click CI_CD "https://github.com/emash90/wama_microservices/blob/main/.github/workflows/deploy.yaml"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef gateway fill:#FCF3CF,stroke:#B7950B,stroke-width:2px;
    classDef microservice fill:#ABEBC6,stroke:#239B56,stroke-width:2px;
    classDef messaging fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef deployment fill:#F5CBA7,stroke:#D35400,stroke-width:2px;
    classDef database fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
