# cmosquera1998/encuentro_matrimonial_backend architecture

> Architecture diagram of the GitHub repository cmosquera1998/encuentro_matrimonial_backend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cmosquera1998/encuentro_matrimonial_backend
- Repository: https://github.com/cmosquera1998/encuentro_matrimonial_backend

## Overview

##### Project type and purpose
- This is a backend web application (monolithic) built with Spring Boot. Its purpose is to provide a REST API for managing “Encuentros Matrimoniales” (marital encounters), covering user management, four “pillar” data models, formation modules, and geographic hierarchies. It uses Spring Security with JWT, Spring Data JPA, Swagger for documentation, and PostgreSQL for persistence. It can be containerized with Docker/Docker-Compose.

##### File structure
- Top-level artifacts:
- pom.xml, mvnw / mvnw.cmd, .mvn wrapper → Maven build
- Dockerfile, docker-compose.yml, docker.env → Container setup
- src/main/java/com/encuentro/matrimonial → Core app code
- src/main/resources → application.properties, messages.properties
- Within src/main/java/com/encuentro/matrimonial:
- configuration → SwaggerConfig, message bundles
- constants → Resource path and message constants
- controller → REST controllers for authentication, users, pillars, formation, location
- modelo → JPA entities (User, Role, City, Pilar1-4, Formation, etc.)
- repository → Spring Data JPA repos
- security → JWT filter, password encoder, security config
- service + implementation → Business logic interfaces and classes
- util → JWT util, initial data loader, error message wrappers
- Configuration files for Swagger, Spring profiles, and CORS settings appear in configuration packages.

##### Extract insights from the README
- Clearly describes a layered architecture: Controllers → Services → Repositories → Database.
- Uses JWT tokens for stateless auth, role-based access by geographic level.
- Exposes REST endpoints for each module.
- Uses Docker Compose for local setup, and can run with Maven packaging.

