# nhat-tien/ipm architecture

> Architecture diagram of the GitHub repository nhat-tien/ipm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nhat-tien/ipm
- Repository: https://github.com/nhat-tien/ipm

## Overview

##### Main Components Identification
- Frontend Client: Represented by the IPM.ClientApp folder, a Svelte-based application that contains components, routes, services, and use cases to render the UI.
- Web API / Backend Gateway: The IPM.WebApi project acts as the API layer. It exposes RESTful endpoints (see ApiEndpoints, Controllers, Validators, etc.) and integrates with other backend layers.
- Application Layer: Located in the IPM.Application project, this layer holds the use cases, business logic, repositories’ interfaces, unit-of-work abstractions, services (like authentication and email), and utility classes. It orchestrates the business rules.
- Domain Layer: Found in the IPM.Domain project, where the core business entities (such as AffiliatedUnit, AidType, Project, User, etc.) are defined. This is where your business models and domain logic reside.
- Infrastructure/Data Access Layer: The IPM.Infrastructure project implements data access using Entity Framework Core. It includes the DB Context, repository implementations, database configurations, migrations, and unit-of-work implementations.
- Database: The system is designed to use PostgreSQL, as indicated in the README and configured by the EF Core migrations.
- External Services/Utilities: Although not a separate project, note the integration with external systems like email services, Minio (for file storage), and possibly JWT authentication. These are wired in via service registers and custom services in the WebApi layer.
- Docker Components: The Dockerfile and docker-compose.yml show that containerization is used for the deployment or development environment.

##### Relationships & Interactions
- The Frontend (Svelte) communicates with the Web API through HTTP REST endpoints.
- The Web API then invokes handlers in the Application Layer (use cases) for business operations.
- The Application Layer uses repository interfaces and unit-of-work abstractions to access and manipulate data.
- The Infrastructure Layer provides concrete implementations of these interfaces, and communicates directly with the PostgreSQL database using Entity Framework Core.
- Additional services such as authentication, email, and file handling are integrated in the Web API layer and further support the overall operations.
- Docker is used to encapsulate and manage services, such as spinning up database containers and possibly API containers.

##### Architectural Patterns & Design Principles
- Adopts a layered (clean) architecture that decouples business logic, infrastructure concerns, and presentation (UI).
- Employs dependency inversion by defining interfaces in the Application layer while using concrete implementations in Infrastructure.
- Uses use case (or command/query) based organization within the Application layer, which can be clearly represented as individual “business process” blocks.
- Separation of concerns with distinct routing (Frontend pages, API endpoints), business logic (Application use cases), and data persistence (Infrastructure/EF Core).

##### Relevant Technologies/Frameworks
- Backend: .NET Core 8.0, Entity Framework Core, ASP.NET Core Web API.
- Frontend: Svelte, NodeJS (v20+), Vite.
- Database: PostgreSQL.
- Containerization: Docker, Docker Compose.
- Additional Libraries: JWT authentication, Email Service implementations, and supporting middleware/filters.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "UI/Client"
        FE("Frontend (IPM.ClientApp - Svelte)"):::frontend
    end

    subgraph "API Gateway"
        API("API Gateway (IPM.WebApi)"):::api
    end

    subgraph "Application"
        APP("Application Layer (IPM.Application)"):::application
    end

    subgraph "Domain"
        DOM("Domain Layer (IPM.Domain)"):::domain
    end

    subgraph "Infrastructure/Data Access"
        INF("Infrastructure/Data Access (IPM.Infrastructure)"):::infrastructure
    end

    subgraph "Database"
        DB("PostgreSQL Database"):::database
    end

    subgraph "External Services"
        EMAIL("Email Service (IPM.WebApi - Email)"):::external
        JWT("JWT Service (IPM.WebApi - JWT)"):::external
        MINIO("Minio Service (IPM.WebApi - Minio)"):::external
    end

    subgraph "Deployment (Docker)"
        DOCKERFILE("Dockerfile"):::docker
        DOCKERCOMPOSE("docker-compose.yml"):::docker
    end

    FE -->|"HTTPRequest"| API
    API -->|"InvokeUseCase"| APP
    APP -->|"ExecuteBusinessLogic"| DOM
    APP -->|"RepositoryCall"| INF
    INF -->|"DataPersistence"| DB
    API -->|"SendEmail"| EMAIL
    API -->|"GenerateToken"| JWT
    API -->|"StoreFile"| MINIO
    DOCKERFILE --- DOCKERCOMPOSE
    DOCKERFILE --- API
    DOCKERFILE --- DB

    click FE "https://github.com/nhat-tien/ipm/blob/main/src/IPM.ClientApp"
    click API "https://github.com/nhat-tien/ipm/blob/main/src/IPM.WebApi"
    click APP "https://github.com/nhat-tien/ipm/blob/main/src/IPM.Application"
    click DOM "https://github.com/nhat-tien/ipm/blob/main/src/IPM.Domain"
    click INF "https://github.com/nhat-tien/ipm/tree/main/src/IPM.Infrastructure/EntityFrameworkDataAccess"
    click DB "https://github.com/nhat-tien/ipm/tree/main/src/IPM.Infrastructure/Migrations"
    click EMAIL "https://github.com/nhat-tien/ipm/blob/main/src/IPM.WebApi/Services/EmailService.cs"
    click JWT "https://github.com/nhat-tien/ipm/blob/main/src/IPM.WebApi/Services/JwtService.cs"
    click MINIO "https://github.com/nhat-tien/ipm/blob/main/src/IPM.WebApi/Services/MinioService.cs"
    click DOCKERFILE "https://github.com/nhat-tien/ipm/tree/main/Dockerfile"
    click DOCKERCOMPOSE "https://github.com/nhat-tien/ipm/blob/main/docker-compose.yml"

    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef api fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef application fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef domain fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef infrastructure fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
    classDef database fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
    classDef external fill:#D7CCC8,stroke:#5D4037,stroke-width:2px;
    classDef docker fill:#B2DFDB,stroke:#00796B,stroke-width:2px;
```
