# yyyanhkhoa/salary-management architecture

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

- Interactive diagram: https://gitdiagram.com/yyyanhkhoa/salary-management
- Repository: https://github.com/yyyanhkhoa/salary-management

## Overview

##### Project Type & Purpose
- This is a desktop-based salary management system built in C# (.NET) that uses Windows Forms for the user interface.
- Its main objective is to manage employee-related data; this includes employee details, positions, qualifications, union and unit history, among others.
- The application uses PostgreSQL as its data store, with Entity Framework handling data access (as evidenced by migration files, the EF context, and repository classes).

##### High-Level Components
a. User Interface (View)
- Located in the “View” directory, it contains multiple form subdirectories for employees, positions, qualifications, etc.
- These represent different modules/screens like Login, Home, Employee lists, detailed views, and administration interfaces.

b. Business Logic & Data Access (Controller)
- The “Controller” directory provides the core functionality. It includes:
- Infrastructure: Contains data input, entities definitions, extensions, and helper classes.
- Repository Pattern: A series of repository classes (for employees, positions, qualifications, etc.) that encapsulate data access.
- EF Migrations: The “Migrations” directory indicates that Entity Framework is used for database schema management and evolution.
- Database Context: The SalaryManContext.cs file is the central EF context connecting the app to PostgreSQL.

c. Domain Models (Model)
- The “Model” directory defines data models and view models for the application. These include detailed views of employees, position timelines, salary details, etc.
- They serve as the underlying data structure that the Controller and View layers use to exchange information.

d. Database (PostgreSQL)
- As per the README, PostgreSQL serves as the backend database. All data access is performed through EF to PostgreSQL.
- A separate “connection-string.txt” may also be used to set or override database connection details.

##### Relationships & Interactions
- The UI (View layer) interacts with the Controller, which contains both business logic and data access components.
- The Controller uses Repository classes to carry out CRUD operations and any business rules against the database.
- The domain models (Model layer) are passed between the Controller and the View, ensuring a clean separation of concerns.
- Database migrations ensure that the EF context and domain models remain in sync with the physical PostgreSQL database schema.

##### Architectural Patterns & Design Principles
- The project is layered: a separation of concerns between the presentation (View), business logic/data access (Controller), and domain models (Model).
- The Repository Pattern is used extensively. This encapsulates database transactions and abstracts away the complexity of data access.
- Entity Framework handles the ORM layer, as well as schema migrations, ensuring relational mapping with PostgreSQL.
- Although it’s not a full-blown MVC web application, the structured separation is similar in philosophy to MVC/MVVM.

##### Final Suggested Elements
- Clearly labeled components (e.g., "LoginForm", "Employee Management UI", "Controller/Repositories", "EF Migration", "PostgreSQL Database").
- From the UI layer to the Controller for user-triggered events.
- From the Controller to the Database to represent data operations.
- Back from the Controller to the UI to show processed data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI/Presentation Layer
    subgraph "UI/Presentation"
        LoginForm["Login Form"]:::ui
        Home["Home"]:::ui
        Employee["Employee Management UI"]:::ui
        Positions["Positions UI"]:::ui
        Qualifications["Qualifications UI"]:::ui
        Unions["Unions UI"]:::ui
        Units["Units UI"]:::ui
        Users["Users UI"]:::ui
    end

    %% Controller/Infrastructure Layer
    subgraph "Controller/Infrastructure"
        ControllerNode["Controller - Business Logic & Data Access"]:::controller
        EmpRepo["Employee Repository"]:::controller
        PosRepo["Position Repository"]:::controller
        SalaryManContext["EF Context (SalaryManContext)"]:::controller
        Migrations["EF Migrations"]:::controller
    end

    %% Domain Models Layer
    subgraph "Domain Models"
        EmployeeModel["Employee Model"]:::model
        EmployeeQualification["Employee Qualification Model"]:::model
        EmployeeSalary["Employee Salary Model"]:::model
    end

    %% Database Component (PostgreSQL)
    Database["PostgreSQL Database"]:::database

    %% Connections from UI to Controller
    LoginForm -->|"Action"| ControllerNode
    Home -->|"Action"| ControllerNode
    Employee -->|"Action"| ControllerNode
    Positions -->|"Action"| ControllerNode
    Qualifications -->|"Action"| ControllerNode
    Unions -->|"Action"| ControllerNode
    Units -->|"Action"| ControllerNode
    Users -->|"Action"| ControllerNode

    %% Connections within Controller Layer
    ControllerNode -->|"Uses"| EmpRepo
    ControllerNode -->|"Uses"| PosRepo
    EmpRepo -->|"Uses"| SalaryManContext
    PosRepo -->|"Uses"| SalaryManContext
    Migrations -->|"Syncs"| SalaryManContext

    %% Connections between Controller and Domain Models
    ControllerNode -->|"DataExchange"| EmployeeModel
    ControllerNode -->|"DataExchange"| EmployeeQualification
    ControllerNode -->|"DataExchange"| EmployeeSalary

    %% Connection from Controller to Database
    ControllerNode -->|"CRUD"| Database
    SalaryManContext -->|"ORM"| Database

    %% Click Events for UI Components
    click LoginForm "https://github.com/yyyanhkhoa/salary-management/tree/main/View/LoginForm"
    click Home "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Home"
    click Employee "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Employees"
    click Positions "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Positions"
    click Qualifications "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Qualifications"
    click Unions "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Unions"
    click Units "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Units"
    click Users "https://github.com/yyyanhkhoa/salary-management/tree/main/View/Users"

    %% Click Events for Controller Components
    click ControllerNode "https://github.com/yyyanhkhoa/salary-management/tree/main/Controller"
    click EmpRepo "https://github.com/yyyanhkhoa/salary-management/blob/main/Controller/Infrastructure/Repositories/RepositoryEmployee.cs"
    click PosRepo "https://github.com/yyyanhkhoa/salary-management/blob/main/Controller/Infrastructure/Repositories/RepositoryPosition.cs"
    click SalaryManContext "https://github.com/yyyanhkhoa/salary-management/blob/main/Controller/Infrastructure/SalaryManContext.cs"
    click Migrations "https://github.com/yyyanhkhoa/salary-management/tree/main/Controller/Migrations"

    %% Click Events for Domain Models
    click EmployeeModel "https://github.com/yyyanhkhoa/salary-management/blob/main/Model/Employee.cs"
    click EmployeeQualification "https://github.com/yyyanhkhoa/salary-management/blob/main/Model/EmployeeQualification.cs"
    click EmployeeSalary "https://github.com/yyyanhkhoa/salary-management/blob/main/Model/EmployeeSalary.cs"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef controller fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef model fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef database fill:#FAD7A0,stroke:#000,stroke-width:2px;
```
