# project-marimo/marimo architecture

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

- Interactive diagram: https://gitdiagram.com/project-marimo/marimo
- Repository: https://github.com/project-marimo/marimo

## Overview

##### Project Type and Purpose
- This is a full‑stack, automotive maintenance system consisting of:
- A cross‑platform mobile client (Flutter/Dart) that connects via Bluetooth to an OBD2 scanner, runs on‑device AI for tire wear and expert Q&A, and communicates with a backend via REST.
- A Java Spring Boot monolithic server offering authenticated REST APIs, business logic for car data, card benefits, insurance, navigation and payment management.
- A MySQL relational database and Redis cache, deployed in Docker on AWS EC2, fronted by Nginx, with Jenkins pipelines for CI/CD.

##### Main Architectural Zones
- Mobile Client Zone
- Flutter UI screens (home, map, monitoring, payment, insurance, signin, tire diagnosis).
- State management via Provider.
- Bluetooth module ↔ OBD2 scanner for real‑time vehicle data.
- On‑device AI: Gemma3 for chat/expert AI; MobileNetV2 for tire wear detection.
- HTTP client services for REST calls to backend.
- Backend Server Zone
- API Layer: Controllers grouped by domain (auth, car, card, insurance, navigation, payment, external).
- Service Layer: Business logic, algorithmic processing, external API integration (Fintech, Opinet).
- Data Layer: JPA repositories ↔ MySQL; RedisCache for user card‑benefit caching.
- Security: Spring Security with JWT filters.
- Configuration, aspects, converters, exception handling.
- Infrastructure Zone
- Docker container running Spring Boot.
- Nginx reverse proxy (SSL termination, routing).
- AWS RDS (MySQL), AWS EC2 (app server), Redis 7.0.
- CI/CD: Jenkins builds Docker images, deploys to AWS.
- External services: SSAFY financial network for card data; Opinet fuel price API.

