Skip to content

Instantly share code, notes, and snippets.

View pedrovasconcellos's full-sized avatar

Pedro Vasconcellos pedrovasconcellos

View GitHub Profile
@pedrovasconcellos
pedrovasconcellos / CLEAN_ARCHITECTURE.md
Last active November 7, 2025 02:00
Clean Architecture Memory Bank

Clean Architecture Memory Bank

TL;DR

  • Clean Architecture keeps business rules independent from delivery so changes in frameworks never break core logic.
  • Dependencies flow inward: infrastructure → adapters → application → domain.
  • Use cases expose ports; adapters implement them; infrastructure wire everything together under cmd/ entrypoints.

Core Principles

  • Separation of concerns: Domain logic lives in entities/value objects; use cases orchestrate; adapters translate boundaries; infrastructure provide tooling (frameworks and drivers) only.
  • Dependency rule: Inner layers know nothing about outer layers—never import adapters or infrastructure from the domain or application packages.
@pedrovasconcellos
pedrovasconcellos / ResultT.go
Created April 28, 2023 20:19
Result class in Go Language
type ResultT struct {
Response interface{}
Errors map[string]string
}
func NewResultT() ResultT {
return ResultT{
Response: nil,
Errors: make(map[string]string),
}
@pedrovasconcellos
pedrovasconcellos / ResultT.rs
Last active April 28, 2023 20:15
Result class in Rust Language
use std::collections::HashMap;
pub struct ResultT<T> {
response: Option<T>,
errors: HashMap<String, String>,
}
impl<T> ResultT<T> {
pub fn new() -> Self {
ResultT {
@pedrovasconcellos
pedrovasconcellos / EnumExtensions.cs
Last active June 7, 2023 17:38
InvalidToDefaultEnumConverter
public static class EnumExtensions
{
public static T? GetDefaultValue<T>() where T : Enum
{
var enumType = typeof(T);
var defaultValueAttribute = Attribute
.GetCustomAttribute(enumType, typeof(DefaultValueAttribute)) as DefaultValueAttribute;
if (defaultValueAttribute is not null &&
defaultValueAttribute.Value is T)
@pedrovasconcellos
pedrovasconcellos / EnumExtension.cs
Last active April 12, 2023 19:04
EnumExtension with GetDescription
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
public static class EnumExtension
{
public static string GetDescription<TEnum>(this TEnum value) where TEnum : Enum
{
FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
@pedrovasconcellos
pedrovasconcellos / ObjectExtension.cs
Created December 31, 2020 02:59
ObjectExtension with CopyObject and CopyPropertiesTo
using System.IO;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Linq;
namespace Vasconcellos.Extensions
{
public static class ObjectExtension
{
/// <summary>
@pedrovasconcellos
pedrovasconcellos / Pagination.cs
Last active April 28, 2023 20:01
Pagination
public async Task<IActionResult> Example(int? page, int? rows)
{
IList<object> entities = await _service.Get();
if (page != null && page > 0 && rows != null && rows > 0)
{
entities = query.Skip((int)(rows * (page - 1))).Take((int)rows).ToList();
}
else
entities = query.ToList();