a. Main components
- API Gateway / HTTP layer (Spring MVC controllers)
- Security Layer (JWT filter + Spring Security)
- Business Logic Layer (Service interfaces + implementations)
- Data Access Layer (Spring Data JPA Repositories)
- Database (PostgreSQL)
- External tools: Swagger UI for API docs, Docker/Docker-Compose for containerization
b. Relationships and interactions
- Clients (e.g., frontend apps or API consumers) send HTTP requests to the API Gateway.
- Requests pass through the JWT filter (JwtRequestFilter) for authentication/authorization.
- Authenticated calls hit the appropriate Controller.
- Controller delegates to Service.
- Service invokes Repository to perform CRUD on the DB.
- DB returns entities, Service applies business logic, Controller maps to HTTP response models.
- Swagger UI reads Controller annotations to provide interactive docs.
- Docker Compose orchestrates container startup of the app and PostgreSQL.
c. Architectural patterns and design principles
- Layered (onion) architecture: Controllers → Services → Repositories → Entities
- Dependency injection via Spring
- Separation of concerns: Security, API layer, business logic, persistence
- Stateless JWT authentication for horizontal scalability
- Configuration by Spring Profiles (dev, prod, docker)
d. Key technologies/frameworks
- Spring Boot / Spring MVC, Spring Security (JWT)
- Spring Data JPA + Hibernate
- PostgreSQL 13
- Swagger (SpringFox)
- Docker & Docker-Compose
- Maven

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients
    Client["API Consumer\n(e.g., Frontend)"]:::external
    SwaggerUI["Swagger UI"]:::external

    %% Security Layer
    subgraph "Security Layer"
        JWTFilter["JwtRequestFilter"]:::security
        SecurityConfig["SecurityConfig"]:::security
        UserDetailsSvc["UserDetailService"]:::security
        PasswordEncoder["BCryptPasswordEncoder"]:::security
    end

    %% API Layer
    subgraph "API Gateway / HTTP Layer"
        Controllers["REST Controllers"]:::controller
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        ServiceInterfaces["Service Interfaces"]:::service
        ServiceImpl["Service Implementations"]:::service
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Repositories["Spring Data JPA Repositories"]:::repo
    end

    %% Data Model
    subgraph "Data Model"
        Entities["JPA Entities\n(User, Role, Pilar1-4, Location, etc.)"]:::entity
        InitialLoader["InitialDataLoader"]:::util
    end

    %% Utilities & Config
    subgraph "Configuration & Utilities"
        SwaggerCfg["SwaggerConfig\n& SwaggerView"]:::infra
        MessagesCfg["MesaggesConfiguration"]:::infra
        Constants["Application Constants"]:::infra
        JwtUtil["JwtUtil"]:::util
        ErrorUtils["ErrorMessage, GeneralResponse"]:::util
    end

    %% Database
    PostgreSQL["PostgreSQL Database"]:::db

    %% Docker
    subgraph "Docker Environment"
        DockerCompose["docker-compose.yml\nenvs"]:::infra
        AppContainer["App Container\n(Dockerfile)"]:::infra
    end

    %% Flows
    Client -->|Sends HTTP Request| JWTFilter
    JWTFilter -->|If Authenticated| Controllers
    Controllers -->|Calls| ServiceInterfaces
    ServiceInterfaces -->|Implemented by| ServiceImpl
    ServiceImpl -->|Uses| Repositories
    Repositories -->|CRUD| PostgreSQL
    Controllers -->|Documented by| SwaggerUI
    SwaggerUI -->|Reads Annotations| SwaggerCfg

    SecurityConfig -->|Wires| JWTFilter
    SecurityConfig -->|Configures| UserDetailsSvc
    SecurityConfig -->|Configures| PasswordEncoder

    JwtUtil -->|Generates/Validates| JWTFilter
    InitialLoader -->|Bootstraps Data| Repositories
    ErrorUtils -->|Wraps Responses| Controllers
    MessagesCfg -->|Loads Messages| Controllers
    Constants -->|Provides Paths/Messages| Controllers

    DockerCompose -->|Orchestrates| AppContainer
    DockerCompose -->|Orchestrates| PostgreSQL
    AppContainer -->|Runs| Controllers

    %% Click Events
    click Controllers "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/controller"
    click JWTFilter "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/security/JwtRequestFilter.java"
    click SecurityConfig "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/security/SecurityConfig.java"
    click UserDetailsSvc "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/security/UserDetailService.java"
    click PasswordEncoder "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/security/BCryptPasswordEncoder.java"
    click ServiceInterfaces "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/service"
    click ServiceImpl "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/service/implementation"
    click Repositories "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/repository"
    click Entities "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/modelo"
    click SwaggerCfg "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/configuration/SwaggerConfig.java"
    click SwaggerCfg "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/configuration/SwaggerView.java"
    click MessagesCfg "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/configuration/MesaggesConfiguration.java"
    click Constants "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/src/main/java/com/encuentro/matrimonial/constants"
    click JwtUtil "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/util/JwtUtil.java"
    click InitialLoader "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/util/InitialDataLoader.java"
    click ErrorUtils "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/util/ErrorMessage.java"
    click ErrorUtils "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/util/ErrorMessage2.java"
    click ErrorUtils "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/src/main/java/com/encuentro/matrimonial/util/GeneralResponse.java"
    click AppContainer "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/Dockerfile"
    click DockerCompose "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/docker-compose.yml"
    click DockerCompose "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/docker.env"
    click ServiceInterfaces "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/pom.xml"
    click ServiceInterfaces "https://github.com/cmosquera1998/encuentro_matrimonial_backend/tree/desarrollov2/mvnw"
    click ServiceInterfaces "https://github.com/cmosquera1998/encuentro_matrimonial_backend/blob/desarrollov2/mvnw.cmd"

    %% Styles
    classDef controller fill:#D0E6F6,stroke:#3B7EA1,stroke-width:1px
    classDef service fill:#E8EAF6,stroke:#5C6BC0,stroke-width:1px
    classDef repo fill:#E8F5E9,stroke:#388E3C,stroke-width:1px
    classDef entity fill:#F1F8E9,stroke:#558B2F,stroke-width:1px
    classDef db fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef security fill:#FFE0B2,stroke:#F57C00,stroke-width:1px
    classDef util fill:#F3E5F5,stroke:#8E24AA,stroke-width:1px
    classDef infra fill:#ECEFF1,stroke:#607D8B,stroke-width:1px
    classDef external fill:#FFFFFF,stroke:#000000,stroke-width:1px,stroke-dasharray: 3 3
```
