# abhishek-kumar24698e/safecity-fullstack architecture

> Architecture diagram of the GitHub repository abhishek-kumar24698e/safecity-fullstack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abhishek-kumar24698e/safecity-fullstack
- Repository: https://github.com/abhishek-kumar24698e/safecity-fullstack

## Overview

1. **Repo shape**
   - This is a three-part monorepo: `SafeCity` backend API, `SafeCity.Domain` shared domain model, and `SafeCity-Frontend` Angular SPA.
   - The backend owns business logic and persistence; the frontend is a thin client; the domain project holds the EF Core entity model and enums.

2. **Primary architectural boundary**
   - The clearest boundary is between the Angular app and the ASP.NET Core API.
   - All state-changing and query operations flow from Angular components/services to REST controllers, then through service and repository layers to SQL Server via EF Core.
   - Real-time updates bypass the normal request/response path and go through SignalR.

3. **Frontend structure**
   - The Angular app uses standalone components and route-based lazy loading.
   - `src/app/features/*` contains the major screens: auth, dashboard, incidents, cases, patrols, field reports, dispatch, resources, crisis, response, audits, compliance, users, notifications, profile, landing.
   - `src/app/layout/*` provides the application shell: `main-layout` and `sidebar`.
   - `src/app/core/*` contains cross-cutting client concerns: auth guards, HTTP interceptors, typed API models, and feature-specific services.

4. **Frontend request flow**
   - User interaction starts in a feature component.
   - Feature services in `src/app/core/services` call the API over HTTP.
   - `auth.interceptor.ts` attaches the JWT to outgoing requests.
   - `auth.guard.ts` protects authenticated routes, and route access is further shaped by role-based navigation in the sidebar and route config.

5. **Backend API layer**
   - The backend is organized by feature/module, with one controller per major area: Auth, User, Incident, Case, Patrol, FieldReport, Dispatch, Resource, Crisis, Response, Audit, Compliance, and Notification.
   - Controllers are the HTTP edge: routing, authorization, request binding, and response formatting.
   - The naming suggests a fairly explicit REST API surface aligned to the same business domains visible in the frontend.

6. **Service layer**
   - Each business area has a service class under `Services/*`.
   - These services are the main orchestration layer: validation, workflow/state transitions, audit/logging concerns, and coordination across repositories.
   - The presence of interfaces for each service indicates a dependency-injected, testable boundary between controllers and data access.

7. **Repository and persistence layer**
   - Each domain module has a repository pair under `Repository/*` with interface plus implementation.
   - Repositories encapsulate EF Core queries against `SafeCityDbContext`.
   - This keeps SQL/ORM concerns isolated from business rules and makes the backend a conventional layered architecture rather than an anemic controller-to-DbContext setup.

8. **Shared domain model**
   - `SafeCity.Domain` contains the core entities, enums, and `SafeCityDbContext`.
   - Entities include `User`, `Incident`, `Case`, `Dispatch`, `Resource`, `Patrol`, `FieldReport`, `Crisis`, `Response`, `Team`, `Audit`, and `AuditLog`, plus supporting role and status enums.
   - Keeping the domain in a separate project makes the model reusable and keeps API concerns out of the persistence model.

9. **DTO and mapping boundary**
   - The API does not expose entities directly; it uses DTOs grouped by feature under `DTOs/*`.
   - `Mapper/MappingProfile.cs` centralizes entity-to-DTO translation through AutoMapper.
   - This is an important architecture boundary because it separates persistence shape from network contract shape.

10. **Authentication, authorization, and audit**
   - Identity is centered around `AuthController`/`AuthService` and `UserController`/`UserService`.
   - The repo contains JWT, password hashing helpers, auth guards, and auth utilities, indicating token-based stateless sessions.
   - Audit concerns are first-class: `AuditController`, `AuditService`, `AuditLogger`, and `AuditLog` show that operational actions are tracked separately from normal business entities.

11. **Real-time notifications**
   - `Hubs/NotificationHub.cs` is the real-time boundary for push messaging.
   - The frontend has a notifications feature and the backend has a dedicated notification service and controller, which suggests that notifications are both persisted and broadcast live.
   - This is the main non-REST subsystem in the architecture.

12. **Cross-cutting utilities**
   - The backend `Utility` folder contains shared validation and helper logic such as email/password/phone helpers, exception helpers, and custom validation attributes.
   - These utilities support the service layer but are not themselves application features.
   - On the frontend, `shared/constants.ts`, `shared/auth-utils.ts`, and `shared/icon.component.ts` serve the same cross-cutting role.

13. **How the modules line up**
   - The frontend feature pages map closely to backend modules: incidents/cases, dispatch/resources, patrols/field reports, crisis/response, audits/compliance, and user/auth flows.
   - That symmetry makes the architecture easy to diagram as a set of domain modules connected through one API and one database, rather than as unrelated screens.

