-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocumentation.txt
More file actions
298 lines (186 loc) · 7.12 KB
/
documentation.txt
File metadata and controls
298 lines (186 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# E-Commerce Spring Boot Backend – Complete Technical Documentation
---
## 1. Project Overview
The **E-Commerce Spring Boot Backend** is a **microservices-based distributed system** designed to power a scalable, secure, and production-ready e-commerce platform. The system follows **modern cloud-native architecture principles**, leveraging Spring Boot, Spring Cloud, service discovery, API gateway, centralized configuration, security, and multiple databases.
This backend supports core e-commerce functionalities such as:
* User authentication and authorization
* Product catalog management
* Shopping cart handling
* Order processing
* Payment processing
* Email notifications
The application is designed to be **highly scalable**, **fault-tolerant**, and **easily deployable** using containers and orchestration tools.
---
## 2. Key Architectural Principles
* **Microservices Architecture**
* **Single Responsibility per Service**
* **Loose Coupling & High Cohesion**
* **Centralized Configuration Management**
* **Service Discovery & Load Balancing**
* **API Gateway Pattern**
* **Secure-by-Design (Spring Security)**
---
## 3. Technology Stack
### Core Backend
* **Java 17+**
* **Spring Boot**
* **Spring Cloud**
### Microservices & Cloud
* Spring Cloud **Eureka Server** (Service Discovery)
* Spring Cloud **Gateway** (API Gateway)
* Spring Cloud **Config Server** (Centralized Configuration)
### Security
* **Spring Security**
* In-Memory Authentication
* Database-backed Authentication
* Role-Based Access Control (RBAC)
### Databases
* **PostgreSQL** – Relational Data (Users, Orders, Payments)
* **MongoDB** – NoSQL Data (Products, Carts)
### Messaging & Communication
* RESTful APIs
* WebClient / OpenFeign (inter-service communication)
### Notifications
* **Email Service** (SMTP / JavaMailSender)
---
## 4. High-Level System Architecture
```
┌──────────────────┐
│ Config Server │
└────────▲─────────┘
│
┌────────────────┴────────────────┐
│ Eureka Server │
└────────▲───────────▲─────────────┘
│ │
┌────────┴───┐ ┌───┴────────┐
│ API Gateway│ │ Auth Service│
└────▲───────┘ └────▲────────┘
│ │
┌───────────┼────────────────┼────────────────────┐
│ │ │ │
│ Product Service Cart Service Order Service │
│ │ │ │
│ Payment Service Email Service │
└──────────────────────────────────────────────────┘
```
---
## 5. Microservices Overview
| Service Name | Responsibility | Database |
| ---------------- | ------------------------------ | ----------------- |
| Config Server | Centralized configuration | None |
| Eureka Server | Service discovery | None |
| API Gateway | Routing, security | None |
| UserAuth Service | Authentication & authorization | PostgreSQL |
| Product Service | Product catalog | MongoDB |
| Cart Service | Shopping cart | PostgreSQL |
| Order Service | Order lifecycle | MongoDB |
| Payment Service | Payment handling | PostgreSQL |
| Email Service | Notifications | SMTP |
---
## 6. Config Server
### Purpose
* Centralized management of configuration files
* Environment-specific configs (dev, test, prod)
### Benefits
* No hard-coded configs in services
* Dynamic refresh using Spring Cloud Bus (optional)
---
## 7. Eureka Server (Service Discovery)
### Purpose
* Registers all microservices
* Enables dynamic service lookup
### Benefits
* No hard-coded service URLs
* Load balancing and fault tolerance
---
## 8. API Gateway
### Responsibilities
* Single entry point for all client requests
* Request routing
* Authentication & authorization
* Rate limiting and logging (optional)
### Security Implementation
#### Authentication Methods
1. **In-Memory Authentication**
* Used for admin / testing
2. **Database Authentication**
* Validates users from PostgreSQL
#### Authorization
* Role-based access control (ADMIN, USER)
* Endpoint-level security
---
## 9. UserAuth Service
### Responsibilities
* User registration
* Login & credential validation
* Role management
### Database (PostgreSQL)
* Users table
* Roles table
---
## 10. Product Service
### Responsibilities
* Product creation & updates
* Inventory management
* Product search
### Database (MongoDB)
* Flexible schema for product attributes
* High read performance
---
## 11. Cart Service
### Responsibilities
* Add/remove items from cart
* Maintain cart per user
* Calculate cart totals
### Database (MongoDB)
* Fast updates
* Document-based cart structure
---
## 12. Order Service
### Responsibilities
* Order creation
* Order status tracking
* Interaction with payment service
### Database (PostgreSQL)
* ACID transactions
* Strong consistency
---
## 13. Payment Service
### Responsibilities
* Payment initiation
* Payment verification
* Transaction logging
### Database (PostgreSQL)
* Secure transaction storage
---
## 14. Email Service
### Responsibilities
* Order confirmation emails
* Payment success/failure notifications
* Account alerts
### Technology
* JavaMailSender
* SMTP (Gmail / SES / Outlook)
---
## 15. Inter-Service Communication
* REST APIs
* Service name resolution via Eureka
* Gateway-based routing
---
## 16. Security Design
### Gateway-Level Security
* Centralized authentication
* Token/session validation
### Service-Level Security
* Internal service-to-service trust
## 17. Database Strategy (Polyglot Persistence)
### Why MongoDB?
* Product & cart data is schema-flexible
* High read/write throughput
### Why PostgreSQL?
* Orders & payments need strong consistency
* Relational constraints
---
This **E-Commerce Spring Boot Backend** is a **robust, scalable, and secure microservices system** following industry best practices. It demonstrates real-world backend engineering skills, making it suitable for **production deployment, interviews, and enterprise use cases**.
---