# junioranheu/mongo-and-redis-playground-api architecture

> Architecture diagram of the GitHub repository junioranheu/mongo-and-redis-playground-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/junioranheu/mongo-and-redis-playground-api
- Repository: https://github.com/junioranheu/mongo-and-redis-playground-api

## Overview

1. **Overall shape**
   - This is a small .NET solution organized in a layered/clean-architecture style: **API → Application → Domain ← Infrastructure**.
   - The domain layer owns the core model and abstractions; infrastructure provides MongoDB and Redis implementations; the API hosts HTTP endpoints.

2. **API layer**
   - `MongoRedisPlayground.API` is the entry point and web host (`Program.cs`).
   - It contains two controllers: `HeroesController` and `HeroAttributesController`, which expose the application’s capabilities over HTTP.
   - `DependencyInjection.cs` and `DependencyAppConfiguration.cs` are used to wire up the lower layers and configuration.

3. **Application layer**
   - `MongoRedisPlayground.Application` contains the use-case services: `HeroService` and `HeroAttributeService`.
   - This layer coordinates business operations and acts as the boundary between controllers and persistence/caching.
   - It depends on abstractions from the domain rather than concrete storage implementations.

4. **Domain model**
   - `MongoRedisPlayground.Domain` holds the core entities: `Hero`, `HeroAttribute`, and `Ability`.
   - It also defines domain enums such as `HeroRoleEnum` and `AttackTypeEnum`, which encode business vocabulary.
   - Shared constants live here too, including cache key definitions in `CacheKeys`.

5. **Domain contracts**
   - The domain defines repository interfaces like `IHeroRepository` and `IHeroAttributeRepository`.
   - It also defines `ICacheService`, keeping caching as an abstract capability rather than tying business logic to Redis directly.
   - This makes the application layer independent of MongoDB/Redis implementation details.

6. **Infrastructure layer**
   - `MongoRedisPlayground.Infrastructure` provides the concrete technical adapters.
   - `Repositories/HeroRepository.cs` and `Repositories/HeroAttributeRepository.cs` implement the domain repository interfaces.
   - `Services/RedisCacheService.cs` implements the cache abstraction, likely using Redis as the backing store.

7. **Persistence boundary**
   - `Persistence/MongoDbContext.cs` and `Persistence/MongoDbSettings.cs` indicate MongoDB is the primary data store.
   - The repositories are the main boundary where application/domain objects are translated to MongoDB documents and back.
   - Configuration for the database connection is separated into settings rather than embedded in code.

8. **Caching boundary**
   - Redis is a second external system, represented by the infrastructure cache service.
   - Cache key naming is centralized in the domain constants, suggesting cache usage is part of the business flow rather than an ad hoc implementation detail.
   - The likely pattern is controller request → application service → repository/cache abstraction → MongoDB and/or Redis.

9. **Request/data flow**
   - A client calls an API controller.
   - The controller delegates to `HeroService` or `HeroAttributeService`.
   - The service uses repository interfaces and cache abstraction defined in the domain.
   - Infrastructure classes fulfill those calls against MongoDB and Redis.

10. **Dependency direction**
   - Dependencies point inward: API and Infrastructure depend on Application/Domain abstractions.
   - Domain does not depend on the web, MongoDB, or Redis.
   - This separation is the main architectural boundary to show in a diagram.

11. **Solution composition**
   - The solution file `MongoRedisPlayground.slnx` ties together four projects: API, Application, Domain, and Infrastructure.
   - Each project has its own `.csproj`, reinforcing the modular boundaries.

12. **What to highlight in a diagram**
   - Show **controllers** at the edge, **application services** in the middle, **domain entities/interfaces** at the core, and **MongoDB/Redis** as external systems reached only through infrastructure.
   - The two primary functional areas are **Heroes** and **Hero Attributes**, each with parallel controller/service/repository paths.

