# mttm774/medical-record-users-api architecture

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

- Interactive diagram: https://gitdiagram.com/mttm774/medical-record-users-api
- Repository: https://github.com/mttm774/medical-record-users-api

## Overview

##### Main Components
- API Backend: The heart of the application is the .NET Core API (located in the “medical-record-users-api” folder) which includes controllers (for Health Check and Users) and data models (representing entities like User, Medico, HistoriaGeneral, etc.).
- Database: Although not explicitly defined by a separate folder, the project provides a Dockerfile (mssql.Dockerfile) and environment files (mssql.env), indicating that an instance of Microsoft SQL Server is used as the storage layer. In addition, there is a SQL initialization script (docker/create_db.sql) for setting up the database.
- Containerization Infrastructure: There are several Dockerfiles (for the API, for mssql), as well as docker-compose files (docker-compose.develop.yml and docker-compose.yml) that define how the containers for the API and database are built and orchestrated locally.
- Deployment & Orchestration: Kubernetes manifests (under the “kubernetes” directory, with separate configurations for development and staging) prepare the service for deployment to container orchestration environments, possibly within Azure Kubernetes Service (AKS) for staging.
- Configuration & Environment Management: The project uses multiple environment configuration files (.env.dev, .env.example, and various appsettings files), ensuring different settings for development, staging, and production.
- Middleware: There is custom middleware (UptimeMiddleware.cs) indicating that there is extra logic (e.g., tracking uptime) embedded within the API request pipeline.
- External Testing/Integration: The “postman” folder indicates that there is a dedicated collection for API testing, including different environments (local and staging).

- At the center, you have the API service (your .NET Core API) which should be clearly labeled inside a container.
- Link the API service with the Kubernetes deployment configuration. For Development, show a local orchestration scenario and for Staging, show integration with an Azure Kubernetes cluster with an Ingress controller.

##### Patterns & Design Principles
- Separation of Concerns: The clear separation between API logic (controllers, models, middleware) and database access.
- Environment-Specific Configuration: Different appsettings and Docker/Kubernetes configuration files for development versus staging.
- Containerization and Microservices: Emphasis on Docker container images for reproducibility and Kubernetes manifests for orchestration in multi-node deployments.
- API Health and Monitoring: A simple health check endpoint indicates built-in monitoring and reliability checks.
- Infrastructure-as-Code: Usage of Docker Compose and Kubernetes YAML files shows that deployment and infrastructure are managed alongside code.

##### Relevant Technologies, Frameworks, & Libraries
- .NET Core and the .NET Framework (as indicated by the badges in the README) for building the API.
- C# as the programming language.
- Docker for containerization; multiple Dockerfiles are present (for the API and SQL Server instance).
- Kubernetes for orchestration of the containers in both development & staging environments.
- Possibly Entity Framework (given the typical approach with MedicalbdContext and data model files) connecting to SQL Server.
- Nginx is mentioned as a proxy/reverse proxy layer in one of the Docker Compose commands.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    subgraph "External Clients"
        EX["Postman (External Testing)"]:::external
    end

    %% API Service Layer
    subgraph "API Service Layer"
        API["API Backend (.NET Core)"]:::api
        CT["Controllers"]:::api
        DM["Data Models"]:::api
        MW["Middleware (Uptime)"]:::api
        CONF["Configuration Files"]:::api
        API --- CT
        API --- DM
        API --- MW
        API --- CONF

        CONF -->|"includes"| AS["appsettings.json"]:::config
        CONF -->|"includes"| ASD["appsettings.Development.json"]:::config
        CONF -->|"includes"| ASS["appsettings.Staging.json"]:::config
        CONF -->|"includes"| ENV1[".env.dev"]:::config
        CONF -->|"includes"| ENV2[".env.example"]:::config
    end

    %% Data Storage
    subgraph "Data Storage"
        DB["SQL Server Database"]:::database
    end

    %% Containerization & Deployment
    subgraph "Containerization & Deployment"
        DC["Docker Compose (Local)"]:::infrastructure
        KDEV["Kubernetes (Development)"]:::infrastructure
        KSTG["Kubernetes (Staging)"]:::infrastructure

        subgraph "API Container Config"
            DF["Dockerfile (API)"]:::infrastructure
            DCYM["docker-compose.yml"]:::infrastructure
            DCYDEV["docker-compose.develop.yml"]:::infrastructure
        end

        subgraph "Database Container Config"
            MDF["mssql.Dockerfile"]:::infrastructure
            MEN["mssql.env"]:::infrastructure
            MSQL["docker/create_db.sql"]:::infrastructure
        end

        DC --- KDEV
        DC --- KSTG
        API --- DC
        DB --- MDF
    end

    %% Connections
    EX -->|"HTTPRequest"| API
    API -->|"SQLQuery"| DB

    %% Click Events
    click API "https://github.com/mttm774/medical-record-users-api/tree/main/medical-record-users-api"
    click CT "https://github.com/mttm774/medical-record-users-api/tree/main/medical-record-users-api/Controllers"
    click DM "https://github.com/mttm774/medical-record-users-api/tree/main/medical-record-users-api/DataModel"
    click MW "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/Middleware/UptimeMiddleware.cs"
    click AS "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/appsettings.json"
    click ASD "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/appsettings.Development.json"
    click ASS "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/appsettings.Staging.json"
    click ENV1 "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/.env.dev"
    click ENV2 "https://github.com/mttm774/medical-record-users-api/blob/main/medical-record-users-api/.env.example"
    click DF "https://github.com/mttm774/medical-record-users-api/tree/main/Dockerfile"
    click DCYM "https://github.com/mttm774/medical-record-users-api/blob/main/docker-compose.yml"
    click DCYDEV "https://github.com/mttm774/medical-record-users-api/blob/main/docker-compose.develop.yml"
    click MDF "https://github.com/mttm774/medical-record-users-api/blob/main/mssql.Dockerfile"
    click MEN "https://github.com/mttm774/medical-record-users-api/blob/main/mssql.env"
    click MSQL "https://github.com/mttm774/medical-record-users-api/blob/main/docker/create_db.sql"
    click KDEV "https://github.com/mttm774/medical-record-users-api/tree/main/kubernetes/develop"
    click KSTG "https://github.com/mttm774/medical-record-users-api/tree/main/kubernetes/staging"
    click EX "https://github.com/mttm774/medical-record-users-api/tree/main/postman"

    %% Styles
    classDef api fill:#f9dcdc,stroke:#d9534f,stroke-width:2px;
    classDef database fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef infrastructure fill:#cff4fc,stroke:#055160,stroke-width:2px;
    classDef external fill:#fefefe,stroke:#6c757d,stroke-width:2px,stroke-dasharray: 5 5;
    classDef config fill:#fff3cd,stroke:#ffecb5,stroke-width:2px;
```
