This document describes the initial backend package structure for the Co-App Spring Boot project. Co-App backend follows a layered architecture.
com.coapp.backend
├── CoAppApplication.java
│
├── config
├── controller
├── service
├── repository
├── model
│ ├── document
│ └── enumeration
├── dto
└── exception
Purpose: Application-wide configuration.
This package contains Spring configuration classes that define cross-cutting concerns such as security, CORS, and web configuration.
Purpose: REST API layer.
Controllers expose HTTP endpoints and act as the entry point for client requests.
Responsibilities:
- Handle HTTP methods (GET, POST, PUT, DELETE)
- Validate request input
- Convert request/response bodies to/from DTOs
- Delegate business logic to the service layer
Controllers should not contain business logic.
Purpose: Business logic layer.
This layer contains the core application logic and orchestration between repositories and other services.
Responsibilities:
- Implement business rules
- Coordinate multiple repositories
Purpose: Data access layer.
Repositories abstract database interactions and are responsible for persisting and querying data from MongoDB.
Responsibilities:
- CRUD operations
- Query definitions
Purpose: Domain model definitions.
This package represents the core business entities of the application.
Purpose: MongoDB document models.
These classes:
- Represent how data is stored in MongoDB
- Are annotated with
@Document - May contain fields that should not be exposed to clients (e.g., passwords)
Purpose: Enumerations for fixed sets of allowed values.
Enums help ensure data consistency and readability across the application.
Example:
public enum ApplicationStatus {
INTEND_TO_APPLY,
APPLIED,
SCHEDULED_FOR_INTERVIEW,
OFFER_PENDING,
ACCEPTED,
REJECTED
}
...
Application newApplication = new Application();
newApplication.setStatus(ApplicationStatus.INTEND_TO_APPLY);Purpose: Data Transfer Objects.
DTOs are used to transfer data between layers and to/from the client.
Key Ideas:
- DTOs are safe to expose to the frontend
- They may omit sensitive fields (e.g., password, internal IDs)
- They may be tailored specifically to frontend needs
Client <---> Controller <---> Service <---> Repository <---> MongoDB
-------(DTO)------->(Domain Object)-------------------------------->
| Layer | Works With | Responsibility |
|---|---|---|
| Controller | DTOs | Handles HTTP, validation, request/response mapping |
| Service (Logic) | Domain Objects/DTOs | Business rules, orchestration |
| Repository | Domain Objects | Database persistence (MongoDB) |
Purpose: Centralized error handling.
This package contains custom exceptions and global exception handling logic.