# sasha-pober/emergency-ms architecture

> Architecture diagram of the GitHub repository sasha-pober/emergency-ms, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sasha-pober/emergency-ms
- Repository: https://github.com/sasha-pober/emergency-ms

## Overview

##### Project type and purpose
- emergency-ms is a full-stack, event-tracking application.
- Frontend: Angular web client for users to log in, view maps, and create/view emergencies.
- Backend: .NET Core Web API exposing REST endpoints to manage Emergency, Image, Type, Location, Source, Street entities.
- Persistence: Entity Framework Core with a relational database (via AppDbContext).

##### File structure and architectural patterns
- Top-level “backend” folder contains a single .NET solution (EmengencyMS.API.sln) subdivided into:
- Domain: business entities and repository interfaces
- Infrastructure: EF Core DbContext, database migrations, repository implementations
- Services (Abstractions & Implementations): business logic layer
- Presentation: Web API controllers, DTOs/mappings, Startup/Program
- “frontend/emergencyMS-web” is an Angular CLI project:
- Components, models, services, guards
- Uses HTTP requests to the backend API
- Architectural patterns:
- Layered (Presentation → Services → Infrastructure → Domain)
- Repository pattern (IEmergencyRepository etc.)
- Dependency Injection (via Startup.cs extension methods)
- DTO mapping between layers

##### Main components and their relationships
- User’s Browser/Angular App
- Components (Login, Main, Map, CreateEmergency, Dashboard)
- Angular Services (AuthService, EmergencyService, MapService, TypeService)
→ call
- Backend Web API
- Presentation Layer (Controllers)
→ inject →
- Service Layer (IEmergencyService, IImageService, ITypeService)
→ use →
- Infrastructure Layer
– Repositories (EmergencyRepository, ImageRepository, TypeRepository)
– AppDbContext (EF Core)
→ persists →
- Relational Database
- Static Assets (GeoJSON under wwwroot or in Angular assets)

##### Important architectural/design principles
- Separation of concerns (layers each with single responsibility)
- DI and inversion of control for loose coupling
- Repository + Unit of Work (EF Core) for data access
- DTOs and AutoMapper-style mapping to isolate domain from transport models
- Angular feature modules and route guards for UI segmentation & security

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend" 
        direction TB
        AngularApp["Angular App"]:::frontend
        subgraph "Components"
            direction TB
            CreateEmergencyComponent["CreateEmergencyComponent"]:::frontend
            LoginComponent["LoginComponent"]:::frontend
            MainComponent["MainComponent"]:::frontend
            MapComponent["MapComponent"]:::frontend
            UserDashboardComponent["UserDashboardComponent"]:::frontend
        end
        subgraph "Services"
            direction TB
            AuthService["AuthService"]:::frontend
            EmergencyService["EmergencyService"]:::frontend
            MapService["MapService"]:::frontend
            TypeService["TypeService"]:::frontend
        end
        subgraph "Guards"
            direction TB
            AuthGuard["AuthGuard"]:::frontend
        end
        AngularApp -->|"uses"| CreateEmergencyComponent
        AngularApp -->|"uses"| LoginComponent
        AngularApp -->|"uses"| MainComponent
        AngularApp -->|"uses"| MapComponent
        AngularApp -->|"uses"| UserDashboardComponent
        AngularApp -->|"injects"| AuthService
        AngularApp -->|"injects"| EmergencyService
        AngularApp -->|"injects"| MapService
        AngularApp -->|"injects"| TypeService
        AngularApp -->|"protects"| AuthGuard
        AngularApp -->|"HTTP/JSON"| APIControllers
    end

    subgraph "Backend (Docker Container)" 
        direction TB
        subgraph "Presentation Layer" 
            direction TB
            APIControllers["API Controllers"]:::presentation
            Startup["Startup & Program"]:::presentation
        end
        subgraph "Service Layer" 
            direction TB
            ServiceInterfaces["Service Interfaces"]:::biz
            ServiceImplementations["Service Implementations"]:::biz
        end
        subgraph "Infrastructure Layer" 
            direction TB
            Repositories["Repositories"]:::infra
            DbContext["AppDbContext"]:::infra
        end
        subgraph "Domain Layer" 
            direction TB
            Entities["Entities"]:::infra
            RepoInterfaces["Repository Interfaces"]:::infra
        end
        APIControllers -->|"injects"| ServiceInterfaces
        ServiceInterfaces -->|"implemented by"| ServiceImplementations
        ServiceImplementations -->|"uses"| Repositories
        Repositories -->|"uses"| DbContext
        DbContext -->|"persists"| SQLDatabase
    end

    SQLDatabase["SQL Database"]:::db

    click AngularApp "https://github.com/sasha-pober/emergency-ms/tree/main/frontend/emergencyMS-web"
    click CreateEmergencyComponent "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/components/create-emergency/create-emergency.component.ts"
    click LoginComponent "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/components/login/login.component.ts"
    click MainComponent "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/components/main/main.component.ts"
    click MapComponent "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/components/map/map.component.ts"
    click UserDashboardComponent "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/components/user-dashboard/user-dashboard.component.ts"
    click AuthService "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/services/auth/auth.service.ts"
    click EmergencyService "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/services/emergency/emergency.service.ts"
    click MapService "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/services/map/map.service.ts"
    click TypeService "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/services/type/type.service.ts"
    click AuthGuard "https://github.com/sasha-pober/emergency-ms/blob/main/frontend/emergencyMS-web/src/app/guards/auth.guard.ts"
    click Entities "https://github.com/sasha-pober/emergency-ms/tree/main/backend/EmengencyMS.API/Domain/Entities"
    click RepoInterfaces "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Domain/Interfaces/IEmergencyRepository.cs"
    click DbContext "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Infrastructure/AppDbContext.cs"
    click Repositories "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Infrastructure/Repositories/EmergencyRepository.cs"
    click ServiceInterfaces "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Services.Abstractions/Interfaces/IEmergencyService.cs"
    click ServiceImplementations "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Services/Implementations/EmergencyService.cs"
    click APIControllers "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/Presentation/Controllers/EmergencyController.cs"
    click Startup "https://github.com/sasha-pober/emergency-ms/blob/main/backend/EmengencyMS.API/EmengencyMS.API/Startup.cs"
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef biz fill:#C2FABC,stroke:#000
    classDef infra fill:#FFD580,stroke:#000
    classDef presentation fill:#E3E4FA,stroke:#000
    classDef db fill:#A0C4FF,stroke:#000,stroke-dasharray: 5 5,shape:cylinder
```
