How oscararismendi/survey-backend works
Main Components
• Entry Point & Configuration: At the very top is the SurveyBackendApplication.java file which boots up the application. Also include the configuration files (application.properties and variants) and Maven scripts (pom.xml, mvnw).
• Controllers (API Layer): Represented by classes in the “infrastructure/controllers” directory (such as SurveyController.java and UserController.java). These components are responsible for handling incoming HTTP requests and mapping them to service calls.
• Application Services (Business Logic Layer): Classes like SurveyService, IUserService, and UserDetailServiceImpl in the “application/services” folder encapsulate business rules and logic.
• Domain Layer (Data/Entity Models): This includes entity classes (like Survey, Question, UserEntity, Role, etc.) located under “domain/entity” and the associated DTOs in “domain/entity/dto”. This layer models the core data of surveys, questions, users, permissions, etc.
• Repository Layer (Data Access): Found under “infrastructure/repositories” for users, surveys, and roles. These classes (for example, SurveyRepository and UserRepository) manage persistence and are typically interfaces or adapters that connect to a database.
• Security Components: The “security” package, which contains the SpringSecurityConfig and the JWT token validator (JwtTokenValidator), plus utility classes like JwtUtils, manage authentication/authorization via JWT.
• Utilities & Support: Include anything that aids in operations, like the “utils” package, and possibly the SQL import file for database initialization (import.sql).
• Controllers then invoke Application Services to process business logic.
• Application Services interact with Repositories to fetch, store, or update entities in the database.
• Domain Entities are shared between Services and Repositories as the data model.
• Security components (configured via SpringSecurityConfig) intercept incoming requests. They validate JWT tokens using JwtTokenValidator and JwtUtils before allowing the request to reach controllers.
Architectural Patterns & Design Principles
• Layered Architecture: Emphasize the separation between presentation (controllers), business logic (services), data (repositories and domain), and security.
• Dependency Inversion: Controllers depend on services, not directly on repositories, ensuring modularity.
• RESTful API design: The controllers serve as endpoints to expose the survey functionalities.
• Security Best Practices: Use JWT for stateless security and authentication, as seen in the security package.
Technologies, Frameworks, and Tools
• Java and Spring Boot are central to the project.
• Maven is used for build and dependency management.
• JWT is used for security (with supporting classes like JwtTokenValidator and JwtUtils).
• Database connectivity (likely using Spring Data JPA) through Repository interfaces.
• Testing framework is visible (JUnit tests under src/test).