Skip to content

Commit 69edb6c

Browse files
authored
Merge pull request #17 from felipemelozx/doc/add-adr
doc: add adr
2 parents b2eacbd + 99d4bf1 commit 69edb6c

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

doc/adr/adr.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
## Architectural Decision Record (ADR)
2+
3+
### Context
4+
5+
The project aims to build a full-stack financial management application, focusing on learning Java, Spring, React.js, Clean Architecture, CI/CD, and testing. The system should support authentication, CRUD operations for resources (transactions, budget, recurring accounts), a dashboard with charts, and optional evolutions such as integration with external APIs and PDF report generation.
6+
7+
### Decision
8+
9+
We will adopt the following architectural decisions for the project:
10+
11+
1. **Code Organization (Backend):** The code will be organized in a modular fashion, with each entity having its own directory. Each directory will contain:
12+
- **Entity (Model):** Represents the application's data and domain.
13+
- **Controller:** Handles HTTP requests and interacts with the service layer.
14+
- **Service:** Contains business logic, orchestrating interaction between the Controller and Repository.
15+
- **Repository:** Manages database communication (data access).
16+
- **DTOs:** Data Transfer Objects, used for input and output in APIs.
17+
2. **Frameworks and Languages:**
18+
- Spring Boot 3.4.4 with Java 17, following Clean Architecture and SOLID principles.
19+
- Layered architecture: Controller → Service → Repository.
20+
3. **Authentication and Security:**
21+
- JWT with Spring Security for stateless authentication and support for roles (USER, ADMIN).
22+
- CORS configuration and protection against SQL Injection.
23+
4. **Frontend:**
24+
- React.js with Vite (or Angular as an alternative), integrated with the backend via REST APIs.
25+
5. **Database:**
26+
- H2 for development; PostgreSQL for production, managed with Flyway.
27+
6. **CI/CD:**
28+
- GitHub Actions for linting, tests (unit, integration, E2E), static analysis (CodeQL, SonarQube), and deployment (manual/automatic) to AWS.
29+
7. **Testing:**
30+
- Coverage ≥ 80% with JUnit 5, Mockito, and Cypress (frontend E2E).
31+
8. **Documentation:**
32+
- OpenAPI for APIs and ADRs for architectural decisions.
33+
9. **Infrastructure:**
34+
- Docker and Docker Compose for local environment; AWS for production, managed with Terraform.
35+
10. **Optional Evolutions:**
36+
- Cache with Redis, PDF report generation, and external integrations.
37+
38+
### Pedagogical Objective
39+
40+
Practice full-stack development and DevOps, including Infrastructure as Code (IaC).
41+
42+
### Scope
43+
44+
MVP with CRUD operations, authentication, and dashboard; evolutions with external integrations.
45+
46+
### Terraform Details
47+
48+
Deployment to AWS requires configuration of resources such as EC2 (for the application), RDS (PostgreSQL), and VPC (secure network), which must be provisioned in an automated, versioned, and reproducible manner to support CI/CD and scalability.
49+
50+
### Alternatives Considered
51+
52+
### Infrastructure Management
53+
54+
- **Terraform:**
55+
- **Pros:** Declarative, multi-cloud, active community, GitHub Actions integration, versioned with Git.
56+
- **Cons:** Learning curve for HCL syntax, need to manage state (.tfstate).
57+
- **AWS CloudFormation:**
58+
- **Pros:** Native to AWS, direct integration with services.
59+
- **Cons:** Less flexible for multi-cloud, more verbose syntax (JSON/YAML).
60+
- **AWS CDK:**
61+
- **Pros:** Uses languages like Java, allows programmatic logic.
62+
- **Cons:** More complex for teams focused on declarative IaC.
63+
64+
### Backend Framework
65+
66+
- **Spring Boot 3.4:**
67+
- **Pros:** Large community, native support for REST, Security, JPA.
68+
- **Cons:** Initially complex advanced configuration.
69+
- **Quarkus:**
70+
- **Pros:** Fast startup, lower memory consumption.
71+
- **Cons:** Less adoption, less documentation for beginners.
72+
- **Choice:** Spring Boot (aligns with pedagogical and career objectives).
73+
74+
### Authentication
75+
76+
- **JWT + Spring Security:**
77+
- **Pros:** Stateless, scalable, easy integration.
78+
- **Cons:** Logout and refresh tokens require additional implementation.
79+
- **OAuth 2.0:**
80+
- **Pros:** Supports SSO, robust for delegated authentication.
81+
- **Cons:** Unnecessary complexity for MVP.
82+
- **Choice:** JWT (simplicity and scope adequacy).
83+
84+
### Frontend
85+
86+
- **React.js + Vite:**
87+
- **Pros:** Lightweight, fast startup.
88+
- **Cons:** Manual state management.
89+
- **Angular:**
90+
- **Pros:** Structured, includes integrated tools (e.g., CLI, RxJS).
91+
- **Cons:** Steeper learning curve.
92+
- **Vue.js:**
93+
- **Pros:** Simple, lightweight, good documentation.
94+
- **Cons:** Less adoption in corporate projects.
95+
- **Choice:** Angular, as it is more commonly used with Java in corporate projects.
96+
97+
### Database
98+
99+
- **H2 (dev) + PostgreSQL (prod):**
100+
- **Pros:** H2 is lightweight for development; PostgreSQL is robust, scalable, widely used.
101+
- **Cons:** Migration configuration requires care.
102+
- **MySQL:**
103+
- **Pros:** Popular, easy configuration.
104+
- **Cons:** Fewer advanced features than PostgreSQL.
105+
- **Choice:** H2 and PostgreSQL (balance between rapid development and robustness in production).
106+
107+
### Consequences
108+
109+
### Positive
110+
111+
- **Scalability:** Stateless architecture and AWS deployment allow future growth.
112+
- **Quality:** CI/CD from Sprint 1, with linting, tests, and static analysis, ensures robust code.
113+
- **Learning:** Stack (Spring Boot, React, CI/CD) covers modern full-stack development fundamentals.
114+
- **Documentation:** OpenAPI and ADRs facilitate maintenance and technical presentation.
115+
- **Flexibility:** Clean Architecture and well-defined layers allow evolutions (Redis, PDF, Google Sheets) without major refactoring.
116+
117+
### Negative
118+
119+
- **Initial Complexity:** Configuring Spring Security, Flyway, and GitHub Actions may be challenging for beginners.
120+
- **Maintenance:** Managing refresh tokens (JWT) and Flyway migrations requires attention.
121+
- **Learning Curve:** Angular and E2E tests (Cypress) may require extra effort for less experienced teams.
122+
- **Cost:** Deployment on AWS may incur additional costs (beyond pedagogical scope).
123+
124+
### Implementation Plan
125+
126+
1. **Sprint 1: Setup and Quality**
127+
- Configure Spring Boot project with H2, Flyway, and JPA entities.
128+
- Create GitHub Actions pipeline (Lint, Unit Tests, CodeQL, SonarQube).
129+
- Document ADRs and initial modeling (ER Diagram).
130+
2. **Sprint 2: Authentication**
131+
- Implement /auth endpoints (register, login, me) with JWT.
132+
- Configure CORS and integration tests (MockMvc).
133+
3. **Sprints 3–5: CRUD and Tests**
134+
- Develop Controllers, Services, and Repositories for Transactions, Budget, Envelopes, and Recurring Accounts.
135+
- Implement DTOs, validations, and global error handling (@ControllerAdvice).
136+
- Unit tests, integration tests (Testcontainers), and coverage ≥80%.
137+
## 4. **Sprint 6: Front-end**
138+
139+
- **Angular Setup**: Configure the Angular project using the latest version compatible with Java 17. Utilize the Angular CLI for project scaffolding and development.
140+
- **UI Development**: Develop user interfaces for login, CRUD operations, and dashboard using Angular components, services, and routing.
141+
- **E2E Testing with Cypress**: Implement end-to-end tests for the front-end to ensure the application functions as expected across different user scenarios.
142+
143+
## 5. **Sprint 7: DevOps**
144+
145+
- **Docker Multi-stage Build**: Create a multi-stage Dockerfile to optimize the image size and build process. The first stage compiles the application, and the second stage packages it into a minimal runtime image.[Java Tech Blog](https://javanexus.com/blog/docker-compose-spring-boot-postgresql?utm_source=chatgpt.com)
146+
- **Docker Compose**: Set up a `docker-compose.yml` file to define and run multi-container Docker applications, including services for the application, PostgreSQL database, and Redis cache.
147+
- **GitHub Actions CI/CD Pipeline**: Configure GitHub Actions workflows for continuous integration and deployment. The pipeline should include steps for code checkout, JDK setup, Maven build, artifact archiving, and deployment to AWS EC2 instances using SCP and SSH.[Medium](https://medium.com/%40muhibgazi/spring-boot-application-deployment-to-aws-ec2-with-github-actions-731ce940a135?utm_source=chatgpt.com)
148+
- **Health Checks with Spring Boot Actuator**: Integrate Spring Boot Actuator to provide production-ready features such as health checks, metrics, and application information. Configure health endpoints to monitor the application's status.
149+
150+
## 6. **Sprint 8: Optimizations**
151+
152+
- **Redis Caching**: Implement caching mechanisms using Redis to improve application performance by reducing a database load for frequently accessed data.
153+
- **PDF Reports Generation**: Develop functionality to generate PDF reports for financial summaries, transaction histories, and other relevant data.
154+
- **Google Sheets Integration**: Integrate with Google Sheets API to allow users to export data directly to spreadsheets for further analysis and reporting.
155+
- **Automatic Deployment on Merge**: Configure GitHub Actions to trigger automatic deployment to AWS upon merging changes into the main branch, ensuring continuous delivery.
156+
- **Final Documentation**: Complete the project documentation, including OpenAPI specifications for the API endpoints, a comprehensive README file, and a technical demo showcasing the application's features and architecture.
157+
158+
---
159+
This ADR outlines the architectural decisions and implementation plan for the full-stack financial management application. The focus is on leveraging modern technologies and best practices to ensure scalability, maintainability, and a robust learning experience.

0 commit comments

Comments
 (0)