Skip to content

Commit 199d039

Browse files
committed
add
1 parent ecae5cd commit 199d039

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,80 @@ Here's a high-level diagram of the SplitKro application architecture:
145145

146146
This diagram illustrates the main components of the SplitKro application and how they interact with each other. The application follows a typical Spring Boot architecture with additional components like Swagger for API documentation and Spring Security for authentication.
147147

148-
---
148+
## Data Modeling
149+
150+
The SplitKro application uses a relational database model to manage users, groups, expenses, and settlements. Below is a detailed explanation of each table and its relationships.
151+
152+
### Tables
153+
154+
1. **users**
155+
- Stores user account information
156+
- Fields: id, username, email, password_hash, created_at, updated_at
157+
- Primary Key: id
158+
- Unique Constraints: username, email
159+
160+
2. **groups**
161+
- Represents expense sharing groups
162+
- Fields: id, name, description, created_by, created_at, updated_at
163+
- Primary Key: id
164+
- Foreign Key: created_by references users(id)
165+
166+
3. **user_group**
167+
- Manages the many-to-many relationship between users and groups
168+
- Fields: user_id, group_id, role, joined_at
169+
- Primary Key: (user_id, group_id)
170+
- Foreign Keys:
171+
- user_id references users(id)
172+
- group_id references groups(id)
173+
174+
4. **expenses**
175+
- Records individual expenses
176+
- Fields: id, group_id, payer_id, amount, description, date, category_id, created_at, updated_at
177+
- Primary Key: id
178+
- Foreign Keys:
179+
- group_id references groups(id)
180+
- payer_id references users(id)
181+
- category_id references categories(id)
182+
183+
5. **expense_splits**
184+
- Tracks how expenses are split among users
185+
- Fields: id, expense_id, user_id, amount, created_at, updated_at
186+
- Primary Key: id
187+
- Foreign Keys:
188+
- expense_id references expenses(id)
189+
- user_id references users(id)
190+
191+
6. **settlements**
192+
- Records settlements between users
193+
- Fields: id, payer_id, payee_id, amount, group_id, settled_at, created_at, updated_at
194+
- Primary Key: id
195+
- Foreign Keys:
196+
- payer_id references users(id)
197+
- payee_id references users(id)
198+
- group_id references groups(id)
199+
200+
7. **categories**
201+
- Defines categories for expenses
202+
- Fields: id, name, created_at, updated_at
203+
- Primary Key: id
204+
- Unique Constraint: name
205+
206+
### Relationships
207+
208+
- A user can belong to multiple groups, and a group can have multiple users (Many-to-Many relationship managed through user_group table)
209+
- An expense belongs to one group and is paid by one user (payer)
210+
- An expense can be split among multiple users (One-to-Many relationship with expense_splits)
211+
- A settlement involves two users (payer and payee) and is associated with a group
212+
- Each expense can belong to one category
213+
214+
### Key Features
215+
216+
- Use of SERIAL type for auto-incrementing primary keys
217+
- Timestamps (created_at, updated_at) for audit trails
218+
- Proper foreign key constraints to maintain referential integrity
219+
- Indexes on frequently queried columns for performance optimization
220+
- Use of DECIMAL type for financial amounts to ensure precision
221+
- Trigger-based automatic updating of 'updated_at' columns
222+
223+
149224

0 commit comments

Comments
 (0)