diff --git a/README.md b/README.md index c6d3e7a..b9ae768 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,253 @@ -# backend-mid-project -This is a starter project for the backend of the mid-project. It is built using Spring Boot and Maven. -Good luck! \ No newline at end of file +

πŸ“Œ Ticket Tracking System

+

Mid Backend Track

+

(HackYourFuture)

+ + +A backend application built as part of the **HackYourFuture Mid Backend Track**, implementing a complete ticket tracking system with: + +* User management +* Project management +* Ticket creation & updates +* Ticket assignment +* Email notifications +* Validation & error handling +* Secure environment configuration +* Controller & service layer testing +* The project follows clean architecture principles and uses **Spring Boot 4**, **Java 25**, **PostgreSQL**, and **dotenv** for secure configuration. + +# **🧱 Architecture Overview** + +Code + +``` +β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” +β”‚ Controller β”‚ --> β”‚ Request DTO β”‚ --> β”‚ Service β”‚ --> β”‚ Repository β”‚ --> DB +β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + ↑ ↓ + └────────────── Response DTO β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ + +``` + +* **Controller Layer** β€” REST endpoints +* **Service Layer** β€” business logic, validation, email notifications +* **Repository Layer** β€” JDBC queries using `JdbcTemplate` +* **Database Layer** β€” PostgreSQL schema + +# **πŸ—„οΈ Database Schema** + +The system uses four tables: + +* `users` +* `projects` +* `tickets` +* `ticket_assignees` (many‑to‑many) + +Relationships: + +* One **project** β†’ many **tickets** +* Many **users** ↔ many **tickets** + +# **πŸ“‚ Project Structure** + +Based on your real folder structure: + +Code + +``` +src/main/java/net/hackyourfuture/tickettrackingsystem +β”‚ +β”œβ”€β”€ controller +β”‚ β”œβ”€β”€ ProjectController +β”‚ β”œβ”€β”€ TicketController +β”‚ └── UserController +β”‚ +β”œβ”€β”€ dto +β”‚ β”œβ”€β”€ project +β”‚ β”‚ β”œβ”€β”€ ProjectRequest +β”‚ β”‚ └── ProjectResponse +β”‚ β”œβ”€β”€ ticket +β”‚ β”‚ β”œβ”€β”€ TicketRequest +β”‚ β”‚ └── TicketResponse +β”‚ └── user +β”‚ +β”œβ”€β”€ exception +β”‚ β”œβ”€β”€ ErrorResponse +β”‚ β”œβ”€β”€ GlobalExceptionHandler +β”‚ β”œβ”€β”€ NotFoundException +β”‚ └── ValidationException +β”‚ +β”œβ”€β”€ model +β”‚ β”œβ”€β”€ Project +β”‚ β”œβ”€β”€ Ticket +β”‚ β”œβ”€β”€ TicketAssignee +β”‚ └── User +β”‚ +β”œβ”€β”€ repository +β”‚ β”œβ”€β”€ ProjectRepository +β”‚ β”œβ”€β”€ TicketAssigneeRepository +β”‚ β”œβ”€β”€ TicketRepository +β”‚ └── UserRepository +β”‚ +β”œβ”€β”€ service +β”‚ β”œβ”€β”€ EmailNotificationService +β”‚ β”œβ”€β”€ ProjectService +β”‚ β”œβ”€β”€ TicketService +β”‚ β”œβ”€β”€ UserService +β”‚ └── TicketTrackingSystemApplication +β”‚ +└── resources + β”œβ”€β”€ db/TrackTicket_schema.sql + └── application.properties +``` + +# + +# **πŸ§ͺ Test Structure** + +You mentioned: + +> **Tests are only made for controller and service** + +Your test folder: + +Code + +``` +src/test/java/net/hackyourfuture/tickettrackingsystem +β”‚ +β”œβ”€β”€ controller +β”‚ β”œβ”€β”€ ProjectControllerTest +β”‚ β”œβ”€β”€ TicketControllerTest +β”‚ └── UserControllerTest +β”‚ +β”œβ”€β”€ service +β”‚ β”œβ”€β”€ ProjectServiceTest +β”‚ β”œβ”€β”€ TicketServiceTest +β”‚ └── UserServiceTest +``` + +βœ” Uses **MockMvc** for controller tests βœ” Uses **Mockito** for service tests βœ” Matches HYF expectations for mid‑backend level + + + +# **πŸ”§ Secure Dotenv Loading** + +Inside `TicketTrackingSystemApplication`: + +java + +``` +Dotenv dotenv = Dotenv.load(); + +System.setProperty("DB_URL", dotenv.get("DB_URL")); +System.setProperty("DB_USERNAME", dotenv.get("DB_USERNAME")); +System.setProperty("DB_PASSWORD", dotenv.get("DB_PASSWORD")); +System.setProperty("EMAIL_API_KEY", dotenv.get("EMAIL_API_KEY")); +System.setProperty("EMAIL_FROM", dotenv.get("EMAIL_FROM")); +``` + +βœ” No secrets printed βœ” No secrets committed βœ” Works in CI/CD + + + +# **βš™οΈ application.properties** + +Code + +``` +spring.datasource.url=${DB_URL} +spring.datasource.username=${DB_USERNAME} +spring.datasource.password=${DB_PASSWORD} +spring.datasource.driver-class-name=org.postgresql.Driver +``` + + + +# **πŸš€ Running the Application** + +### **1. Install dependencies** + +Code + +``` +mvn clean install +``` + +### **2. Start PostgreSQL** + +Code + +``` +docker run --name postgres -e POSTGRES_PASSWORD=pass -p 5432:5432 -d postgres +``` + +### **3. Run the app** + +Code + +``` +mvn spring-boot:run +``` + +# **πŸ“‘ API Summary** + +Your API is fully documented in `API_DESIGN.md`. Here is the summary: + +### **Users** + +* GET /users +* GET /users/{id} +* POST /users +* PUT /users/{id} +* DELETE /users/{id} + +### **Projects** + +* GET /projects + +### **Tickets** + +* POST /tickets +* GET /tickets +* GET /tickets/{id} +* PUT /tickets/{id} +* POST /tickets/{ticketId}/assignees +* DELETE /tickets/{ticketId}/assignees/{userId} + +# **πŸ“¨ Email Notifications** + +Emails are sent when: + +* A ticket is **updated** +* A user is **assigned** + +Emails include: + +* Ticket ID +* Title +* Description +* Status + +If sending fails: +* Ticket update still succeeds +* Error is logged + +# πŸ”„ CI/CD Pipeline +GitHub Actions pipeline includes: +Java 25 +Maven build +Tests +Cache optimization + +Triggers: + +push β†’ main +pull_request β†’ main +# 🀝 Contribution Guidelines +* Write clean, readable code +* Follow naming conventions +* Keep controllers thin +* Put logic in services +* Validate all inputs +* Add tests for new features +* Use meaningful commit messages \ No newline at end of file