##### Architectural Patterns and Design Principles
- Layered architecture on backend (Controller → Service → Repository).
- Domain‑driven package organization (auth, car, card, insurance, navigation, payment).
- Provider pattern on Flutter for separation of UI and state.
- On‑device AI for latency reduction and privacy.
- Caching to solve N+1 and improve performance (Redis + fetch join).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client Zone
    subgraph "Mobile Client Zone"
        direction TB
        FlutterApp["Flutter App"]:::mobile
        Screens["UI Screens"]:::mobile
        Provider["State Management (Provider)"]:::mobile
        BluetoothModule["Bluetooth Module"]:::mobile
        OBD2["OBD2 Scanner"]:::external
        AIModels["On-device AI Models"]:::mobile
        ChatService["Chat/Expert AI Service"]:::mobile
        HTTPClient["HTTP Client Services"]:::mobile
    end

    %% Backend Server Zone
    subgraph "Backend Server Zone"
        direction TB
        Nginx["Nginx Reverse Proxy"]:::infra
        SpringBoot["Spring Boot API"]:::backend
        Controllers["API Layer - Controllers"]:::backend
        Services["Service Layer"]:::backend
        Repositories["Data Layer - JPA Repositories"]:::backend
        Security["Security Config & JWT Filters"]:::backend
        RedisCacheConfig["Redis Caching Config"]:::backend
        FintechClient["External Fintech API Client"]:::external
        OpinetSync["Opinet Fuel Price Sync Service"]:::backend
    end

    %% Data Stores Zone
    subgraph "Data Stores"
        direction TB
        MySQL["MySQL Database"]:::cylinder
        RedisDB["Redis Cache"]:::cylinder
    end

    %% Infrastructure Zone
    subgraph "Infrastructure & CI/CD"
        direction TB
        DockerRegistry["Docker Registry"]:::infra
        Jenkins["Jenkins CI/CD"]:::infra
        AWS_EC2["AWS EC2"]:::cloud
        AWS_RDS["AWS RDS (MySQL)"]:::cloud
        ExternalCardNet["SSAFY Financial Network"]:::external
        OpinetAPI["Opinet Fuel Price API"]:::external
    end

    %% Mobile Client flows
    FlutterApp --> Screens
    FlutterApp --> Provider
    Provider --> BluetoothModule
    BluetoothModule -->|TCP-Bluetooth| OBD2
    FlutterApp --> AIModels
    FlutterApp --> ChatService
    FlutterApp --> HTTPClient
    HTTPClient -->|HTTP/HTTPS| Nginx

    %% Backend flows
    Nginx -->|routes| SpringBoot
    SpringBoot --> Controllers
    Controllers --> Services
    Services --> Repositories
    Repositories --> MySQL
    Services -->|cache| RedisDB
    Services --> Security
    Services --> RedisCacheConfig
    Services --> FintechClient
    Services --> OpinetSync
    FintechClient -->|HTTPS| ExternalCardNet
    OpinetSync -->|HTTPS| OpinetAPI

    %% CI/CD & Deployment
    Jenkins -->|build| DockerRegistry
    Jenkins -->|deploy| AWS_EC2
    AWS_EC2 --> Nginx
    AWS_EC2 --> SpringBoot
    AWS_RDS --> MySQL

    %% Click Events
    click Screens "https://github.com/project-marimo/marimo/tree/master/marimo_client/lib/screens"
    click Provider "https://github.com/project-marimo/marimo/tree/master/marimo_client/lib/providers"
    click BluetoothModule "https://github.com/project-marimo/marimo/blob/master/marimo_client/android/app/src/main/kotlin/com/example/marimo_client/BluetoothHelper.kt"
    click AIModels "https://github.com/project-marimo/marimo/blob/master/marimo_client/assets/ai/tire_depth_model.tflite"
    click ChatService "https://github.com/project-marimo/marimo/blob/master/marimo_client/lib/services/commons/chat_service.dart"
    click HTTPClient "https://github.com/project-marimo/marimo/blob/master/marimo_client/lib/services/commons/api.dart"
    click SpringBoot "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/MarimoApplication.java"
    click Controllers "https://github.com/project-marimo/marimo/tree/master/marimo-server/src/main/java/com/ssafy/marimo/*/controller"
    click Services "https://github.com/project-marimo/marimo/tree/master/marimo-server/src/main/java/com/ssafy/marimo/*/service"
    click Repositories "https://github.com/project-marimo/marimo/tree/master/marimo-server/src/main/java/com/ssafy/marimo/*/repository"
    click Security "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/common/config/SecurityConfig.java"
    click Security "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/common/filter/JWTFilter.java"
    click RedisCacheConfig "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/common/config/RedisCacheConfig.java"
    click FintechClient "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/external/fintech/FintechApiClient.java"
    click OpinetSync "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/java/com/ssafy/marimo/navigation/service/OpinetStationSyncService.java"
    click DockerRegistry "https://github.com/project-marimo/marimo/tree/master/marimo-server/Dockerfile"
    click Jenkins "https://github.com/project-marimo/marimo/tree/master/.gitlab/merge_request_templates"
    click AWS_RDS "https://github.com/project-marimo/marimo/blob/master/marimo-server/src/main/resources/application.yml"

    %% Styles
    classDef mobile fill:#D0E8FF,stroke:#009,stroke-width:1px
    classDef backend fill:#DFFFD0,stroke:#090,stroke-width:1px
    classDef cylinder fill:#FFF2CC,stroke:#CC9900,stroke-width:1px
    classDef cloud fill:#F0F8FF,stroke:#00A,stroke-width:1px
    classDef infra fill:#EEEEEE,stroke:#666,stroke-width:1px
    classDef external fill:#F8D7DA,stroke:#D00,stroke-width:1px
    class Screens,Provider,BluetoothModule,AIModels,ChatService,HTTPClient mobile
    class Nginx,SpringBoot,Controllers,Services,Repositories,Security,RedisCacheConfig backend
    class MySQL,RedisDB cylinder
    class AWS_EC2,AWS_RDS cloud
    class DockerRegistry,Jenkins infra
    class ExternalCardNet,OpinetAPI external
```
