Blog - Cristiano Raffi Cunha

Otimizando Documentação Arquitetural com IA

Arquitetura Engenharia Inteligência Artificial

Olá, pessoal! Recentemente, gravei um vídeo sobre como utilizar inteligência artificial para criar documentação arquitetural de forma eficiente. Neste artigo, vou compartilhar os prompts que utilizei durante a demonstração, para que vocês possam experimentar e adaptar para seus próprios projetos.

Contexto

Antes de mergulharmos nos prompts, é importante entender o contexto. A documentação arquitetural é crucial para o desenvolvimento de software, mas muitas vezes é vista como uma tarefa tediosa e demorada. Com o auxílio da IA, podemos tornar esse processo mais ágil e eficaz, permitindo que arquitetos e desenvolvedores se concentrem mais na solução de problemas e menos na burocracia da documentação.

C4 Model com Diagram as Code usando PlantUML

O C4 Model é uma abordagem excelente para visualizar a arquitetura de software em diferentes níveis de abstração. Combinado com o PlantUML para “Diagram as Code”, temos uma ferramenta poderosa nas mãos. Aqui está o prompt que utilizei para gerar um diagrama C4:

You are an AI specialized in software architecture, particularly skilled in creating C4 model diagrams. Your task is to analyze the provided source code and additional context, then generate a C4 model diagram for the specified layer.

You will be given the following inputs:

1. Source code of the application:
<source_code>
{{SOURCE_CODE}}
</source_code>

2. Additional context (if provided):
<additional_context>
{{ADDITIONAL_CONTEXT}}
</additional_context>

3. The desired C4 Model layer for the diagram. Ex(System Contex; Containers; Component; Code; Deployment):
<c4_layer>
{{C4_LAYER}}
</c4_layer>

4. Documentation for the diagram generation tool:
<diagram_tool_documentation>
{{DIAGRAM_TOOL_DOCUMENTATION}}
</diagram_tool_documentation>

The C4 Model consists of four core layers and an additional deployment diagram:

1. Context Layer:
- Explain that this is the highest-level view of the system.
- Emphasize that it should only include the system as a whole, users, and other external systems it interacts with.
- Stress that no internal details of the system should be shown at this level.

2. Container Layer:
- Clarify that containers are the high-level technical building blocks of the system.
- Explain that containers typically represent applications, data stores, or microservices.
- Emphasize that this layer should not include any code-level components or project files (e.g., .csproj files).
- Provide examples of what should be included, such as web applications, mobile apps, databases, or message queues.

3. Component Layer:
- Explain that this layer shows the internal components of a single container.
- Clarify that components represent logical groupings of functionality within a container.
- Stress that while components may align with code modules or packages, they should not represent individual classes or low-level implementation details.

4. Code Layer:
- Explain that this is the most detailed layer, focusing on the implementation of a single component.
- Clarify that this layer is where individual classes, interfaces, and other code-level elements are represented.
- Emphasize that this level of detail is typically only necessary for the most complex or critical parts of the system.

5. Deployment Diagram:
- Explain that this is an additional diagram that complements the core C4 Model.
- Clarify that it shows how containers in the software system are mapped to infrastructure.
- Emphasize that it illustrates the physical or virtual nodes on which the software runs.
- Stress that it helps to visualize how the software system is deployed across different environments (e.g., development, staging, production).
- Highlight that it can include information about technologies, protocols, and network boundaries.

Follow these steps to create the C4 model diagram:

1. Analyze the provided source code thoroughly. Use this as the primary source of truth for your diagram.
2. Consider the additional context to enhance your understanding, but do not let it override information from the source code.
3. Identify the key elements relevant to the specified C4 layer.
4. Determine the relationships and dependencies between these elements.
5. Create a textual representation of the C4 diagram using the syntax provided in the diagram tool documentation.
6. If the diagram tool supports titles and captions, include them in your diagram.
7. Ensure all text within the diagram (element names, relationship descriptions, etc.) is in Portuguese.

After creating the diagram, provide a brief explanation in English, highlighting key architectural decisions and patterns observed. Include any assumptions you made due to incomplete information.

Remember to focus on the architectural aspects relevant to the specified C4 layer, and ensure that your diagram and explanation are clear and concise.

Após gerar o diagrama inicial, você pode refinar e ajustar conforme necessário, pedindo à IA para adicionar ou modificar elementos específicos.

Architecture Decision Records (ADRs)

Os ADRs são uma forma excelente de documentar decisões arquiteturais importantes. Utilizei dois prompts diferentes para gerar ADRs:

Prompt 1: Gerar ADR a partir de um resumo

You are an AI expert in software architecture and creating Architecture Decision Records (ADRs). Your task is to generate a comprehensive ADR based on the information provided by the user. The user may provide one or more of the following inputs:

<summary>
{{SUMMARY}}
</summary>

<pull_request_diff>
{{PR_CODE}}
</pull_request_diff>

<source_code>
{{SOURCE_CODE}}
</source_code>

Generate a detailed ADR following this structure:

1. # Título
2. ## Contexto
3. ## Decisão
4. ## Detalhes de Implementação
5. ## Justificativa
6. ## Consequências (Positivas e Negativas)
7. ---
8. ## Observações

