# leeyreserrano/keyly architecture

> Architecture diagram of the GitHub repository leeyreserrano/keyly, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/leeyreserrano/keyly
- Repository: https://github.com/leeyreserrano/keyly

## Overview

1. **Repository shape**
   - This repo is a full stack password-manager system with three main runtime areas: a Spring Boot backend, a Vite/React web frontend, and a second React-based client under `keyly` that looks like an extension-style or lightweight companion UI because it includes `popup.tsx`.
   - Supporting pieces include MySQL initialization scripts, Nginx TLS config, and Docker/Docker Compose deployment artifacts.

2. **Backend as the system core**
   - `backend/api` is the central application. It exposes REST endpoints through controllers such as `AuthController`, `ItemController`, `CarpetaController`, `BagulController`, `CompartitController`, `UsuariController`, and several admin/config controllers.
   - The backend is organized in a classic layered Spring architecture: controller → service → repository → MySQL.

3. **Domain boundaries and main business concepts**
   - The domain is built around credential storage and organization: `Bagul` (vault/container), `Carpeta` (folder), `Item` (credential entry), and `Compartit` (shared access).
   - Supporting organizational/security entities include `Usuari`, `Rol`, `Config`, `Domini`, `Sucursal`, and `Departament`.
   - Enums such as `Permisos`, `RolIntern`, and `TipusEntitat` suggest permission-driven access control and typed domain relationships.

4. **Backend data flow**
   - Client requests hit controllers, which delegate to services for business rules.
   - Services persist and query through repository interfaces such as `ItemRepo`, `UsuariRepo`, `BagulRepo`, and others, which connect to MySQL.
   - The backend returns dedicated response DTOs rather than raw entities, indicating a clean API boundary.

5. **DTOs and mapping layer**
   - The `request`, `response`, and `response/basics` packages show that the API is designed around explicit data contracts.
   - Mapper classes (`ItemMapper`, `UsuariMapper`, etc.) transform between persistence models and API payloads, keeping entity structure separated from external API shape.

6. **Authentication and security**
   - Authentication is handled by `AuthController` and `AuthService`, with JWT support in `security/JwtUtils`, `JwtAuthenticationFilter`, and `SecurityConfig`.
   - This implies the frontends authenticate once, then send JWT-bearing requests for protected endpoints.
   - `JwtAuthenticationEntryPoint` indicates a centralized unauthorized-response path.

7. **Error handling**
   - The backend has custom exceptions for domain failures such as invalid domain, missing entity, image problems, password-generation issues, and user/corruption-related errors.
   - `GestorGlobalExcepcions` and `ErrorResponse` form the global exception boundary, translating backend failures into consistent API errors.

8. **Frontend web app**
   - `frontend-react` is a Vite + React + TypeScript app with pages for login, home, item lists, add/edit item flows, and folder creation.
   - Its structure is component-driven (`Sidebar`, `LoginCard`, `CredentialCard`, modals) with API modules in `src/api` for login, folders, and items.
   - The theme/customization folders suggest a styled UI layer, likely built on a component library with centralized theming.

9. **Second client in `keyly`**
   - The `keyly` app is another React/TypeScript frontend with `home`, `login`, `popup`, and API service modules.
   - Because it contains `popup.tsx`, it likely serves as a browser-extension or embedded client rather than the main web SPA.
   - It shares the same conceptual domain as the main frontend: auth plus folder/item operations.

10. **Database bootstrap and deployment**
   - `db/mysql-init` contains scripts for user setup, table creation, triggers, and seed inserts, so MySQL is initialized from code rather than manually.
   - `nginx/conf.d` includes a default site config plus certificate/key files, indicating HTTPS termination and likely reverse-proxy deployment.
   - `docker-compose.yml` at the root suggests the intended runtime is containerized, with MySQL, backend, and frontend/proxy wired together.

11. **Testing and maintainability**
   - Backend service tests exist for the main business services, which means the core domain logic is unit-tested separately from controllers and persistence.
   - The architecture is therefore centered on business logic in services, with thin controllers and explicit DTO boundaries, making it diagram-friendly and easier to evolve.