14. **Infrastructure/runtime implications**
   - The backend expects SQL Server through EF Core and runs as an ASP.NET Core Web API.
   - The frontend is an Angular SPA built with Tailwind-based styling and client-side routing.
   - The system is therefore deployed as at least two independently running services: browser SPA plus API, with the API also hosting SignalR connections.

Main entry points: [`SafeCity/SafeCity/Controllers/AuthController.cs`](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Controllers/AuthController.cs) (Controllers), [`SafeCity/SafeCity/Services/Auth/AuthService.cs`](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Services/Auth/AuthService.cs) (Services), [`SafeCity-Frontend/src/app/app.routes.ts`](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/app.routes.ts) (Routes), [`SafeCity/SafeCity/Mapper/MappingProfile.cs`](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Mapper/MappingProfile.cs) (Mapping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["SafeCity-Frontend"]
  node_spa["Angular SPA<br/>frontend app<br/>[app.ts]"]
  node_routes["Routes<br/>route config<br/>[app.routes.ts]"]
  node_layout["App Shell<br/>layout<br/>[main-layout.ts]"]
  node_authclient["Auth Client<br/>client auth"]
  node_apiservices["API Services<br/>client services<br/>[auth.service.ts]"]
  node_features["Feature Screens<br/>feature pages<br/>[incidents-page.ts]"]
  node_sharedui["Shared UI<br/>client shared<br/>[constants.ts]"]
end

subgraph group_backend["SafeCity API"]
  node_controllers["Controllers<br/>api edge<br/>[AuthController.cs]"]
  node_dto["DTOs<br/>contract models<br/>[LoginRequestDto.cs]"]
  node_mapping["Mapping<br/>[MappingProfile.cs]"]
  node_services["Services<br/>business layer<br/>[AuthService.cs]"]
  node_repos["Repositories<br/>data access<br/>[UserRepository.cs]"]
  node_hub(("Notification Hub<br/>signalr hub<br/>[NotificationHub.cs]"))
  node_auditlog["Audit Logging<br/>audit service<br/>[AuditLogger.cs]"]
end

subgraph group_domain["SafeCity.Domain"]
  node_db[("DbContext<br/>ef core context")]
  node_entities["Entities<br/>domain model<br/>[User.cs]"]
  node_enums["Enums<br/>[UserRoleOption.cs]"]
end

node_spa -->|"uses"| node_routes
node_routes -->|"mounts"| node_layout
node_routes -->|"lazy loads"| node_features
node_features -->|"calls"| node_apiservices
node_apiservices -->|"secured by"| node_authclient
node_authclient -->|"requests"| node_controllers
node_sharedui -.->|"supports"| node_features
node_controllers -->|"binds"| node_dto
node_controllers -->|"delegates"| node_services
node_services -->|"uses"| node_repos
node_services -->|"logs"| node_auditlog
node_repos -->|"queries"| node_db
node_db -->|"tracks"| node_entities
node_entities -->|"uses"| node_enums
node_mapping -->|"maps"| node_entities
node_mapping -->|"maps"| node_dto
node_controllers -.->|"pushes"| node_hub
node_services -.->|"broadcasts"| node_hub
node_controllers -.->|"formats"| node_mapping

click node_spa "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/app.ts"
click node_routes "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/app.routes.ts"
click node_layout "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/layout/main-layout/main-layout.ts"
click node_authclient "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/core/interceptors/auth.interceptor.ts"
click node_apiservices "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/core/services/auth.service.ts"
click node_features "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/features/incidents/incidents-page.ts"
click node_sharedui "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/shared/constants.ts"
click node_controllers "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Controllers/AuthController.cs"
click node_dto "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/DTOs/User/LoginRequestDto.cs"
click node_mapping "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Mapper/MappingProfile.cs"
click node_services "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Services/Auth/AuthService.cs"
click node_repos "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Repository/User/UserRepository.cs"
click node_hub "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Hubs/NotificationHub.cs"
click node_auditlog "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Services/AuditLog/AuditLogger.cs"
click node_db "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Data/SafeCityDbContext.cs"
click node_entities "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Entity/User.cs"
click node_enums "https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Enum/UserRoleOption.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_spa,node_routes,node_layout,node_authclient,node_apiservices,node_features,node_sharedui toneBlue
class node_controllers,node_dto,node_mapping,node_services,node_repos,node_hub,node_auditlog toneAmber
class node_db,node_entities,node_enums toneMint
```

## Components

### SafeCity-Frontend

Angular SPA with feature routes, layout shell, and client-side API access

- [Angular SPA](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/app.ts): frontend app · Browser client with route-based features and standalone components · `SafeCity-Frontend/src/app/app.ts`
- [Routes](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/app.routes.ts): route config · Top-level client routing and lazy-loaded feature boundaries · `SafeCity-Frontend/src/app/app.routes.ts`
- [App Shell](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/layout/main-layout/main-layout.ts): layout · Main layout and sidebar navigation for authenticated screens · `SafeCity-Frontend/src/app/layout/main-layout/main-layout.ts`
- [Auth Client](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/core/interceptors/auth.interceptor.ts): client auth · JWT handling, route protection, and HTTP interception · `SafeCity-Frontend/src/app/core/interceptors/auth.interceptor.ts`
- [API Services](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/core/services/auth.service.ts): client services · Typed service layer for feature-specific API calls · `SafeCity-Frontend/src/app/core/services/auth.service.ts`
- [Feature Screens](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/features/incidents/incidents-page.ts): feature pages · Primary domain screens such as incidents, cases, patrols, dispatch, and users · `SafeCity-Frontend/src/app/features/incidents/incidents-page.ts`
- [Shared UI](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity-Frontend/src/app/shared/constants.ts): client shared · Cross-cutting constants, auth helpers, and reusable icon component · `SafeCity-Frontend/src/app/shared/constants.ts`

### SafeCity API

ASP.NET Core REST API with services, repositories, DTOs, and SignalR

- [Controllers](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Controllers/AuthController.cs): api edge · REST endpoints for auth, users, incidents, cases, operations, and notifications · `SafeCity/SafeCity/Controllers/AuthController.cs`
- [DTOs](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/DTOs/User/LoginRequestDto.cs): contract models · Request and response contracts separating API shape from entities · `SafeCity/SafeCity/DTOs/User/LoginRequestDto.cs`
- [Mapping](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Mapper/MappingProfile.cs): dto mapping · AutoMapper profile translating entities to API contracts · `SafeCity/SafeCity/Mapper/MappingProfile.cs`
- [Services](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Services/Auth/AuthService.cs): business layer · Workflow orchestration, validation, and coordination across repositories · `SafeCity/SafeCity/Services/Auth/AuthService.cs`
- [Repositories](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Repository/User/UserRepository.cs): data access · EF Core repository layer encapsulating persistence queries and updates · `SafeCity/SafeCity/Repository/User/UserRepository.cs`
- [Notification Hub](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Hubs/NotificationHub.cs): signalr hub · Real-time push channel for live notifications · `SafeCity/SafeCity/Hubs/NotificationHub.cs`
- [Audit Logging](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity/SafeCity/Services/AuditLog/AuditLogger.cs): audit service · Dedicated logging boundary for operational tracking and audit events · `SafeCity/SafeCity/Services/AuditLog/AuditLogger.cs`

### SafeCity.Domain

Shared entities, enums, and EF Core DbContext

- [DbContext](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Data/SafeCityDbContext.cs): ef core context · Shared EF Core context used by repositories · `SafeCity.Domain/SafeCity.Domain/Data/SafeCityDbContext.cs`
- [Entities](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Entity/User.cs): domain model · Core entities for users, incidents, cases, dispatch, resources, patrols, reports, crisis, response, audit, compliance, and teams · `SafeCity.Domain/SafeCity.Domain/Entity/User.cs`
- [Enums](https://github.com/abhishek-kumar24698e/safecity-fullstack/blob/main/SafeCity.Domain/SafeCity.Domain/Enum/UserRoleOption.cs): domain enums · Status, role, type, and result enums used across the model · `SafeCity.Domain/SafeCity.Domain/Enum/UserRoleOption.cs`

## Connections

- Angular SPA → Routes: uses · The app boots into the routed shell
- Routes → App Shell: mounts · Authenticated routes render inside the main application shell
- Routes → Feature Screens: lazy loads · Feature areas are split into route-based screens
- Feature Screens → API Services: calls · Feature components invoke typed services for data access
- API Services → Auth Client: secured by · Outgoing requests rely on JWT attachment and route guards
- Auth Client → Controllers: requests · Client HTTP traffic targets REST controllers
- Shared UI → Feature Screens: supports · Shared helpers and UI primitives are used across screens
- Controllers → DTOs: binds · Controllers accept and return DTO contracts
- Controllers → Services: delegates · HTTP edge forwards work into business services
- Services → Repositories: uses · Services coordinate persistence through repositories
- Services → Audit Logging: logs · Operational actions are captured through audit logging
- Repositories → DbContext: queries · Repositories use the shared EF Core context
- DbContext → Entities: tracks · The context is built around the shared entity model
- Entities → Enums: uses · Entities depend on status and role enumerations
- Mapping → Entities: maps · AutoMapper translates between persistence models and DTOs
- Mapping → DTOs: maps · Mapping profile produces API response and request shapes
- Controllers → Notification Hub: pushes · Notification controller/service interactions can publish live updates
- Services → Notification Hub: broadcasts · Notification workflows can emit real-time messages
- Controllers → Mapping: formats · Controllers rely on mapped contract shapes for responses