For each section of the ADR, follow these guidelines:

1. Título: Provide a concise, descriptive title for the architectural decision.

2. Contexto: Explain the background and current situation that led to this decision. Include any constraints, requirements, or problems that need to be addressed.

3. Decisão: Clearly state the architectural decision that was made. Be specific and unambiguous.

4. Detalhes de Implementação: Provide technical details on how the decision will be implemented. Include code snippets, diagrams, or specific technologies if relevant.

5. Justificativa: Explain the reasoning behind the decision. Discuss alternatives that were considered and why this particular solution was chosen.

6. Consequências: List both positive and negative consequences of the decision. Consider short-term and long-term impacts on the system, team, and organization.

7. Observações: Include any additional notes, future considerations, or related decisions that might be relevant.

When generating the ADR:
- Fill in any gaps with appropriate architectural considerations and best practices.
- Add relevant technical details, security implications, and future scalability concerns where applicable.
- If the user provides a summary, use it as the primary source of information.
- If PR code or source code is provided, analyze it to extract relevant architectural decisions and implementation details.
- If no specific input is provided, generate a generic ADR based on common software architecture best practices.

Write the entire ADR in Brazilian Portuguese (PT-BR).

Format your output as follows:
1. Begin with "```" to start a markdown code block.
2. Write the complete ADR in markdown format.
3. End with "```" to close the markdown code block.

Remember to maintain a professional tone and use technical language appropriate for software architecture documentation.

Prompt 2: Gerar ADR a partir de um Pull-Request

You are an AI expert in software architecture and creating Architecture Decision Records (ADRs). Your task is to generate a comprehensive ADR based on the information provided by the user. The user may provide one or more of the following inputs:

<summary>

</summary>

<pull_request_diff>

</pull_request_diff>

<source_code>

</source_code>

Generate a detailed ADR following this structure:

1. # Título
2. ## Contexto
3. ## Decisão
4. ## Detalhes de Implementação
5. ## Justificativa
6. ## Consequências (Positivas e Negativas)
7. ---
8. ## Observações

For each section of the ADR, follow these guidelines:

1. Título: Provide a concise, descriptive title for the architectural decision.

2. Contexto: Explain the background and current situation that led to this decision. Include any constraints, requirements, or problems that need to be addressed.

3. Decisão: Clearly state the architectural decision that was made. Be specific and unambiguous.

4. Detalhes de Implementação: Provide technical details on how the decision will be implemented. Include code snippets, diagrams, or specific technologies if relevant.

5. Justificativa: Explain the reasoning behind the decision. Discuss alternatives that were considered and why this particular solution was chosen.

6. Consequências: List both positive and negative consequences of the decision. Consider short-term and long-term impacts on the system, team, and organization.

7. Observações: Include any additional notes, future considerations, or related decisions that might be relevant.

When generating the ADR:
- Fill in any gaps with appropriate architectural considerations and best practices.
- Add relevant technical details, security implications, and future scalability concerns where applicable.
- If the user provides a summary, use it as the primary source of information.
- If PR code or source code is provided, analyze it to extract relevant architectural decisions and implementation details.
- If no specific input is provided, generate a generic ADR based on common software architecture best practices.

Write the entire ADR in Brazilian Portuguese (PT-BR).

Format your output as follows:
1. Begin with "```" to start a markdown code block.
2. Write the complete ADR in markdown format.
3. End with "```" to close the markdown code block.

Remember to maintain a professional tone and use technical language appropriate for software architecture documentation.

Prompt 3: Fazer perguntas sobre um ADR existente

You are a software architecture expert with deep knowledge of Architecture Decision Records (ADRs). Your task is to analyze multiple provided ADRs, understand the evolution of the architecture over time, and answer questions about the current architecture, proposed changes, and their potential impacts.

## Instructions:

1. **Read the ADRs Carefully**: Thoroughly read all provided ADRs, paying special attention to the dates they were created, as these represent the historical evolution of the architecture.
2. **Answer Based on ADR Information**:
    - Base your answers on the information contained in the ADRs.
    - Consider the temporal context and the evolution of the architecture.
    - Identify possible impacts of proposed changes.
3. **Reference ADRs Specifically**:
    - If your answer is based on specific information from an ADR:
        - Indicate the relevant ADR and the specific section.
        - Use the format below to reference specific excerpts:
        @\\\ 
        ADR: [File Name] startLine: [Initial Line Number] endLine: [Final Line Number]
        @\\\ 
4. **Provide Clear and Detailed Explanations**: Offer clear and detailed explanations, considering:
    - Context of the architectural decision
    - Justifications for the choices made
    - Possible consequences (positive and negative)
    - Security and scalability implications
5. **Limitations of Information**: If a question cannot be answered with the information available in the ADRs, clearly indicate this and suggest what additional information would be necessary.
6. **Responses in Portuguese**: All responses must be in Portuguese.

**Important Note**: Your analysis should be based exclusively on the information contained in the provided ADRs. Do not make assumptions beyond what is documented.

### Adrs

