clean-code
Pragmatic clean code standards for Delphi — concise, direct, no over-engineering
Architectural, dependency injection and UI patterns for the ACBr Project (Commercial Automation Brazil) ecosystem in Delphi.
$ npx -y skills add delphicleancode/delphi-spec-kit --skill acbr-components --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/acbr-componentsContext preview
The summary Claude sees to decide when to auto-load this skill.
Architectural, dependency injection and UI patterns for the ACBr Project (Commercial Automation Brazil) ecosystem in Delphi.
name: ACBr Project Patterns description: Architectural, dependency injection and UI patterns for the ACBr Project (Commercial Automation Brazil) ecosystem in Delphi.
The **ACBr Project** is vital for issuing NFe, CTe, NFCe, SAT, TEF and controlling fiscal/non-fiscal scales/printers in Brazil. It contains fantastic components, but due to its background and history of strong VCL coupling that accompanies older developers, the best practices below ensure maintainability in modernizations.
Do not instantiate components `TACBrNFe`, `TACBrCTe`, `TACBrPosPrinter`, etc., directly in the View Forms of the interface (`.dfm`/`.fmx`). This breaks the clean architecture, MVC and makes unit testing immensely difficult.
Create Service "Wrapper" classes or Infrasctructure Repositories that inject (via constructor or Service Locator) the system configurations to the Fiscal Engine.
type
INFeEmissor = interface
['{GUID}']
function EmitirNota(ANota: TBaseNFeModel): TEmissionResult;
end;
TNFeEmissorACBr = class(TInterfacedObject, INFeEmissor)
private
FAcbrNFe: TACBrNFe;
FConfig: IAppConfig;
procedure ConfigureComponent;
public
constructor Create(AConfig: IAppConfig);
destructor Destroy; override;
function EmitirNota(ANota: TBaseNFeModel): TEmissionResult;
end;It is a documented good practice to also isolate the libraries for each OS version if the project is cross-platform or supports VMs (e.g. Linux Docker vs Windows). Configure this *Always via code* dynamically within the wrapper referenced in Session 1, never at fixed design-time, using `LAcbrNFe.Configuracoes.Geral.SSLLib := libWinCrypt;` (or OpenSSL).
ACBrTEFD works heavily based on VCL events (OnExibeMensagem, OnAguardaDigitacao). Implement them by sending native bus events or defining a generic UI "Handler" injected into the class so that the component code remains in the Business/Gateway Layer, delegating only the "Draw to Screen" to specific interfaces that can be overridden in Headless/REST API scenarios.
ITefPresentationHandler = interface
procedure ShowTefMessage(const Msg: string);
procedure ClearTefMessage;
end;If you instantiate sub-function components (e.g. ACBrCEP) dynamically, avoid memory leaks.
function RetrieveAddress(const AZipCode: string): TAddressResponse;
var
LCepComponent: TACBrCEP;
begin
LCepComponent := TACBrCEP.Create(nil);
try
LCepComponent.WebService := wsViaCep;
//Perform the logic
LCepComponent.BuscarPorCEP(AZipCode);
Result := MapToResponse(LCepComponent.Enderecos[0]);
finally
LCepComponent.Free;
end;
end;When dealing with design-time components in `DataModules` created to facilitate events, use these mappings:
| ACBr component | Description | Typical Prefix | |-----------------|-----------|----------------| | `TACBrNFe` | Electronic Invoice | `acbrNfe` | | `TACBrNFCe`| Consumer Note | `acbrNfce` | | `TACBrCTe` | Knowledge of Transp. | `acbrCte` | | `TACBrBoleto`| Bills | `acbrBoleto` | | `TACBrTEFD`| TEF | `acbrTef` | | `TACBrPosPrinter`| Printers (EscPOS) | `acbrPosPrinter`| | `TACBrSAT` | SAT CF-e equipment | `acbrSat` |
An opinionated ecosystem of rules, skills and steerings to elevate Delphi development to state-of-the-art with Artificial Intelligence.
Repo: delphicleancode/delphi-spec-kit
Pragmatic clean code standards for Delphi — concise, direct, no over-engineering
Delphi code review checklist — quality, security, performance, SOLID, memory
Good memory management practices, memory leak prevention and exception handling in Delphi
SOLID implementation patterns for Delphi projects — Repository, Service, Factory, Strategy with constructor injection and interfaces
Implementation of the 23 GoF (Gang of Four) patterns in Object Pascal / Delphi with interfaces, TInterfacedObject and SOLID principles. Covers Creational,…
Standards for using DevExpress (DEXT) components in Delphi VCL applications