Main entry points: [`MongoRedisPlayground.slnx`](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.slnx) (Solution), [`MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs`](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs) (Mongo context), [`MongoRedisPlayground.API/DependencyInjection.cs`](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/DependencyInjection.cs) (API DI), [`MongoRedisPlayground.Application/Services/HeroService.cs`](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/Services/HeroService.cs) (Hero service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_api_program["Program<br/>host<br/>[Program.cs]"]
  node_api_di["API DI<br/>composition root"]
  node_api_cfg["App config<br/>startup config"]
  node_heroes_controller["Heroes API<br/>controller"]
  node_hero_attrs_controller["Hero attrs API<br/>controller"]
end

subgraph group_application["Application"]
  node_app_di["App DI<br/>composition root"]
  node_hero_service["Hero service<br/>use case service<br/>[HeroService.cs]"]
  node_hero_attr_service["Attr service<br/>use case service"]
end

subgraph group_domain["Domain"]
  node_hero_entity(("Hero<br/>entity<br/>[Hero.cs]"))
  node_hero_attr_entity(("HeroAttribute<br/>entity<br/>[HeroAttribute.cs]"))
  node_ability_entity(("Ability<br/>entity<br/>[Ability.cs]"))
  node_domain_contracts{{"Repos & cache<br/>interfaces"}}
  node_domain_consts["Cache keys<br/>constants<br/>[CacheKeys.cs]"]
end

subgraph group_infrastructure["Infrastructure"]
  node_mongo_ctx[("Mongo context<br/>mongo persistence<br/>[MongoDbContext.cs]")]
  node_mongo_settings["Mongo settings<br/>persistence config<br/>[MongoDbSettings.cs]"]
  node_hero_repo["Hero repo<br/>mongo repository<br/>[HeroRepository.cs]"]
  node_hero_attr_repo["Attr repo<br/>mongo repository"]
  node_redis_cache["Redis cache<br/>cache service"]
end

node_solution["Solution<br/>slnx"]

node_solution -->|"includes"| node_api_program
node_solution -->|"includes"| node_app_di
node_solution -->|"includes"| node_domain_contracts
node_solution -->|"includes"| node_mongo_ctx
node_api_program -->|"uses"| node_api_di
node_api_di -->|"registers"| node_app_di
node_api_di -->|"loads"| node_api_cfg
node_heroes_controller -->|"calls"| node_hero_service
node_hero_attrs_controller -->|"calls"| node_hero_attr_service
node_hero_service -->|"depends on"| node_domain_contracts
node_hero_attr_service -->|"depends on"| node_domain_contracts
node_hero_service -->|"works with"| node_hero_entity
node_hero_attr_service -->|"works with"| node_hero_attr_entity
node_domain_contracts -->|"implemented by"| node_hero_repo
node_domain_contracts -->|"implemented by"| node_hero_attr_repo
node_domain_contracts -->|"implemented by"| node_redis_cache
node_hero_repo -->|"uses"| node_mongo_ctx
node_hero_attr_repo -->|"uses"| node_mongo_ctx
node_mongo_ctx -->|"configured by"| node_mongo_settings
node_redis_cache -->|"uses"| node_domain_consts
node_hero_entity -->|"contains"| node_ability_entity
node_hero_entity -->|"references"| node_domain_consts
node_hero_attr_entity -->|"references"| node_domain_consts

click node_solution "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.slnx"
click node_api_program "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Program.cs"
click node_api_di "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/DependencyInjection.cs"
click node_api_cfg "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/DependencyAppConfiguration.cs"
click node_heroes_controller "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Controllers/HeroesController.cs"
click node_hero_attrs_controller "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Controllers/HeroAttributesController.cs"
click node_app_di "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/DependencyInjection.cs"
click node_hero_service "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/Services/HeroService.cs"
click node_hero_attr_service "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/Services/HeroAttributeService.cs"
click node_hero_entity "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/Hero.cs"
click node_hero_attr_entity "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/HeroAttribute.cs"
click node_ability_entity "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/Ability.cs"
click node_domain_consts "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Consts/CacheKeys.cs"
click node_mongo_ctx "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs"
click node_mongo_settings "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Persistence/MongoDbSettings.cs"
click node_hero_repo "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Repositories/HeroRepository.cs"
click node_hero_attr_repo "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Repositories/HeroAttributeRepository.cs"
click node_redis_cache "https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Services/RedisCacheService.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_program,node_api_di,node_api_cfg,node_heroes_controller,node_hero_attrs_controller toneBlue
class node_app_di,node_hero_service,node_hero_attr_service toneAmber
class node_hero_entity,node_hero_attr_entity,node_ability_entity,node_domain_contracts,node_domain_consts toneMint
class node_mongo_ctx,node_mongo_settings,node_hero_repo,node_hero_attr_repo,node_redis_cache toneRose
class node_solution toneNeutral
```

## Components

### API

HTTP entrypoint and composition root

- [Program](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Program.cs): host · Web host entrypoint · `MongoRedisPlayground.API/Program.cs`
- [API DI](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/DependencyInjection.cs): composition root · Wires API dependencies and configuration · `MongoRedisPlayground.API/DependencyInjection.cs`
- [App config](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/DependencyAppConfiguration.cs): startup config · Application configuration helpers · `MongoRedisPlayground.API/DependencyAppConfiguration.cs`
- [Heroes API](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Controllers/HeroesController.cs): controller · HTTP endpoints for heroes · `MongoRedisPlayground.API/Controllers/HeroesController.cs`
- [Hero attrs API](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.API/Controllers/HeroAttributesController.cs): controller · HTTP endpoints for hero attributes · `MongoRedisPlayground.API/Controllers/HeroAttributesController.cs`

### Application

Use-case orchestration layer

- [App DI](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/DependencyInjection.cs): composition root · Registers application services · `MongoRedisPlayground.Application/DependencyInjection.cs`
- [Hero service](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/Services/HeroService.cs): use case service · Coordinates hero operations · `MongoRedisPlayground.Application/Services/HeroService.cs`
- [Attr service](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Application/Services/HeroAttributeService.cs): use case service · Coordinates hero attribute operations · `MongoRedisPlayground.Application/Services/HeroAttributeService.cs`

### Domain

Core model and contracts

- [Hero](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/Hero.cs): entity · Core hero model · `MongoRedisPlayground.Domain/Entities/Hero.cs`
- [HeroAttribute](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/HeroAttribute.cs): entity · Hero attribute model · `MongoRedisPlayground.Domain/Entities/HeroAttribute.cs`
- [Ability](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Entities/Ability.cs): entity · Capability/value object · `MongoRedisPlayground.Domain/Entities/Ability.cs`
- **Repos & cache**: interfaces · Repository and cache abstractions
- [Cache keys](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Domain/Consts/CacheKeys.cs): constants · Shared cache naming and system constants · `MongoRedisPlayground.Domain/Consts/CacheKeys.cs`

### Infrastructure

MongoDB and Redis adapters

- [Mongo context](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs): mongo persistence · MongoDB access context · `MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs`
- [Mongo settings](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Persistence/MongoDbSettings.cs): persistence config · MongoDB configuration values · `MongoRedisPlayground.Infrastructure/Persistence/MongoDbSettings.cs`
- [Hero repo](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Repositories/HeroRepository.cs): mongo repository · Persists heroes in MongoDB · `MongoRedisPlayground.Infrastructure/Repositories/HeroRepository.cs`
- [Attr repo](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Repositories/HeroAttributeRepository.cs): mongo repository · Persists hero attributes in MongoDB · `MongoRedisPlayground.Infrastructure/Repositories/HeroAttributeRepository.cs`
- [Redis cache](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.Infrastructure/Services/RedisCacheService.cs): cache service · Redis-backed cache implementation · `MongoRedisPlayground.Infrastructure/Services/RedisCacheService.cs`

### Other components

- [Solution](https://github.com/junioranheu/mongo-and-redis-playground-api/blob/main/MongoRedisPlayground.slnx): slnx · Ties the four projects together · `MongoRedisPlayground.slnx`

## Connections

- Solution → Program: includes · Solution includes the API project
- Solution → App DI: includes · Solution includes the Application project
- Solution → Repos & cache: includes · Solution includes the Domain project
- Solution → Mongo context: includes · Solution includes the Infrastructure project
- Program → API DI: uses · Bootstraps dependency wiring
- API DI → App DI: registers · API composition root registers app services
- API DI → App config: loads · API wiring uses app configuration helpers
- Heroes API → Hero service: calls · Controller delegates hero requests to the service
- Hero attrs API → Attr service: calls · Controller delegates attribute requests to the service
- Hero service → Repos & cache: depends on · Uses repository and cache abstractions
- Attr service → Repos & cache: depends on · Uses repository and cache abstractions
- Hero service → Hero: works with · Hero operations center on the hero model
- Attr service → HeroAttribute: works with · Attribute operations center on the attribute model
- Repos & cache → Hero repo: implemented by · Hero repository interface is implemented in infrastructure
- Repos & cache → Attr repo: implemented by · Hero attribute repository interface is implemented in infrastructure
- Repos & cache → Redis cache: implemented by · Cache abstraction is implemented in infrastructure
- Hero repo → Mongo context: uses · Repository talks to MongoDB through the context
- Attr repo → Mongo context: uses · Repository talks to MongoDB through the context
- Mongo context → Mongo settings: configured by · Mongo access is driven by settings
- Redis cache → Cache keys: uses · Cache key naming comes from domain constants
- Hero → Ability: contains · Hero model includes abilities
- Hero → Cache keys: references · Domain model shares common constants
- HeroAttribute → Cache keys: references · Attribute model shares common constants