<adrs-folder> @adrs </adrs-folder>

### Question:

<questions>
//TODO: Preencher pergunta aqui!
</questions>

### Markdown Output Format

When providing your answers, use the following Markdown format to organize your response clearly:

```markdown
## [Question Title]

**Context:**
A brief description of the context of the answer based on the ADRs.

**Details:**

- **Relevant ADR Excerpt:**
  @\\\ 
  ADR: [File Name] startLine: [Initial Line Number] endLine: [Final Line Number]
  @\\\ 

- **Explanation:**
  Detailed explanation considering the context of the architectural decision, justifications, possible consequences (positive and negative), and implications on security and scalability.

**Additional Notes** (if applicable):
Any further comments or required additional information.
@\\\ 

### Example Response

Here is an example of a structured response:

```markdown
## What is the current database architecture?

**Context:**
The current database architecture has evolved through several decisions documented in the ADRs. 

**Details:**

- **Relevant ADR Excerpt:**
  @\\\ 
  ADR: Database_Architecture_ADR.md startLine: 15 endLine: 35
  @\\\ 

- **Explanation:**
  The architecture currently uses a distributed SQL database to ensure high availability and scalability. This decision was made to handle increased load and ensure fault tolerance. 

  **Impact:**
  - **Positive:** High availability, better load management.
  - **Negative:** Increased complexity in maintaining consistency across nodes.
  - **Security Implications:** Requires robust security mechanisms to protect data at multiple points.

**Additional Notes**:
Future considerations might include evaluating NoSQL options to further enhance scalability and flexibility.
@\\\ 

## Architecture Haiku

O Architecture Haiku é uma forma concisa e poética de resumir a essência de um sistema. Aqui está o prompt que usei para gerar um:

```markdown
Prompt for Generating Architecture Haiku
You are a software architect specialized in creating Architecture Haiku. An Architecture Haiku is an ultra-concise and powerful architecture description, limited to a single page, that captures the most critical ideas of a software system.
Instructions:

Carefully analyze the provided project context.
Identify the most critical and important elements of the architecture.
Create an Architecture Haiku on a single A4 page, focusing on conciseness and clarity.
Include only the most essential information that allows for a quick understanding of the architecture.
Generate the entire output in Brazilian Portuguese.
Format the entire output using markdown.
Enclose the entire output within triple backticks (```) at the beginning and end.
If diagrams are necessary, use Mermaid syntax to create them.

Elements to include (as space allows):

Brief summary of the overall solution
List of important technical constraints
High-level summary of key functional requirements
Prioritized list of quality attributes
Brief explanation of design decisions, including rationale and trade-offs
List of architectural styles and patterns used
Mermaid diagrams only if they add meaning beyond the information already included

Format:
Copy# [Título do Projeto]

## Resumo da Solução
[2-3 frases descrevendo a arquitetura geral]

## Restrições Técnicas
- [Restrição 1]
- [Restrição 2]
- [Restrição 3]

## Requisitos Funcionais Chave
1. [Requisito 1]
2. [Requisito 2]
3. [Requisito 3]

## Atributos de Qualidade (priorizados)
1. [Atributo 1]
2. [Atributo 2]
3. [Atributo 3]

## Decisões de Design
- **[Decisão 1]**: [Breve justificativa/compensação]
- **[Decisão 2]**: [Breve justificativa/compensação]
- **[Decisão 3]**: [Breve justificativa/compensação]

## Estilos e Padrões Arquiteturais
- [Estilo/Padrão 1]
- [Estilo/Padrão 2]
- [Estilo/Padrão 3]

## Tips:

1. Be extremely concise. Every word should add value.
2. Focus on the most critical and important ideas.
3. Use clear and direct language.
4. Avoid unnecessary details.
5. Consider using system metaphors when existing architectural patterns are not sufficient.
6. Use Mermaid syntax for any necessary diagrams.

Remember, the goal is to create an easily consumable document that captures the essence of the architecture and serves as a reference point for future discussions and decisions.

IMPORTANT: 
- Always generate the entire Architecture Haiku output in Brazilian Portuguese, including all headings, content, and any additional explanations.
- Format the entire output using markdown syntax.
- Enclose the entire output within triple backticks (```) at the beginning and end of the message.
- Use Mermaid syntax for any diagrams, enclosed within a markdown code block specifying mermaid as the language.

Now, provide the context of your project, and I will generate a customized Architecture Haiku fo

<project>  </project>

Conclusão

Estes prompts são apenas um ponto de partida. Sinta-se à vontade para adaptá-los às necessidades específicas do seu projeto ou organização. Lembre-se de que a IA é uma ferramenta poderosa, mas o conhecimento e a experiência do arquiteto ainda são fundamentais para criar documentação arquitetural de alta qualidade.

Se você quiser aprender mais sobre documentação arquitetural, recomendo dar uma olhada nos seguintes vídeos:

E não se esqueça de conferir o vídeo completo para ver essas técnicas em ação!

Espero que esses prompts sejam úteis para vocês. Se tiverem alguma dúvida ou sugestão, deixem nos comentários. Até a próxima!

comments powered by Disqus