# devfullcycle/imersao12 architecture

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

- Interactive diagram: https://gitdiagram.com/devfullcycle/imersao12
- Repository: https://github.com/devfullcycle/imersao12

## Overview

1. This repository is a small multi-service system, not a single app. It contains three runnable products — a Go simulator, a NestJS API, and a React frontend — plus Kafka and Kubernetes deployment assets.

2. The React frontend (`react-frontend`) is the user-facing entrypoint. Its structure suggests a map-based UI: `Mapping.tsx`, `Navbar.tsx`, `util/geolocation.ts`, `util/map.ts`, and `util/models.ts` indicate browser geolocation, map rendering, and route visualization. `route-exists.error.ts` implies the UI handles route-creation conflicts or validation feedback from the backend.

3. The NestJS backend (`nest-api`) is the domain/API layer. It is organized around a single `routes` feature module with controller, service, DTOs, entity, and a gateway. That indicates a classic Nest structure with:
   - HTTP endpoints for route CRUD/commands
   - a WebSocket gateway for realtime updates
   - a persistence model centered on a `Route` entity

4. The backend likely owns the system’s authoritative route state. The presence of `.docker/mongo/init.js` and Mongo-specific Docker assets strongly suggests MongoDB is the persistence boundary for the API. The API is packaged independently with both development and production Dockerfiles.

5. The simulator (`simulator`) is a separate Go service that produces movement or destination events. Its structure splits into `application/route`, `application/kafka`, and `infra/kafka`, which shows a clean separation between business behavior and Kafka plumbing. The `destinations/*.txt` files suggest the simulator reads predefined coordinate or destination sequences and emits them as streaming events.

6. Kafka is the asynchronous integration backbone. The `apache-kafka` directory contains Kafka compose setup and a Kafka Connect Elasticsearch connector configuration, so the repository is prepared for event streaming plus sink export to Elasticsearch. In architecture terms, Kafka is the decoupling layer between the simulator and downstream consumers.

7. The system’s main data flow is likely:
   - user interacts with the React UI
   - UI calls the NestJS API to create/query routes
   - simulator emits route/destination events into Kafka
   - backend and/or Kafka Connect consume those events for realtime updates or indexing
   - frontend reflects updates via API/WebSocket data
   The gateway in the backend is the main hint that live updates are pushed rather than polled.

8. Kubernetes manifests under `k8s/` show production-style deployment boundaries for `backend`, `frontend`, and `simulator`, each with its own `deploy.yaml` and `service.yaml`, and some with `configmap.yaml`. That means each service is independently deployable and configurable, with environment-specific settings externalized from the containers.

9. Local development is container-first across the repo. Each major app has Docker assets and a `docker-compose.yaml`, so the intended workflow is to run the stack as multiple containers rather than as one monolith. This also reinforces the service boundaries: UI, API, simulator, Kafka, and Mongo are separate runtime units.

10. The main architectural boundaries to draw are:
   - browser UI boundary: React app
   - synchronous API boundary: NestJS HTTP endpoints
   - realtime boundary: NestJS gateway / WebSocket path
   - persistence boundary: MongoDB for route data
   - streaming boundary: Kafka for simulated route events
   - deployment boundary: Docker/Kubernetes per service
   The repo is essentially a microservices/event-driven demo centered on route tracking and live movement visualization.

