# ykh2000/medieval architecture

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

- Interactive diagram: https://gitdiagram.com/ykh2000/medieval
- Repository: https://github.com/ykh2000/medieval

## Overview

1. **High-level shape**  
   MediEval is a single ASP.NET Core MVC monolith with a standard server-rendered UI. Requests come in through MVC controllers, which coordinate business logic in `Data/Services`, persist through EF Core, and render Razor views. The app is centered on an OTC medicine commerce workflow plus admin and real-time communication features.

2. **Presentation layer**  
   The main UI is split between standard MVC controllers under `Controllers/` and an admin-only MVC `Area` under `Areas/Admin/`. Views live in `Views/` and `Areas/Admin/Views/`, with shared layouts and partials. This separation is important for the architecture diagram because admin and customer-facing pages are distinct routes and layouts.

3. **Core business domains**  
   The domain models in `Models/` cover medicines, pharmacies, pharmacy brands, orders, order items, shopping cart items, chat messages, and users. These are the core entities that flow through the app: catalog browsing, cart management, checkout/order creation, and customer support chat.

4. **Data access and persistence**  
   `Data/AppDbContext.cs` is the EF Core database boundary. `Migrations/` shows the schema evolves through EF migrations, and `AppDbInitializer.cs` likely seeds or prepares the database. `Data/Base/` contains a repository abstraction, but the implementation also uses service classes directly, so the persistence boundary is service-oriented rather than purely repository-driven.

5. **Application services**  
   The `Data/Services/` layer is the main business logic boundary. It includes `MedicineService`, `OrdersService`, `PharmacyService`, `PharmacyBrandService`, and buffered file upload services. Controllers depend on these services instead of talking to EF Core directly, which keeps the MVC layer thin and makes service classes the key orchestration point for data operations.

6. **Authentication and user management**  
   Authentication is handled through ASP.NET Core Identity, reflected by `ApplicationUser`, account-related view models, and `AccountController`. Roles are defined in `Data/Static/UserRoles.cs`, and the UI includes login, registration, password recovery, lockout, and access-denied flows. Authorization is used to separate regular users from admins.

7. **Catalog and commerce flow**  
   Users browse medicines and pharmacy-related entities through `MedicineController`, `PharmacyController`, and `PharmacyBrandController`. The shopping flow runs through the cart and order models plus `OrdersController`. The `ShoppingCart` helper and `ShoppingCartSummary` view component indicate the cart is maintained server-side and summarized in the UI.

8. **Admin subsystem**  
   The admin area includes controllers for home, medicine, and user management, plus a dedicated admin layout. This is a clear boundary for privileged operations such as managing catalog data and user administration. In the diagram, this should be shown as a separate presentation slice over the same service and database layers.

9. **Real-time communication**  
   The app uses SignalR hubs in `Hubs/` for chat, notifications, and user presence/counting. Browser-side JavaScript in `wwwroot/js/` connects to these hubs to provide live updates for customer–pharmacist chat and alerts. This is an asynchronous push channel separate from normal HTTP request/response traffic.

10. **File upload subsystem**  
   There are two upload paths: a buffered file upload controller/service and a dedicated image upload controller/model pair. Uploaded content is stored under `UploadedFiles/` and also under `wwwroot/Images/` for browser access. This subsystem is likely used for medicine images and other user-submitted files, and it forms a distinct storage boundary outside the database.

11. **Email and external integration**  
   `Services/MailJetEMailSender.cs` and `MailJetOptions.cs` show outbound email integration via Mailjet. This is part of the account lifecycle, likely supporting registration and password reset workflows. It is an external dependency separate from the core database and UI layers.

12. **Frontend assets and client runtime**  
   The client side is mainly Razor-rendered HTML with Bootstrap, jQuery, validation scripts, and SignalR JavaScript libraries under `wwwroot/lib/`. Custom scripts such as `chat.js`, `notification.js`, and `usersCount.js` bind the real-time features to the UI. The frontend is therefore not a SPA; it is server-rendered with targeted JavaScript enhancements.

13. **Configuration and deployment context**  
   `appsettings.json`, `appsettings.Development.json`, `launchSettings.json`, and the `serviceDependencies` files define runtime configuration and deployment wiring. The presence of SQL Server service metadata indicates the app is designed to run against a relational SQL backend, with environment-specific configuration controlling connection strings and related settings.

14. **What the diagram should emphasize**  
   The cleanest architecture view is: browser/UI → MVC controllers or SignalR hubs → service layer → EF Core DbContext → SQL Server, with side paths for file storage and Mailjet email. The admin area, real-time hubs, and upload subsystem should be drawn as separate vertical slices because they cross-cut the core commerce flow without replacing it.

