# codewithgradi/gradiapi architecture

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

- Interactive diagram: https://gitdiagram.com/codewithgradi/gradiapi
- Repository: https://github.com/codewithgradi/gradiapi

## Overview

#### Purpose and Entry Point
GradiApi is a .NET 10 ASP.NET Core REST API backing a personal portfolio/profile: one personal profile with associated experience and project records. Application composition, HTTP pipeline, environment loading, CORS, OpenAPI, DI, and exception handling begin in `Program.cs`; service registrations are centralized in `Extentions/ServiceExtentions.cs`.

#### HTTP API Boundary
Three controllers expose the resource-oriented API: personal profile creation/read/update, and list/create/update operations for experiences and projects. Controllers should remain the transport boundary, accepting request DTOs and returning response DTOs rather than persistence entities.
- `Controllers/PersonalController.cs`
- `Controllers/ExperienceController.cs`
- `Controllers/ProjectController.cs`

#### Application Services and Business Rules
Each resource has a service layer between controllers and persistence. This is the intended location for orchestration, profile-association checks when creating projects/experiences, update semantics, and translation of domain failures into custom exceptions.
- `Services/PersonalService.cs`
- `Services/ExperienceService.cs`
- `Services/ProjectService.cs`
- `Exceptions/BusinessRuleException.cs`

#### Persistence Boundary
Repository interfaces abstract data access from services; concrete repositories use the EF Core context. PostgreSQL is the sole documented durable external dependency. The context owns entity sets, relationships, and EF mapping; migrations capture the deployable schema history.
- `Data/AppDbContext.cs`
- `Interface/IPersonalRepo.cs`
- `Repo/PersonalRepo.cs`
- `Migrations/20260717182018_init.cs`

#### Domain Aggregate and Relationships
`Personal` is the aggregate-facing profile data returned to clients, containing structured social links and associations to projects and experiences. `Project` and `Experience` are individually updated records and include update timestamps. Array-like profile and project fields are persisted through EF/PostgreSQL mapping.
- `Models/Personal.cs`
- `Models/Project.cs`
- `Models/Experience.cs`
- `Utils/Socials.cs`

#### Contract Transformation Flow
The main request path is: client JSON → controller DTO → service → repository/entity → PostgreSQL; reads reverse this flow into response DTOs. Mapperly-based mappers isolate API contracts from entities and protect controller/service code from manual field conversion.
- `DTO/PostPersonalDto.cs`
- `DTO/GetPersonalDto.cs`
- `Mappers/PersonalMappers.cs`
- `Mappers/ExperienceMappers.cs`

#### Runtime, Configuration, and Operations
The runtime is `net10.0` ASP.NET Core with EF Core, Npgsql PostgreSQL provider, snake_case naming conventions, DotNetEnv, and Mapperly. Configuration selects `Dev` or `Prod` connection strings via `Env`, while frontend URLs configure CORS. Development exposes OpenAPI. The container deployment boundary is defined by `Dockerfile`; PostgreSQL must be supplied externally.
- `gradiapi.csproj`
- `appsettings.json`
- `appsettings.Development.json`
- `Dockerfile`

