How junioranheu/mongo-and-redis-playground-api works
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 Solution · MongoDbContext.cs Mongo context · DependencyInjection.cs API DI · HeroService.cs Hero service
Components 19
API
HTTP entrypoint and composition root
- Program · Web host entrypoint
MongoRedisPlayground.API/Program.cs - API DI · Wires API dependencies and configuration
MongoRedisPlayground.API/DependencyInjection.cs - App config · Application configuration helpers
MongoRedisPlayground.API/DependencyAppConfiguration.cs - Heroes API · HTTP endpoints for heroes
MongoRedisPlayground.API/Controllers/HeroesController.cs - Hero attrs API · HTTP endpoints for hero attributes
MongoRedisPlayground.API/Controllers/HeroAttributesController.cs
Application
Use-case orchestration layer
- App DI · Registers application services
MongoRedisPlayground.Application/DependencyInjection.cs - Hero service · Coordinates hero operations
MongoRedisPlayground.Application/Services/HeroService.cs - Attr service · Coordinates hero attribute operations
MongoRedisPlayground.Application/Services/HeroAttributeService.cs
Domain
Core model and contracts
- Hero · Core hero model
MongoRedisPlayground.Domain/Entities/Hero.cs - HeroAttribute · Hero attribute model
MongoRedisPlayground.Domain/Entities/HeroAttribute.cs - Ability · Capability/value object
MongoRedisPlayground.Domain/Entities/Ability.cs - Repos & cache · Repository and cache abstractions
- Cache keys · Shared cache naming and system constants
MongoRedisPlayground.Domain/Consts/CacheKeys.cs
Infrastructure
MongoDB and Redis adapters
- Mongo context · MongoDB access context
MongoRedisPlayground.Infrastructure/Persistence/MongoDbContext.cs - Mongo settings · MongoDB configuration values
MongoRedisPlayground.Infrastructure/Persistence/MongoDbSettings.cs - Hero repo · Persists heroes in MongoDB
MongoRedisPlayground.Infrastructure/Repositories/HeroRepository.cs - Attr repo · Persists hero attributes in MongoDB
MongoRedisPlayground.Infrastructure/Repositories/HeroAttributeRepository.cs - Redis cache · Redis-backed cache implementation
MongoRedisPlayground.Infrastructure/Services/RedisCacheService.cs
Other components
- Solution · Ties the four projects together
MongoRedisPlayground.slnx
Connections 23
- 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