Main entry points: [`nest-api/src/routes/routes.module.ts`](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.module.ts) (Routes module), [`react-frontend/src/components/Mapping.tsx`](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/components/Mapping.tsx) (Mapping), [`react-frontend/src/App.tsx`](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/App.tsx) (App), [`nest-api/src/routes/routes.service.ts`](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.service.ts) (Routes service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_react_app["App<br/>React shell<br/>[App.tsx]"]
  node_mapping["Mapping<br/>UI view<br/>[Mapping.tsx]"]
  node_navbar["Navbar<br/>UI chrome<br/>[Navbar.tsx]"]
  node_geo["Geo utils<br/>Browser geolocation<br/>[geolocation.ts]"]
  node_map_utils["Map utils<br/>Map helpers<br/>[map.ts]"]
  node_models["Models<br/>UI types<br/>[models.ts]"]
  node_route_error["Route error<br/>UI error"]
end

subgraph group_backend["Nest API"]
  node_main_ts["Main<br/>Nest bootstrap<br/>[main.ts]"]
  node_app_module["App module<br/>Nest root<br/>[app.module.ts]"]
  node_routes_module["Routes module<br/>Domain module<br/>[routes.module.ts]"]
  node_routes_controller["Routes API<br/>HTTP controller"]
  node_routes_service["Routes service<br/>Domain service<br/>[routes.service.ts]"]
  node_routes_gateway["Routes gateway<br/>WebSocket gateway<br/>[routes.gateway.ts]"]
  node_route_entity[("Route entity<br/>Mongo model<br/>[route.entity.ts]")]
  node_route_dtos["Route DTOs<br/>API contracts"]
end

subgraph group_simulator["Go simulator"]
  node_sim_main["Main<br/>Go entrypoint<br/>[main.go]"]
  node_route_engine["Route engine<br/>Go domain<br/>[route.go]"]
  node_kafka_produce["Kafka produce<br/>Event producer<br/>[produce.go]"]
  node_kafka_infra["Kafka infra<br/>Kafka client<br/>[producer.go]"]
  node_destinations["Destinations<br/>Input data<br/>[1.txt]"]
end

subgraph group_streaming["Kafka stack"]
  node_kafka_compose["Kafka compose<br/>Kafka stack"]
  node_es_connector["ES connector<br/>Connect config"]
end

subgraph group_deploy["Deploy assets"]
  node_mongo_init["Mongo init<br/>DB seed<br/>[init.js]"]
  node_k8s_backend["Backend deploy<br/>K8s manifest<br/>[deploy.yaml]"]
  node_k8s_frontend["Frontend deploy<br/>K8s manifest<br/>[deploy.yaml]"]
  node_k8s_simulator["Simulator deploy<br/>K8s manifest<br/>[deploy.yaml]"]
end

node_react_app -->|"renders"| node_mapping
node_react_app -->|"renders"| node_navbar
node_mapping -->|"uses"| node_geo
node_mapping -->|"uses"| node_map_utils
node_mapping -->|"shares"| node_models
node_mapping -->|"handles"| node_route_error
node_main_ts -->|"boots"| node_app_module
node_app_module -->|"loads"| node_routes_module
node_routes_module -->|"contains"| node_routes_controller
node_routes_module -->|"contains"| node_routes_service
node_routes_module -->|"contains"| node_routes_gateway
node_routes_module -->|"persists"| node_route_entity
node_routes_module -->|"contracts"| node_route_dtos
node_routes_controller -->|"calls"| node_routes_service
node_routes_service -->|"stores"| node_route_entity
node_routes_service -->|"publishes"| node_routes_gateway
node_sim_main -->|"starts"| node_route_engine
node_route_engine -->|"reads"| node_destinations
node_route_engine -->|"emits"| node_kafka_produce
node_kafka_produce -->|"uses"| node_kafka_infra
node_kafka_infra -->|"connects"| node_kafka_compose
node_es_connector -->|"extends"| node_kafka_compose
node_routes_gateway -.->|"consumes"| node_kafka_compose
node_routes_service -.->|"initializes"| node_mongo_init
node_react_app -->|"requests"| node_routes_controller
node_react_app -->|"subscribes"| node_routes_gateway
node_sim_main -->|"produces"| node_kafka_compose
node_k8s_backend -.->|"deploys"| node_routes_module
node_k8s_frontend -.->|"deploys"| node_react_app
node_k8s_simulator -.->|"deploys"| node_sim_main

click node_react_app "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/App.tsx"
click node_mapping "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/components/Mapping.tsx"
click node_navbar "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/components/Navbar.tsx"
click node_geo "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/geolocation.ts"
click node_map_utils "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/map.ts"
click node_models "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/models.ts"
click node_route_error "https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/errors/route-exists.error.ts"
click node_main_ts "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/main.ts"
click node_app_module "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/app.module.ts"
click node_routes_module "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.module.ts"
click node_routes_controller "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.controller.ts"
click node_routes_service "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.service.ts"
click node_routes_gateway "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.gateway.ts"
click node_route_entity "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/entities/route.entity.ts"
click node_route_dtos "https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/dto/create-route.dto.ts"
click node_sim_main "https://github.com/devfullcycle/imersao12/blob/main/simulator/main.go"
click node_route_engine "https://github.com/devfullcycle/imersao12/blob/main/simulator/application/route/route.go"
click node_kafka_produce "https://github.com/devfullcycle/imersao12/blob/main/simulator/application/kafka/produce.go"
click node_kafka_infra "https://github.com/devfullcycle/imersao12/blob/main/simulator/infra/kafka/producer.go"
click node_destinations "https://github.com/devfullcycle/imersao12/blob/main/simulator/destinations/1.txt"
click node_kafka_compose "https://github.com/devfullcycle/imersao12/blob/main/apache-kafka/docker-compose.yaml"
click node_es_connector "https://github.com/devfullcycle/imersao12/blob/main/apache-kafka/connectors/elasticsearch.properties"
click node_mongo_init "https://github.com/devfullcycle/imersao12/blob/main/nest-api/.docker/mongo/init.js"
click node_k8s_backend "https://github.com/devfullcycle/imersao12/blob/main/k8s/backend/deploy.yaml"
click node_k8s_frontend "https://github.com/devfullcycle/imersao12/blob/main/k8s/frontend/deploy.yaml"
click node_k8s_simulator "https://github.com/devfullcycle/imersao12/blob/main/k8s/simulator/deploy.yaml"

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_react_app,node_mapping,node_navbar,node_geo,node_map_utils,node_models,node_route_error toneBlue
class node_main_ts,node_app_module,node_routes_module,node_routes_controller,node_routes_service,node_routes_gateway,node_route_entity,node_route_dtos toneAmber
class node_sim_main,node_route_engine,node_kafka_produce,node_kafka_infra,node_destinations toneMint
class node_kafka_compose,node_es_connector toneRose
class node_mongo_init,node_k8s_backend,node_k8s_frontend,node_k8s_simulator toneIndigo
```

## Components

### React frontend

Browser UI for map-based route viewing and interaction.

- [App](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/App.tsx): React shell · Frontend composition root and app wiring. · `react-frontend/src/App.tsx`
- [Mapping](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/components/Mapping.tsx): UI view · Primary map-based route visualization and interaction screen. · `react-frontend/src/components/Mapping.tsx`
- [Navbar](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/components/Navbar.tsx): UI chrome · Top-level navigation and user controls. · `react-frontend/src/components/Navbar.tsx`
- [Geo utils](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/geolocation.ts): Browser geolocation · Client-side location lookup and browser position helpers. · `react-frontend/src/util/geolocation.ts`
- [Map utils](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/map.ts): Map helpers · Map rendering and route visualization helpers. · `react-frontend/src/util/map.ts`
- [Models](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/util/models.ts): UI types · Shared frontend data models for route and map state. · `react-frontend/src/util/models.ts`
- [Route error](https://github.com/devfullcycle/imersao12/blob/main/react-frontend/src/errors/route-exists.error.ts): UI error · Frontend error for duplicate or invalid route creation. · `react-frontend/src/errors/route-exists.error.ts`

### Nest API

HTTP and realtime domain layer for route state.

- [Main](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/main.ts): Nest bootstrap · API process entrypoint. · `nest-api/src/main.ts`
- [App module](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/app.module.ts): Nest root · Root module that composes the application. · `nest-api/src/app.module.ts`
- [Routes module](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.module.ts): Domain module · Feature boundary for route management. · `nest-api/src/routes/routes.module.ts`
- [Routes API](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.controller.ts): HTTP controller · HTTP endpoints for route commands and queries. · `nest-api/src/routes/routes.controller.ts`
- [Routes service](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.service.ts): Domain service · Route business logic and persistence coordination. · `nest-api/src/routes/routes.service.ts`
- [Routes gateway](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/routes.gateway.ts): WebSocket gateway · Realtime update channel for route changes. · `nest-api/src/routes/routes.gateway.ts`
- [Route entity](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/entities/route.entity.ts): Mongo model · Authoritative route persistence model. · `nest-api/src/routes/entities/route.entity.ts`
- [Route DTOs](https://github.com/devfullcycle/imersao12/blob/main/nest-api/src/routes/dto/create-route.dto.ts): API contracts · Create and update payload contracts for the route API. · `nest-api/src/routes/dto/create-route.dto.ts`

### Go simulator

Event producer that emits destination and route movement data.

- [Main](https://github.com/devfullcycle/imersao12/blob/main/simulator/main.go): Go entrypoint · Simulator process entrypoint. · `simulator/main.go`
- [Route engine](https://github.com/devfullcycle/imersao12/blob/main/simulator/application/route/route.go): Go domain · Simulator route behavior and movement logic. · `simulator/application/route/route.go`
- [Kafka produce](https://github.com/devfullcycle/imersao12/blob/main/simulator/application/kafka/produce.go): Event producer · Application-level event publishing workflow. · `simulator/application/kafka/produce.go`
- [Kafka infra](https://github.com/devfullcycle/imersao12/blob/main/simulator/infra/kafka/producer.go): Kafka client · Low-level Kafka producer and consumer wiring. · `simulator/infra/kafka/producer.go`
- [Destinations](https://github.com/devfullcycle/imersao12/blob/main/simulator/destinations/1.txt): Input data · Predefined destination sequences for the simulator. · `simulator/destinations/1.txt`

### Kafka stack

Async messaging and sink integration boundary.

- [Kafka compose](https://github.com/devfullcycle/imersao12/blob/main/apache-kafka/docker-compose.yaml): Kafka stack · Kafka runtime and connector composition. · `apache-kafka/docker-compose.yaml`
- [ES connector](https://github.com/devfullcycle/imersao12/blob/main/apache-kafka/connectors/elasticsearch.properties): Connect config · Kafka Connect Elasticsearch sink configuration. · `apache-kafka/connectors/elasticsearch.properties`

### Deploy assets

Container and Kubernetes packaging for independent runtime units.

- [Mongo init](https://github.com/devfullcycle/imersao12/blob/main/nest-api/.docker/mongo/init.js): DB seed · Mongo initialization script for the API datastore. · `nest-api/.docker/mongo/init.js`
- [Backend deploy](https://github.com/devfullcycle/imersao12/blob/main/k8s/backend/deploy.yaml): K8s manifest · Kubernetes deployment and service boundary for the API. · `k8s/backend/deploy.yaml`
- [Frontend deploy](https://github.com/devfullcycle/imersao12/blob/main/k8s/frontend/deploy.yaml): K8s manifest · Kubernetes deployment and service boundary for the UI. · `k8s/frontend/deploy.yaml`
- [Simulator deploy](https://github.com/devfullcycle/imersao12/blob/main/k8s/simulator/deploy.yaml): K8s manifest · Kubernetes deployment boundary for the Go simulator. · `k8s/simulator/deploy.yaml`

## Connections

- App → Mapping: renders · The app composes the main map experience.
- App → Navbar: renders · The app includes global navigation.
- Mapping → Geo utils: uses · Map UI reads browser location.
- Mapping → Map utils: uses · Map UI delegates rendering and route visualization.
- Mapping → Models: shares · Map UI relies on shared frontend data structures.
- Mapping → Route error: handles · Map UI surfaces route validation failures.
- Main → App module: boots · Nest entrypoint starts the root module.
- App module → Routes module: loads · The root module wires the routes feature.
- Routes module → Routes API: contains · Feature module exposes HTTP handlers.
- Routes module → Routes service: contains · Feature module contains domain logic.
- Routes module → Routes gateway: contains · Feature module exposes realtime updates.
- Routes module → Route entity: persists · Feature module binds the route model.
- Routes module → Route DTOs: contracts · Feature module defines API payloads.
- Routes API → Routes service: calls · HTTP layer delegates business operations.
- Routes service → Route entity: stores · Service owns route persistence.
- Routes service → Routes gateway: publishes · Service pushes route changes to realtime consumers.
- Main → Route engine: starts · Simulator entrypoint initializes route behavior.
- Route engine → Destinations: reads · Route logic consumes predefined destination sequences.
- Route engine → Kafka produce: emits · Route logic forwards events for streaming.
- Kafka produce → Kafka infra: uses · Producer workflow depends on Kafka client plumbing.
- Kafka infra → Kafka compose: connects · Kafka client targets the Kafka runtime boundary.
- ES connector → Kafka compose: extends · Connect config plugs into the Kafka stack.
- Routes gateway → Kafka compose: consumes · Realtime path can subscribe to streamed events.
- Routes service → Mongo init: initializes · API data boundary is backed by Mongo setup.
- App → Routes API: requests · UI talks to the HTTP API for route actions.
- App → Routes gateway: subscribes · UI can receive realtime route updates.
- Main → Kafka compose: produces · Simulator publishes events into Kafka.
- Backend deploy → Routes module: deploys · Kubernetes packages the API service.
- Frontend deploy → App: deploys · Kubernetes packages the frontend service.
- Simulator deploy → Main: deploys · Kubernetes packages the simulator service.