Main entry points: [`Controllers/PersonalController.cs`](https://github.com/codewithgradi/gradiapi/blob/main/Controllers/PersonalController.cs) (Resource controllers), [`Data/AppDbContext.cs`](https://github.com/codewithgradi/gradiapi/blob/main/Data/AppDbContext.cs) (EF Core context), [`Models/Personal.cs`](https://github.com/codewithgradi/gradiapi/blob/main/Models/Personal.cs) (Personal aggregate), [`Interface/IPersonalRepo.cs`](https://github.com/codewithgradi/gradiapi/blob/main/Interface/IPersonalRepo.cs) (Repository abstraction)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; Operations"]
  node_aspnet{{"ASP.NET Core host<br/>runtime<br/>[Program.cs]"}}
  node_services_registration["Service registration<br/>DI extensions"]
  node_configuration["Environment configuration<br/>settings<br/>[appsettings.json]"]
  node_container["Container image<br/>Docker deployment"]
end

subgraph group_api["HTTP API"]
  node_controllers["Resource controllers<br/>HTTP controllers"]
  node_dto_contracts["Request/response DTOs<br/>API contracts<br/>[PostPersonalDto.cs]"]
end

subgraph group_application["Application"]
  node_personal_service["Personal service<br/>application service<br/>[PersonalService.cs]"]
  node_experience_service["Experience service<br/>application service"]
  node_project_service["Project service<br/>application service<br/>[ProjectService.cs]"]
  node_business_exception["Business rule exception<br/>domain failure"]
  node_mappers["Mapperly mappers<br/>contract mapper<br/>[PersonalMappers.cs]"]
end

subgraph group_data["Domain &amp; Persistence"]
  node_repository_contract["Repository abstraction<br/>repository interface<br/>[IPersonalRepo.cs]"]
  node_repository["EF repositories<br/>repository implementation<br/>[PersonalRepo.cs]"]
  node_db_context[("EF Core context<br/>ORM context<br/>[AppDbContext.cs]")]
  node_personal_aggregate["Personal aggregate<br/>domain model<br/>[Personal.cs]"]
  node_project["Project<br/>domain model<br/>[Project.cs]"]
  node_experience["Experience<br/>domain model<br/>[Experience.cs]"]
  node_migrations["Schema migrations<br/>EF migrations"]
end

node_postgres[("PostgreSQL<br/>external database")]

node_container -->|"runs"| node_aspnet
node_configuration -->|"configures"| node_aspnet
node_aspnet -->|"loads DI"| node_services_registration
node_services_registration -->|"hosts"| node_controllers
node_controllers -->|"accepts and returns"| node_dto_contracts
node_controllers -->|"profile operations"| node_personal_service
node_controllers -->|"experience operations"| node_experience_service
node_controllers -->|"project operations"| node_project_service
node_controllers -->|"maps contracts"| node_mappers
node_personal_service -->|"uses"| node_repository_contract
node_experience_service -->|"uses"| node_repository_contract
node_project_service -->|"uses"| node_repository_contract
node_personal_service -->|"raises"| node_business_exception
node_experience_service -->|"raises"| node_business_exception
node_project_service -->|"raises"| node_business_exception
node_mappers -->|"transforms"| node_personal_aggregate
node_repository_contract -->|"implemented by"| node_repository
node_repository -->|"queries and saves"| node_db_context
node_db_context -->|"maps"| node_personal_aggregate
node_personal_aggregate -->|"has projects"| node_project
node_personal_aggregate -->|"has experiences"| node_experience
node_migrations -->|"defines schema"| node_db_context
node_db_context -->|"persists to"| node_postgres
node_configuration -.->|"connection string"| node_postgres

click node_aspnet "https://github.com/codewithgradi/gradiapi/blob/main/Program.cs"
click node_services_registration "https://github.com/codewithgradi/gradiapi/blob/main/Extentions/ServiceExtentions.cs"
click node_configuration "https://github.com/codewithgradi/gradiapi/blob/main/appsettings.json"
click node_container "https://github.com/codewithgradi/gradiapi/blob/main/Dockerfile"
click node_controllers "https://github.com/codewithgradi/gradiapi/blob/main/Controllers/PersonalController.cs"
click node_dto_contracts "https://github.com/codewithgradi/gradiapi/blob/main/DTO/PostPersonalDto.cs"
click node_personal_service "https://github.com/codewithgradi/gradiapi/blob/main/Services/PersonalService.cs"
click node_experience_service "https://github.com/codewithgradi/gradiapi/blob/main/Services/ExperienceService.cs"
click node_project_service "https://github.com/codewithgradi/gradiapi/blob/main/Services/ProjectService.cs"
click node_business_exception "https://github.com/codewithgradi/gradiapi/blob/main/Exceptions/BusinessRuleException.cs"
click node_mappers "https://github.com/codewithgradi/gradiapi/blob/main/Mappers/PersonalMappers.cs"
click node_repository_contract "https://github.com/codewithgradi/gradiapi/blob/main/Interface/IPersonalRepo.cs"
click node_repository "https://github.com/codewithgradi/gradiapi/blob/main/Repo/PersonalRepo.cs"
click node_db_context "https://github.com/codewithgradi/gradiapi/blob/main/Data/AppDbContext.cs"
click node_personal_aggregate "https://github.com/codewithgradi/gradiapi/blob/main/Models/Personal.cs"
click node_project "https://github.com/codewithgradi/gradiapi/blob/main/Models/Project.cs"
click node_experience "https://github.com/codewithgradi/gradiapi/blob/main/Models/Experience.cs"
click node_migrations "https://github.com/codewithgradi/gradiapi/blob/main/Migrations/20260717182018_init.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_aspnet,node_services_registration,node_configuration,node_container toneBlue
class node_controllers,node_dto_contracts toneAmber
class node_personal_service,node_experience_service,node_project_service,node_business_exception,node_mappers toneMint
class node_repository_contract,node_repository,node_db_context,node_personal_aggregate,node_project,node_experience,node_migrations toneRose
class node_postgres toneNeutral
```

## Components

### Runtime & Operations

- [ASP.NET Core host](https://github.com/codewithgradi/gradiapi/blob/main/Program.cs): runtime · Composes middleware, DI, CORS, OpenAPI, and exception handling. · `Program.cs`
- [Service registration](https://github.com/codewithgradi/gradiapi/blob/main/Extentions/ServiceExtentions.cs): DI extensions · `Extentions/ServiceExtentions.cs`
- [Environment configuration](https://github.com/codewithgradi/gradiapi/blob/main/appsettings.json): settings · Selects Dev or Prod connection strings and frontend CORS origins. · `appsettings.json`
- [Container image](https://github.com/codewithgradi/gradiapi/blob/main/Dockerfile): Docker deployment · `Dockerfile`

### HTTP API

- [Resource controllers](https://github.com/codewithgradi/gradiapi/blob/main/Controllers/PersonalController.cs): HTTP controllers · Personal, experience, and project REST endpoints. · `Controllers/PersonalController.cs`
- [Request/response DTOs](https://github.com/codewithgradi/gradiapi/blob/main/DTO/PostPersonalDto.cs): API contracts · Keep transport payloads separate from persistence entities. · `DTO/PostPersonalDto.cs`

### Application

- [Personal service](https://github.com/codewithgradi/gradiapi/blob/main/Services/PersonalService.cs): application service · `Services/PersonalService.cs`
- [Experience service](https://github.com/codewithgradi/gradiapi/blob/main/Services/ExperienceService.cs): application service · Applies association checks and update semantics. · `Services/ExperienceService.cs`
- [Project service](https://github.com/codewithgradi/gradiapi/blob/main/Services/ProjectService.cs): application service · Applies association checks and update semantics. · `Services/ProjectService.cs`
- [Business rule exception](https://github.com/codewithgradi/gradiapi/blob/main/Exceptions/BusinessRuleException.cs): domain failure · `Exceptions/BusinessRuleException.cs`
- [Mapperly mappers](https://github.com/codewithgradi/gradiapi/blob/main/Mappers/PersonalMappers.cs): contract mapper · Converts DTOs and domain entities at the API boundary. · `Mappers/PersonalMappers.cs`

### Domain & Persistence

- [Repository abstraction](https://github.com/codewithgradi/gradiapi/blob/main/Interface/IPersonalRepo.cs): repository interface · `Interface/IPersonalRepo.cs`
- [EF repositories](https://github.com/codewithgradi/gradiapi/blob/main/Repo/PersonalRepo.cs): repository implementation · Concrete data access used by resource services. · `Repo/PersonalRepo.cs`
- [EF Core context](https://github.com/codewithgradi/gradiapi/blob/main/Data/AppDbContext.cs): ORM context · Owns entity sets, relationships, and PostgreSQL mappings. · `Data/AppDbContext.cs`
- [Personal aggregate](https://github.com/codewithgradi/gradiapi/blob/main/Models/Personal.cs): domain model · Profile root with social links, projects, and experiences. · `Models/Personal.cs`
- [Project](https://github.com/codewithgradi/gradiapi/blob/main/Models/Project.cs): domain model · Associated record with update timestamp. · `Models/Project.cs`
- [Experience](https://github.com/codewithgradi/gradiapi/blob/main/Models/Experience.cs): domain model · Associated record with update timestamp. · `Models/Experience.cs`
- [Schema migrations](https://github.com/codewithgradi/gradiapi/blob/main/Migrations/20260717182018_init.cs): EF migrations · Deployable PostgreSQL schema history. · `Migrations/20260717182018_init.cs`

### Other components

- **PostgreSQL**: external database · Externally supplied durable datastore.

## Connections

- Container image → ASP.NET Core host: runs
- Environment configuration → ASP.NET Core host: configures
- ASP.NET Core host → Service registration: loads DI
- Service registration → Resource controllers: hosts
- Resource controllers → Request/response DTOs: accepts and returns
- Resource controllers → Personal service: profile operations
- Resource controllers → Experience service: experience operations
- Resource controllers → Project service: project operations
- Resource controllers → Mapperly mappers: maps contracts
- Personal service → Repository abstraction: uses
- Experience service → Repository abstraction: uses
- Project service → Repository abstraction: uses
- Personal service → Business rule exception: raises
- Experience service → Business rule exception: raises
- Project service → Business rule exception: raises
- Mapperly mappers → Personal aggregate: transforms
- Repository abstraction → EF repositories: implemented by
- EF repositories → EF Core context: queries and saves
- EF Core context → Personal aggregate: maps
- Personal aggregate → Project: has projects
- Personal aggregate → Experience: has experiences
- Schema migrations → EF Core context: defines schema
- EF Core context → PostgreSQL: persists to
- Environment configuration → PostgreSQL: connection string
