How ericblue/spark-starter-auth0 works
Main Components
• Web Server / Spark Application: Represents the Spark-based application entry point (Application.java). It handles incoming HTTP requests and dispatches them to the proper route handlers.
• Controllers: There are multiple controller packages:
• API Controllers (e.g., SampleAPIController.java) for REST endpoints.
• Auth0 Controllers (e.g., AuthController.java) dedicated to authentication.
• Web Controllers (e.g., DashboardController.java, IndexController.java) for rendering dynamic web views.
• WebSocket Controllers (e.g., WebSocketController.java) for real-time communication.
• Error and Swagger controllers to deal with error responses and to deliver Swagger API documentation.
• Configuration and Environment: Modules inside the config package (e.g., AppConfiguration.java, WebConfig.java) that manage application settings, environment properties, and loading configuration files from src/main/resources (three environments: development, production, and test).
• Services: Service classes (such as SampleAPIService.java) encapsulate the business logic.
• Models & Domain Objects: Define the data structures used across the application (e.g., BaseDomainObject.java, Message.java).
• Exception Handling / Utility: Specific packages for handling exceptions (AppException, LoginException, etc.) and utilities for data encoding and dumping logs.
• External Services: Auth0 integration is core to the app – clearly mark the external Auth0 service (for managing authentication callbacks, token validations, roles management, etc.).
• API Documentation: Swagger integration including static files provided under src/main/resources/public/swagger-ui to deliver API documentation and testing endpoints.
Relationships and Interactions
• The Web Server (Spark Application) routes incoming HTTP calls to the appropriate controllers.
• Web Controllers and API Controllers process requests by calling out to corresponding service classes that encapsulate the core business logic.
• The Authentication module (in Auth0 controllers and configuration) interacts directly with the external Auth0 services for login, callback handling, and token management.
• Exception modules capture errors across the system and present either web views (using templates) or JSON responses.
• The Swagger module interacts with the API endpoints to generate live API documentation.
• The configuration component loads environment-specific properties which determine key variables such as Auth0 client details and environment profiles.
Important Architectural Patterns and Design Principles
• MVC Separation: Controllers handle incoming requests; Services implement the business logic; Models represent the data.
• Environment-Based Configuration: Multiple application properties files support different environments, showing attention to configuration management.
• Modularization: Distinct packages for controllers (with subdivisions for different types), configuration, exceptions, services, models, utilities, and Swagger.
• Integration with External API: Clear separation and encapsulation of Auth0 authentication logic.
• Reuse of Components: Common base classes for controllers (BaseController.java), shared response formats (RestResponse.java), and common exception handling.
Relevant Technologies, Frameworks, and Libraries
• Spark Java framework (v2.9.4) for handling HTTP requests.
• Auth0 Java libraries for web authentication.
• Log4J (configured in log4j2.xml) for logging.
• Maven for dependency management and building the project.
• Swagger for API documentation.
• Maven Snyk security integration.
• Standard Java libraries for utility functions.