Main entry points: [`backend/api/src/main/java/com/keyly/controller`](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/controller) (Controllers), [`docker-compose.yml`](https://github.com/leeyreserrano/keyly/blob/main/docker-compose.yml) (Compose stack), [`backend/api/src/main/java/com/keyly/service`](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/service) (Services), [`frontend-react/src/main.tsx`](https://github.com/leeyreserrano/keyly/blob/main/frontend-react/src/main.tsx) (Web app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Spring backend"]
  node_backend_app(("API app<br/>Spring Boot entrypoint"))
  node_backend_ctrl["Controllers<br/>REST layer"]
  node_backend_service["Services<br/>business layer"]
  node_backend_repo["Repositories<br/>persistence layer"]
  node_backend_model["Domain model<br/>entities and DTOs"]
  node_backend_mapper["Mappers<br/>mapping layer"]
  node_backend_security{{"JWT security<br/>auth and filters"}}
  node_backend_error["Errors<br/>exception boundary"]
end

subgraph group_web["Web clients"]
  node_frontend_web(("Web app<br/>Vite React SPA<br/>[main.tsx]"))
  node_frontend_web_api["Web APIs<br/>client services"]
  node_frontend_web_pages["Pages<br/>screens"]
  node_frontend_web_ui["UI components"]
  node_frontend_web_theme["Theme<br/>styling system"]
  node_keyly_app(("Keyly client<br/>React companion UI<br/>[popup.tsx]"))
  node_keyly_api["Keyly services<br/>client services"]
  node_keyly_pages["Keyly pages<br/>screens"]
end

subgraph group_platform["Data and deployment"]
  node_db_init["MySQL init<br/>bootstrap SQL"]
  node_nginx_conf["Nginx config<br/>TLS reverse proxy<br/>[conf.d]"]
  node_compose["Compose stack<br/>deployment manifest<br/>[docker-compose.yml]"]
end

node_backend_app -->|"starts"| node_backend_ctrl
node_backend_ctrl -->|"delegates"| node_backend_service
node_backend_service -->|"persists via"| node_backend_repo
node_backend_service -->|"maps"| node_backend_mapper
node_backend_mapper -->|"transforms"| node_backend_model
node_backend_repo -->|"stores"| node_backend_model
node_backend_ctrl -->|"accepts/returns"| node_backend_model
node_backend_ctrl -->|"protected by"| node_backend_security
node_backend_security -->|"filters"| node_backend_ctrl
node_backend_error -.->|"handles failures"| node_backend_ctrl
node_backend_error -.->|"handles failures"| node_backend_service
node_frontend_web -->|"calls"| node_frontend_web_api
node_frontend_web -->|"renders"| node_frontend_web_pages
node_frontend_web_pages -->|"uses"| node_frontend_web_ui
node_frontend_web_ui -->|"styled by"| node_frontend_web_theme
node_frontend_web_api -->|"HTTP to"| node_backend_ctrl
node_keyly_app -->|"calls"| node_keyly_api
node_keyly_app -->|"renders"| node_keyly_pages
node_keyly_api -->|"HTTP to"| node_backend_ctrl
node_compose -->|"runs"| node_backend_app
node_compose -->|"runs"| node_frontend_web
node_compose -->|"proxies through"| node_nginx_conf
node_compose -->|"initializes"| node_db_init
node_db_init -.->|"serves data for"| node_backend_repo
node_nginx_conf -.->|"serves"| node_frontend_web
node_nginx_conf -.->|"routes"| node_backend_app

click node_backend_app "https://github.com/leeyreserrano/keyly/blob/main/backend/api/src/main/java/com/keyly/KeylyApplication.java"
click node_backend_ctrl "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/controller"
click node_backend_service "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/service"
click node_backend_repo "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/repo"
click node_backend_model "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/model"
click node_backend_mapper "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/mapper"
click node_backend_security "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/security"
click node_backend_error "https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/exception"
click node_frontend_web "https://github.com/leeyreserrano/keyly/blob/main/frontend-react/src/main.tsx"
click node_frontend_web_api "https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/api"
click node_frontend_web_pages "https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/pages"
click node_frontend_web_ui "https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/components"
click node_frontend_web_theme "https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/theme"
click node_keyly_app "https://github.com/leeyreserrano/keyly/blob/main/keyly/src/popup.tsx"
click node_keyly_api "https://github.com/leeyreserrano/keyly/tree/main/keyly/src/api"
click node_keyly_pages "https://github.com/leeyreserrano/keyly/tree/main/keyly/src/pages"
click node_db_init "https://github.com/leeyreserrano/keyly/tree/main/db/mysql-init"
click node_nginx_conf "https://github.com/leeyreserrano/keyly/blob/main/nginx/conf.d"
click node_compose "https://github.com/leeyreserrano/keyly/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_app,node_backend_ctrl,node_backend_service,node_backend_repo,node_backend_model,node_backend_mapper,node_backend_security,node_backend_error toneBlue
class node_frontend_web,node_frontend_web_api,node_frontend_web_pages,node_frontend_web_ui,node_frontend_web_theme,node_keyly_app,node_keyly_api,node_keyly_pages toneAmber
class node_db_init,node_nginx_conf,node_compose toneMint
```

## Components

### Spring backend

Core API, domain services, persistence, and security.

- [API app](https://github.com/leeyreserrano/keyly/blob/main/backend/api/src/main/java/com/keyly/KeylyApplication.java): Spring Boot entrypoint · Backend application bootstrap. · `backend/api/src/main/java/com/keyly/KeylyApplication.java`
- [Controllers](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/controller): REST layer · HTTP endpoints for auth, items, folders, vaults, sharing, users, and admin data. · `backend/api/src/main/java/com/keyly/controller`
- [Services](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/service): business layer · Domain rules and use-case orchestration. · `backend/api/src/main/java/com/keyly/service`
- [Repositories](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/repo): persistence layer · Spring Data repositories for domain persistence. · `backend/api/src/main/java/com/keyly/repo`
- [Domain model](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/model): entities and DTOs · Vault, folder, item, user, role, config, request, and response contracts. · `backend/api/src/main/java/com/keyly/model`
- [Mappers](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/mapper): mapping layer · Transforms between entities and API payloads. · `backend/api/src/main/java/com/keyly/mapper`
- [JWT security](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/security): auth and filters · JWT issuance, request filtering, unauthorized handling, and security config. · `backend/api/src/main/java/com/keyly/security`
- [Errors](https://github.com/leeyreserrano/keyly/tree/main/backend/api/src/main/java/com/keyly/exception): exception boundary · Global exception handling and API error responses. · `backend/api/src/main/java/com/keyly/exception`

### Web clients

Main React SPA and companion React client.

- [Web app](https://github.com/leeyreserrano/keyly/blob/main/frontend-react/src/main.tsx): Vite React SPA · Main browser UI for login and credential management. · `frontend-react/src/main.tsx`
- [Web APIs](https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/api): client services · Frontend API wrappers for login, folders, and items. · `frontend-react/src/api`
- [Pages](https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/pages): screens · Login, home, items, item editing, and folder creation screens. · `frontend-react/src/pages`
- [UI components](https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/components): components · Shared cards, sidebar, modals, and content assembly. · `frontend-react/src/components`
- [Theme](https://github.com/leeyreserrano/keyly/tree/main/frontend-react/src/theme): styling system · Theme primitives and UI customizations. · `frontend-react/src/theme`
- [Keyly client](https://github.com/leeyreserrano/keyly/blob/main/keyly/src/popup.tsx): React companion UI · Secondary React client, likely extension-style because it includes a popup entrypoint. · `keyly/src/popup.tsx`
- [Keyly services](https://github.com/leeyreserrano/keyly/tree/main/keyly/src/api): client services · Auth, folder, and item API wrappers for the companion client. · `keyly/src/api`
- [Keyly pages](https://github.com/leeyreserrano/keyly/tree/main/keyly/src/pages): screens · Home and login views for the companion client. · `keyly/src/pages`

### Data and deployment

Database bootstrap and container/web server deployment assets.

- [MySQL init](https://github.com/leeyreserrano/keyly/tree/main/db/mysql-init): bootstrap SQL · User, schema, trigger, and seed initialization scripts. · `db/mysql-init`
- [Nginx config](https://github.com/leeyreserrano/keyly/blob/main/nginx/conf.d): TLS reverse proxy · HTTPS and server configuration for deployed services. · `nginx/conf.d`
- [Compose stack](https://github.com/leeyreserrano/keyly/blob/main/docker-compose.yml): deployment manifest · Container orchestration for backend, frontend, database, and proxy. · `docker-compose.yml`

## Connections

- API app → Controllers: starts · Application boots the REST API layer.
- Controllers → Services: delegates · Controllers forward requests to business services.
- Services → Repositories: persists via · Services query and store through repositories.
- Services → Mappers: maps · Services or adjacent layers convert between entities and DTOs.
- Mappers → Domain model: transforms · Mappers bridge domain entities and API contracts.
- Repositories → Domain model: stores · Repositories operate on entities.
- Controllers → Domain model: accepts/returns · Request and response DTOs define the API boundary.
- Controllers → JWT security: protected by · REST endpoints are guarded by JWT security.
- JWT security → Controllers: filters · Security intercepts requests before controllers.
- Errors → Controllers: handles failures · Global exception handling shapes controller errors.
- Errors → Services: handles failures · Service exceptions are converted into API errors.
- Web app → Web APIs: calls · The web app uses API service modules.
- Web app → Pages: renders · App is composed from page-level views.
- Pages → UI components: uses · Screens assemble shared UI components.
- UI components → Theme: styled by · UI components are themed centrally.
- Web APIs → Controllers: HTTP to · Browser API calls hit backend controllers.
- Keyly client → Keyly services: calls · Companion client uses its API services.
- Keyly client → Keyly pages: renders · Popup and page views compose the client UI.
- Keyly services → Controllers: HTTP to · Companion client talks to the same backend API.
- Compose stack → API app: runs · Compose deploys the backend service.
- Compose stack → Web app: runs · Compose deploys the main web client.
- Compose stack → Nginx config: proxies through · Deployment routes traffic via Nginx.
- Compose stack → MySQL init: initializes · Compose wires in the database bootstrap scripts.
- MySQL init → Repositories: serves data for · Initialized MySQL schema supports repository persistence.
- Nginx config → Web app: serves · Nginx fronts the web client in deployment.
- Nginx config → API app: routes · Nginx can forward API traffic to the backend.
