# openchargemap/ocm-system architecture

> Architecture diagram of the GitHub repository openchargemap/ocm-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openchargemap/ocm-system
- Repository: https://github.com/openchargemap/ocm-system

## Overview

##### Main Components
- API Layer:
- OCM.API.Core: Contains the core business logic, handling data-related operations and common services (managers, caching, and utilities).
- OCM.API.Client: Client libraries to interact with the API.
- OCM.API.Web: Implements the RESTful endpoints and MVC controllers to serve website pages and the API.
- OCM.API.Worker: Handles background tasks such as refreshing the cache or running an API mirror.
- Website UI:
- The “Website” folder houses the MVC-based website (controllers, views, and related assets) that support standard web interactions.
- Import/Processing Component:
- The “Import” directory contains various submodules (like the Import Manager UI, Import Worker, and Import Analysis) for processing and importing data from external sources.
- Frontend Application:
- The “App” folder includes client-side code (HTML, JavaScript, TypeScript, CSS) potentially used for a mobile or web application interface.
- Data Storage & Caching:
- SQL Server (with Entity Framework Core) for the primary relational data storage.
- MongoDB as a caching layer used heavily by the API to serve requests faster.
- External Services & Connectors:
- References to external services (such as third-party import providers and possibly external mapping APIs) are integrated in various parts of the system.
- Localisation:
- The “Localisation” folder suggests support for multiple languages, impacting many UI components.

##### Representing Relationships and Flows
- Clients (Developers, Mobile/Website Users, External Apps)
- Web Browser/Mobile App → API Gateway.
- That the API layer (OCM.API.Web) sits behind a gateway and communicates with both the SQL Server (via Entity Framework Core) and MongoDB (for caching).
- Communication links:
- API calls from external systems/AJAX calls from the Website.
- The API Worker periodically refreshes or resets the MongoDB cache.
- The Import modules connect to external data sources and write data to SQL Server (or update the cache).
- The Website’s MVC controllers serve pages and use similar backend services.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate the concerns by splitting the project into layers (API core, presentation layer through MVC, background services, and data access).
- Microservices/Worker Pattern: The background workers for cache refreshing and API mirroring can be seen as microservice-like components.
- Repository and Manager Pattern: The “Manager” classes (e.g., UserManager, AuditLogManager, NotificationManager) and “Provider” patterns in the codebase indicate a clean separation of business logic and data access.
- Extensibility: The design supports outsourcing further import providers or localisation components, making the system modular.

##### Relevant Technologies and Frameworks
- C# with .Net 6 and Entity Framework Core.
- SQL Server as the relational database.
- MongoDB for caching operations.
- ASP.NET MVC for the website and API controllers.
- TypeScript/Angular/Ionic references (via the App folder) for client-side development.
- Third-party libraries (as seen in the “ThirdParty” folder entries) for mapping, bootstrap aesthetics, and client-side validation.

- Notes on Interactions: For instance, “API calls use caching layer (MongoDB) to speed up responses” or “Import modules process external data feeds and update SQL Server.”

##### Final Advice
- Be comprehensive but avoid unnecessary over-complication. Capture each main component and their interdependencies.
- Critical data flows (client requests, API processing, background cache refresh, import flows) and the communication paths between the API/Web, Backend Services, and Data stores.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Clients
    Clients["External Clients"]:::client

    %% Presentation Layer
    subgraph "Presentation Layer"
        APIWeb["OCM.API.Web (REST & MVC)"]:::api
        Website["Website UI"]:::presentation
        Frontend["Frontend Application"]:::presentation
    end

    Clients -->|"APIcalls"| APIWeb
    Clients -->|"Webrequests"| Website
    Clients -->|"Appusage"| Frontend

    %% API Layer / Business Logic
    subgraph "API Layer / Business Logic"
        APICore["OCM.API.Core (Business Logic)"]:::api
        APIClient["OCM.API.Client"]:::api
        APIWorker["OCM.API.Worker"]:::api
    end

    APIWeb -->|"calls"| APICore
    APIClient --- APICore
    APIWorker -->|"refreshes"| MongoDBCache

    %% Import & Processing
    subgraph "Import & Processing"
        ImportModule["Import/Processing Component"]:::import
    end

    %% Data Storage & Caching
    subgraph "Data Storage & Caching"
        SQLServer["SQL Server (Entity Framework Core)"]:::storage
        MongoDBCache["MongoDB Cache"]:::storage
    end

    APICore -->|"reads/writes"| SQLServer
    APICore -->|"queries/updates"| MongoDBCache
    ImportModule -->|"imports-to"| SQLServer

    %% Localisation
    Localisation["Localisation"]:::localisation
    Website -->|"localisation"| Localisation

    %% External Services
    ExternalServices["External Services"]:::external
    ImportModule -->|"fetches"| ExternalServices
    APIWeb -->|"integrates"| ExternalServices

    %% Click Events
    click APICore "https://github.com/openchargemap/ocm-system/blob/master/API/OCM.Net/OCM.API.Core"
    click APIClient "https://github.com/openchargemap/ocm-system/blob/master/API/OCM.Net/OCM.API.Client"
    click APIWeb "https://github.com/openchargemap/ocm-system/blob/master/API/OCM.Net/OCM.API.Web"
    click APIWorker "https://github.com/openchargemap/ocm-system/blob/master/API/OCM.Net/OCM.API.Worker"
    click Website "https://github.com/openchargemap/ocm-system/blob/master/Website/OCM.Web"
    click ImportModule "https://github.com/openchargemap/ocm-system/tree/master/Import"
    click Frontend "https://github.com/openchargemap/ocm-system/tree/master/App"
    click MongoDBCache "https://github.com/openchargemap/ocm-system/blob/master/API/OCM.Net/OCM.API.Core/Util/CacheProviderMongoDB.cs"
    click Localisation "https://github.com/openchargemap/ocm-system/tree/master/Localisation"

    %% Styles
    classDef client fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef presentation fill:#ccffcc,stroke:#0c8,stroke-width:2px;
    classDef api fill:#cce5ff,stroke:#0056b3,stroke-width:2px;
    classDef import fill:#ffe6cc,stroke:#ff6600,stroke-width:2px;
    classDef storage fill:#ffffcc,stroke:#b3b300,stroke-width:2px;
    classDef localisation fill:#e6ccff,stroke:#800080,stroke-width:2px;
    classDef external fill:#d9d9d9,stroke:#808080,stroke-width:2px;
```