Main entry points: [`MediEval/Controllers`](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Controllers) (MVC Controllers), [`MediEval/Areas/Admin/Controllers`](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Areas/Admin/Controllers) (Admin Controllers), [`MediEval/Data/Services`](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Data/Services) (Catalog Services), [`MediEval/Views`](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Views) (Razor Views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_controllers["MVC Controllers<br/>http entrypoints"]
  node_admin_controllers["Admin Controllers<br/>admin mvc"]
  node_views["Razor Views<br/>server ui"]
  node_admin_views["Admin Views<br/>admin ui"]
end

subgraph group_application["Application"]
  node_medicine_service["Catalog Services<br/>business services"]
  node_orders_service["Orders Service<br/>checkout service<br/>[OrdersService.cs]"]
  node_cart["Shopping Cart<br/>session cart<br/>[ShoppingCart.cs]"]
  node_viewmodels["View Models<br/>ui contracts"]
end

subgraph group_infrastructure["Infrastructure"]
  node_dbcontext[("App DbContext<br/>ef core db<br/>[AppDbContext.cs]")]
  node_initializer["Db Initializer<br/>bootstrapper"]
  node_identity["Identity Users<br/>auth model<br/>[ApplicationUser.cs]"]
  node_mailjet["Mailjet Email<br/>external integration"]
end

subgraph group_realtime["Realtime"]
  node_hubs["SignalR Hubs<br/>realtime endpoints"]
end

subgraph group_client["Client Assets"]
  node_client_js["Client Scripts<br/>browser runtime"]
  node_uploads[("File Storage<br/>blob storage")]
end

node_domain_models["Domain Models<br/>entities"]

node_controllers -->|"uses"| node_medicine_service
node_controllers -->|"uses"| node_orders_service
node_controllers -->|"uses"| node_cart
node_controllers -->|"signals"| node_hubs
node_controllers -->|"renders"| node_views
node_admin_controllers -->|"uses"| node_medicine_service
node_admin_controllers -->|"renders"| node_views
node_admin_controllers -->|"renders"| node_admin_views
node_views -->|"binds"| node_viewmodels
node_admin_views -->|"binds"| node_viewmodels
node_medicine_service -->|"persists via"| node_dbcontext
node_orders_service -->|"persists via"| node_dbcontext
node_cart -->|"submits to"| node_orders_service
node_dbcontext -->|"maps"| node_domain_models
node_initializer -->|"prepares"| node_dbcontext
node_controllers -->|"authenticates"| node_identity
node_admin_controllers -->|"authorizes"| node_identity
node_controllers -->|"sends email"| node_mailjet
node_hubs -->|"pushes to"| node_client_js
node_client_js -->|"enhances"| node_views
node_controllers -->|"stores files"| node_uploads
node_medicine_service -->|"reads images"| node_uploads

click node_controllers "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Controllers"
click node_admin_controllers "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Areas/Admin/Controllers"
click node_views "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Views"
click node_admin_views "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Areas/Admin/Views"
click node_medicine_service "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Data/Services"
click node_orders_service "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/Services/OrdersService.cs"
click node_cart "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/Cart/ShoppingCart.cs"
click node_viewmodels "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Data/ViewModel"
click node_dbcontext "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/AppDbContext.cs"
click node_initializer "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/AppDbInitializer.cs"
click node_identity "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Models/ApplicationUser.cs"
click node_mailjet "https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Services/MailJetEMailSender.cs"
click node_hubs "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Hubs"
click node_client_js "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/wwwroot/js"
click node_uploads "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/UploadedFiles"
click node_domain_models "https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Models"

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_controllers,node_admin_controllers,node_views,node_admin_views toneBlue
class node_medicine_service,node_orders_service,node_cart,node_viewmodels toneAmber
class node_dbcontext,node_initializer,node_identity,node_mailjet toneMint
class node_hubs toneRose
class node_client_js,node_uploads toneIndigo
class node_domain_models toneNeutral
```

## Components

### Presentation

Server-rendered MVC UI and admin area.

- [MVC Controllers](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Controllers): http entrypoints · Customer-facing request handlers for account, catalog, cart, orders, chat, and uploads. · `MediEval/Controllers`
- [Admin Controllers](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Areas/Admin/Controllers): admin mvc · Privileged admin routes for home, medicine, and user management. · `MediEval/Areas/Admin/Controllers`
- [Razor Views](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Views): server ui · Main customer-facing Razor pages and shared layouts/partials. · `MediEval/Views`
- [Admin Views](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Areas/Admin/Views): admin ui · Admin area pages and dedicated admin layout. · `MediEval/Areas/Admin/Views`

### Application

Services, cart, and business workflows.

- [Catalog Services](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Data/Services): business services · Medicine, pharmacy, and brand services that drive catalog operations. · `MediEval/Data/Services`
- [Orders Service](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/Services/OrdersService.cs): checkout service · Orchestrates cart-to-order conversion and order retrieval. · `MediEval/Data/Services/OrdersService.cs`
- [Shopping Cart](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/Cart/ShoppingCart.cs): session cart · Server-side cart state and cart summary component. · `MediEval/Data/Cart/ShoppingCart.cs`
- [View Models](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Data/ViewModel): ui contracts · Login, register, admin, cart, and medicine form models used between controllers and views. · `MediEval/Data/ViewModel`

### Infrastructure

EF Core persistence, identity, and external services.

- [App DbContext](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/AppDbContext.cs): ef core db · Primary EF Core boundary for all domain persistence. · `MediEval/Data/AppDbContext.cs`
- [Db Initializer](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Data/AppDbInitializer.cs): bootstrapper · Database seeding and startup preparation logic. · `MediEval/Data/AppDbInitializer.cs`
- [Identity Users](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Models/ApplicationUser.cs): auth model · ASP.NET Core Identity user model and role definitions. · `MediEval/Models/ApplicationUser.cs`
- [Mailjet Email](https://github.com/ykh2000/medieval/blob/medi-eval-eCommerce/MediEval/Services/MailJetEMailSender.cs): external integration · Outbound email provider for account lifecycle workflows. · `MediEval/Services/MailJetEMailSender.cs`

### Realtime

SignalR hubs and browser push features.

- [SignalR Hubs](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Hubs): realtime endpoints · Chat, notification, and user-presence hubs. · `MediEval/Hubs`

### Client Assets

Static JS/CSS and uploaded file storage.

- [Client Scripts](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/wwwroot/js): browser runtime · Custom JavaScript for chat, notifications, users count, and site behavior. · `MediEval/wwwroot/js`
- [File Storage](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/UploadedFiles): blob storage · Local uploaded files and web-accessible images. · `MediEval/UploadedFiles`

### Other components

- [Domain Models](https://github.com/ykh2000/medieval/tree/medi-eval-eCommerce/MediEval/Models): entities · Core commerce entities: medicines, pharmacies, orders, chats, and carts. · `MediEval/Models`

## Connections

- MVC Controllers → Catalog Services: uses · Controllers delegate catalog operations to services.
- MVC Controllers → Orders Service: uses · Order and cart actions flow through order service orchestration.
- MVC Controllers → Shopping Cart: uses · Shopping cart controller logic relies on server-side cart state.
- MVC Controllers → SignalR Hubs: signals · Chat and notifications connect to realtime hubs.
- MVC Controllers → Razor Views: renders · MVC controllers render Razor pages.
- Admin Controllers → Catalog Services: uses · Admin catalog management shares the same service layer.
- Admin Controllers → Razor Views: renders · Admin actions render Razor views through the MVC pipeline.
- Admin Controllers → Admin Views: renders · Admin-specific pages use the area layout and views.
- Razor Views → View Models: binds · Views consume typed models from controllers.
- Admin Views → View Models: binds · Admin pages use dedicated form and listing models.
- Catalog Services → App DbContext: persists via · Catalog services read and write through EF Core.
- Orders Service → App DbContext: persists via · Checkout and order workflows use the database boundary.
- Shopping Cart → Orders Service: submits to · Cart contents are transformed into orders.
- App DbContext → Domain Models: maps · EF Core maps the core domain entities.
- Db Initializer → App DbContext: prepares · Startup seeding and setup operate through DbContext.
- MVC Controllers → Identity Users: authenticates · Account and access flows depend on Identity users and roles.
- Admin Controllers → Identity Users: authorizes · Admin routes are protected by role-based authorization.
- MVC Controllers → Mailjet Email: sends email · Password reset and registration flows trigger outbound mail.
- SignalR Hubs → Client Scripts: pushes to · Browser scripts connect to and consume hub events.
- Client Scripts → Razor Views: enhances · Client scripts enrich server-rendered pages.
- MVC Controllers → File Storage: stores files · Upload controllers write to local upload/image storage.
- Catalog Services → File Storage: reads images · Catalog services may reference uploaded medicine images.
