# danielsrs/relampago_marquinhos architecture

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

- Interactive diagram: https://gitdiagram.com/danielsrs/relampago_marquinhos
- Repository: https://github.com/danielsrs/relampago_marquinhos

## Overview

##### Project Type and Purpose
- This is a monorepo full‑stack TypeScript project managing EV charging stations and user interactions.
- It comprises three principal “apps”:
- Car client (apps/car) – a React (likely React Native) application that simulates an electric vehicle.
- Station client (apps/station) – a React application for station operators.
- Server (src/) – a Node.js/TypeScript REST API with in‑memory (or pluggable) data storage and Zod validation.
- There is also a shared package (apps/shared) providing common UI components, API client, utilities, and contexts.

##### File Structure
- Top‑level:
- package.json, Dockerfiles, docker-compose.yml, install scripts, tsconfig.json – define workspaces, scripts, Docker build, and CI/test setup.
- apps/ – Yarn workspace containing car, station, shared packages.
- src/ – main server and CLI tools (car.ts, station.ts) plus validation schemas and route definitions.
- apps/car and apps/station have their own src/ pages, navigation, state stores (persisted/shared-data), and use apps/shared as a dependency.
- src/server/router.ts and src/server/routes/* implement REST endpoints (registerCar, registerStation, startCharging, reserve, stationSuggestions, etc.).
- Shared code (apps/shared) contains UI components (Navigator, ScrollView, cards), a typed API client (src/api/client.ts), contexts, storage libs, and TCP/log utilities.

##### README for Insights
- Confirms: Node.js + Yarn 4 workspaces; Docker for containerized runs; Zod for validation; Vitest for tests; core features: register users/stations, manage charging sessions, recommendations, payments.

1. Car Client App (apps/car)
2. Station Client App (apps/station)
3. Shared Library (apps/shared)
4. Server API (src/server)
5. Data Layer (src/server/data/data.ts or pluggable DB)
6. CLI Utilities (src/car.ts, src/station.ts) – optional inset

- Both client apps import Common UI & API client from Shared Library.
- Car/Station UIs → HTTP requests → Server Router → Route Handlers → Data Layer.
- Server route handlers use Zod schemas (src/schemas) and business logic (main.ts) for recommendations.
- CLI utils use the same API client against the Server endpoint (for testing or automation).
- docker-compose orchestrates containers: car, station, server.

c. Architectural Patterns & Principles
- Monorepo with Yarn Workspaces – single root coordinating multiple packages.
- Layered architecture in Server: Router → Controllers (routes) → Business Logic → Data Store.
- Shared component library for DRY UI and API client code.
- Zod‑based schema validation ensuring type safety at the edge.
- Clear separation of concerns: Frontends vs. Backend vs. Shared libs.

d. Key Technologies & Frameworks
- TypeScript, Node.js, React (Native)
- Yarn Workspaces, Docker, docker‑compose
- Zod for validation, Vitest for testing
- React Navigation, Context API, custom storage libs

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend" 
        CarApp["Car App\n(React Native)"]:::frontend
        StationApp["Station App\n(React)"]:::frontend
    end

    %% Shared Layer
    subgraph "Shared Library"
        SharedLib["Shared Library"]:::shared
        UI["UI Components"]:::shared
        APIClient["API Client"]:::shared
        UtilsShared["Utils & Contexts"]:::shared
    end

    %% Backend Layer
    subgraph "Backend"
        Server["Server Entry\n(server.ts)"]:::backend
        Router["Server Router\n(router.ts)"]:::backend
        Routes["Route Handlers\n(src/server/routes)"]:::backend
        Schemas["Zod Validation Schemas\n(schemas)"]:::backend
        Logic["Business Logic\n(main.ts)"]:::backend
        Data["Data Layer\n(data.ts)"]:::backend
        ErrorCodes["Error Codes\n(error-codes.ts)"]:::backend
        UtilsBE["Utilities\n(utils.ts)"]:::backend
        CLI_Car["CLI: Car Simulation\n(car.ts)"]:::backend
        CLI_Station["CLI: Station Simulation\n(station.ts)"]:::backend
    end

    %% Infrastructure
    Infra["docker-compose\nOrchestration"]:::infra

    %% Relationships
    CarApp -->|imports| SharedLib
    StationApp -->|imports| SharedLib

    CarApp -->|uses| UI
    StationApp -->|uses| UI

    CarApp -->|calls| APIClient
    StationApp -->|calls| APIClient

    CLI_Car -->|uses API| APIClient
    CLI_Station -->|uses API| APIClient

    APIClient -->|HTTP calls| Server

    Server -->|register handlers| Router
    Router -->|routes to| Routes

    Routes -->|validate| Schemas
    Routes -->|invoke| Logic
    Routes -->|error handling| ErrorCodes

    Logic -->|access| Data
    Logic -->|use utils| UtilsBE

    Infra --> CarApp
    Infra --> StationApp
    Infra --> Server

    %% Click Events
    click CarApp "https://github.com/danielsrs/relampago_marquinhos/tree/main/apps/car"
    click StationApp "https://github.com/danielsrs/relampago_marquinhos/tree/main/apps/station"
    click SharedLib "https://github.com/danielsrs/relampago_marquinhos/tree/main/apps/shared"
    click APIClient "https://github.com/danielsrs/relampago_marquinhos/blob/main/apps/shared/src/api/client.ts"
    click Server "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/server.ts"
    click Router "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/server/router.ts"
    click Routes "https://github.com/danielsrs/relampago_marquinhos/tree/main/src/server/routes"
    click Data "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/server/data/data.ts"
    click Schemas "https://github.com/danielsrs/relampago_marquinhos/tree/main/src/schemas"
    click Logic "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/main.ts"
    click CLI_Car "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/car.ts"
    click CLI_Station "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/station.ts"
    click ErrorCodes "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/error-codes.ts"
    click UtilsBE "https://github.com/danielsrs/relampago_marquinhos/blob/main/src/utils.ts"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,color:#004085
    classDef shared fill:#e2e3e5,stroke:#6c757d,color:#343a40
    classDef backend fill:#d4edda,stroke:#155724,color:#155724
    classDef infra fill:#fff3cd,stroke:#856404,color:#856404
```
