# aelassas/microservices architecture

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

- Interactive diagram: https://gitdiagram.com/aelassas/microservices
- Repository: https://github.com/aelassas/microservices

## Overview

##### Project type and purpose
- Full-stack microservices e-commerce “store” solution built on ASP.NET Core
- Three independent backend microservices (Catalog, Cart, Identity), two API gateways (FrontendGateway, BackendGateway), two client UIs (frontend store, admin backend), shared middleware library, MongoDB per service, Docker-compose deployment, CI/CD pipelines.

##### File-structure highlights
- src/microservices: three self-contained services, each with Controllers, Models, Repositories, Startup, Dockerfile, appsettings.
- src/gateways: Ocelot-based ASP.NET Core projects for frontend and backend APIs, include JWT, CORS, HealthChecks.
- src/middlewares: common JWT builder, encryptor, request/response logging, health-check helpers.
- src/uis: two static‐HTML + vanilla JS apps served by ASP.NET Core, Dockerfiles for containerization.
- docker-compose.yml: orchestrates MongoDB, microservices, gateways, UIs.
- .github/workflows: build/test pipelines.

##### Key README insights
- Database-per-service pattern (isolated MongoDB for each microservice).
- API Gateway pattern with Ocelot (two gateways).
- JWT authentication propagated from Identity microservice, enforced by middleware.
- Health checks and centralized HealthChecksUI.
- CI via GitHub Actions, containerized deployment via Docker Compose.

– Users (Frontend User, Admin User)
– UI apps: Frontend UI, Backend UI
– API Gateways: FrontendGateway, BackendGateway
– Microservices: CatalogMS, CartMS, IdentityMS
– Databases: Mongo-Catalog, Mongo-Cart, Mongo-Identity
– Shared Middleware library (JWT, logging, encryption)
– External: GitHub Actions, Docker Registry (optional)

1. Users → UI apps (HTTP)
2. UI apps → FrontendGateway/BackendGateway (HTTP, JWT in header)
3. Gateways → respective microservices (route via Ocelot)
4. Microservices ↔ their MongoDB instance (CRUD operations)
5. IdentityMS → JWTBuilder → Gateways + other MS for auth
6. HealthChecks endpoints → HealthChecksUI
7. CI/CD: GitHub Actions → build → Docker images → Docker Registry → docker-compose

c. Architectural patterns & principles
- Microservices (single responsibility, independently deployable)
- API Gateway (Ocelot) for request routing, JWT enforcement, logging, health checks
- Database-per-service pattern for data isolation
- Stateless services + JWT auth
- Containerization (Docker multi-stage builds, docker-compose)
- CI/CD pipelines for build/test

d. Technologies & frameworks
- ASP.NET Core (microservices, gateways, UIs)
- Ocelot (API gateway)
- MongoDB (.NET driver, HealthChecks.MongoDb)
- JWT (System.IdentityModel.Tokens, custom JwtBuilder)
- Serilog (logging in gateways)
- xUnit + Moq (unit tests)
- Docker & Docker Compose
- GitHub Actions (build.yml, test.yml)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Users
    subgraph "Users"
        FU["Frontend User"]:::user
        AU["Admin User"]:::user
    end

    %% UI Layer
    subgraph "UI Layer"
        FUI["Frontend UI"]:::ui
        BUI["Backend UI"]:::ui
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        FGW["FrontendGateway"]:::gateway
        BGW["BackendGateway"]:::gateway
    end

    %% Shared Middleware
    SM["Shared Middleware\n(JWT, Logging, Encryption)"]:::middleware

    %% Service Layer
    subgraph "Microservices"
        CM["CatalogMicroservice"]:::micro
        CaM["CartMicroservice"]:::micro
        IM["IdentityMicroservice"]:::micro
    end

    %% Databases
    subgraph "Databases"
        MC["Mongo-Catalog"]:::db
        MCa["Mongo-Cart"]:::db
        MI["Mongo-Identity"]:::db
    end

    %% HealthChecks UI
    HCUI["HealthChecksUI"]:::external

    %% CI/CD and Orchestration
    GA["GitHub Actions"]:::external
    DR["Docker Registry"]:::external
    DC["Docker Compose\nOrchestration"]:::external

    %% Flows: Users to UIs
    FU -->|"HTTP"| FUI
    AU -->|"HTTP"| BUI

    %% UIs to Gateways
    FUI -->|"HTTP + JWT"| FGW
    BUI -->|"HTTP + JWT"| BGW

    %% Gateways to Shared Middleware (JWT enforcement)
    FGW -->|"validate token"| SM
    BGW -->|"validate token"| SM

    %% Gateways to Microservices
    FGW -->|"HTTP"| CM
    FGW -->|"HTTP"| CaM
    BGW -->|"HTTP"| CM
    BGW -->|"HTTP"| CaM
    BGW -->|"HTTP"| IM

    %% Microservices to Databases
    CM -->|"MongoDB Driver"| MC
    CaM -->|"MongoDB Driver"| MCa
    IM -->|"MongoDB Driver"| MI

    %% Identity issues JWT
    IM -->|"issue JWT"| SM

    %% HealthChecks
    FGW -->|"/healthz"| HCUI
    BGW -->|"/healthz"| HCUI
    CM -->|"/healthz"| HCUI
    CaM -->|"/healthz"| HCUI
    IM -->|" /healthz"| HCUI

    %% CI/CD pipeline
    GA -->|"build/test"| DR
    DR -->|"push images"| DC
    DC -->|"deploy containers"| FGW
    DC -->|"deploy containers"| BGW
    DC -->|"deploy containers"| CM
    DC -->|"deploy containers"| CaM
    DC -->|"deploy containers"| IM
    DC -->|"deploy containers"| FUI
    DC -->|"deploy containers"| BUI
    DC -->|"deploy containers"| MC
    DC -->|"deploy containers"| MCa
    DC -->|"deploy containers"| MI

    %% Click Events
    click CM "https://github.com/aelassas/microservices/tree/main/src/microservices/CatalogMicroservice"
    click CaM "https://github.com/aelassas/microservices/tree/main/src/microservices/CartMicroservice"
    click IM "https://github.com/aelassas/microservices/tree/main/src/microservices/IdentityMicroservice"
    click FGW "https://github.com/aelassas/microservices/tree/main/src/gateways/FrontendGateway"
    click BGW "https://github.com/aelassas/microservices/tree/main/src/gateways/BackendGateway"
    click SM "https://github.com/aelassas/microservices/tree/main/src/middlewares/Middleware"
    click FUI "https://github.com/aelassas/microservices/tree/main/src/uis/Frontend"
    click BUI "https://github.com/aelassas/microservices/tree/main/src/uis/Backend"
    click DC "https://github.com/aelassas/microservices/blob/main/docker-compose.yml"
    click GA "https://github.com/aelassas/microservices/blob/main/ .github/workflows/build.yml"
    click GA "https://github.com/aelassas/microservices/blob/main/ .github/workflows/test.yml"

    %% Styles
    classDef micro fill:#cce5ff,stroke:#3399ff,color:#000
    classDef gateway fill:#ffe5cc,stroke:#ff9933,color:#000
    classDef db fill:#e5ffe5,stroke:#33cc33,color:#000
    classDef ui fill:#f3e5ff,stroke:#9933ff,color:#000
    classDef middleware fill:#e0e0e0,stroke:#888888,color:#000
    classDef user fill:#f0f0f0,stroke:#666666,color:#000
    classDef external fill:#ffe6e6,stroke:#ff4d4d,color:#000
```
