package dev.lions.unionflow.server; import io.quarkus.runtime.Quarkus; import io.quarkus.runtime.QuarkusApplication; import io.quarkus.runtime.annotations.QuarkusMain; import jakarta.enterprise.context.ApplicationScoped; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.jboss.logging.Logger; /** * Point d'entrée principal du serveur UnionFlow. * *
UnionFlow est une plateforme de gestion associative multi-tenant * destinée aux organisations de solidarité (associations, mutuelles, coopératives, * tontines, ONG) en Afrique de l'Ouest. * *
Lance l'application Quarkus en mode bloquant. * En mode natif, cette méthode démarre instantanément (< 50ms). * * @param args Arguments de ligne de commande (non utilisés) */ public static void main(String... args) { Quarkus.run(UnionFlowServerApplication.class, args); } /** * Méthode de démarrage de l'application. * *
Affiche les informations de démarrage (URLs, configuration) * puis attend le signal d'arrêt (SIGTERM, SIGINT). * * @param args Arguments passés depuis main() * @return Code de sortie (0 = succès) * @throws Exception Si erreur fatale au démarrage */ @Override public int run(String... args) throws Exception { logStartupBanner(); logConfiguration(); logEndpoints(); logArchitecture(); LOG.info("UnionFlow Server prêt à recevoir des requêtes"); LOG.info("Appuyez sur Ctrl+C pour arrêter"); // Attend le signal d'arrêt (bloquant) Quarkus.waitForExit(); LOG.info("UnionFlow Server arrêté proprement"); return 0; } /** * Affiche la bannière ASCII de démarrage. */ private void logStartupBanner() { LOG.info("----------------------------------------------------------"); LOG.info("- -"); LOG.info("- UNIONFLOW SERVER v" + applicationVersion + " "); LOG.info("- Plateforme de Gestion Associative Multi-Tenant -"); LOG.info("- -"); LOG.info("----------------------------------------------------------"); } /** * Affiche la configuration active. */ private void logConfiguration() { LOG.infof("Profil : %s", activeProfile); LOG.infof("Application : %s v%s", applicationName, applicationVersion); LOG.infof("Java : %s", System.getProperty("java.version")); LOG.infof("Quarkus : %s", quarkusVersion); } /** * Affiche les URLs des endpoints principaux. */ private void logEndpoints() { String baseUrl = buildBaseUrl(); LOG.info("--------------------------------------------------------------"); LOG.info("📡 Endpoints disponibles:"); LOG.infof(" - API REST --> %s/api", baseUrl); LOG.infof(" - Swagger UI --> %s/q/swagger-ui", baseUrl); LOG.infof(" - Health Check --> %s/q/health", baseUrl); LOG.infof(" - Metrics --> %s/q/metrics", baseUrl); LOG.infof(" - OpenAPI --> %s/q/openapi", baseUrl); if ("dev".equals(activeProfile)) { LOG.infof(" - Dev UI --> %s/q/dev", baseUrl); LOG.infof(" - H2 Console --> %s/q/dev/io.quarkus.quarkus-datasource/datasources", baseUrl); } LOG.info("--------------------------------------------------------------"); } /** * Affiche l'inventaire de l'architecture. */ private void logArchitecture() { LOG.info(" Architecture:"); LOG.info(" - 60 Entités JPA"); LOG.info(" - 46 Services CDI"); LOG.info(" - 37 Endpoints REST"); LOG.info(" - 49 Repositories Panache"); LOG.info(" - 142 DTOs (Request/Response)"); LOG.info(" - 1127 Tests automatisés"); LOG.info("--------------------------------------------------------------"); } /** * Retourne la valeur de la variable d'environnement UNIONFLOW_DOMAIN. * Méthode protégée pour permettre la substitution en tests. * * @return valeur de UNIONFLOW_DOMAIN, ou null si non définie */ protected String getUnionflowDomain() { return System.getenv("UNIONFLOW_DOMAIN"); } /** * Construit l'URL de base de l'application. * * @return URL complète (ex: http://localhost:8080) */ String buildBaseUrl() { // En production, utiliser le nom de domaine configuré if ("prod".equals(activeProfile)) { String domain = getUnionflowDomain(); if (domain != null && !domain.isEmpty()) { return "https://" + domain; } } // En dev/test, utiliser localhost String host = "0.0.0.0".equals(httpHost) ? "localhost" : httpHost; return String.format("http://%s:%d", host, httpPort); } }