# hamster-yhz/city-bag architecture

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

- Interactive diagram: https://gitdiagram.com/hamster-yhz/city-bag
- Repository: https://github.com/hamster-yhz/city-bag

## Overview

##### Main Components
- Frontend (city-bag-web): This module contains controllers, DTOs, static resources (like index.html), and REST endpoints. It serves as the public API layer and handles user interactions.
- Backend Service (city-bag-service): This module encapsulates the core business logic. It includes service interfaces, implementation classes, data mappers, domain models (entities/VOs), and integration components (e.g., with third-party APIs like Pexels and AI features). It also shows the use of message consumers (for RabbitMQ), exception handling, and other aspects.
- Application Starter (city-bag-start): This module is responsible for application bootstrapping. It includes configuration classes (AOP for logging, token verification, scheduling, thread pools, Redis, Mybatis Plus, etc.), main application startup, and integration configurations. It coordinates the system’s initialization and external resource connectivity.
- Data Sources & External Services:
- Database: SQL scripts in docs/dev-ops/mysql indicate a MySQL database for storing travel-related data (cities, dormitories, foods, scenic spots, user information, etc.).
- Cache: Redis is integrated (with packages for Redis service and configuration) for caching and perhaps session storage.
- Message Broker: RabbitMQ is set up (with configuration classes) for handling asynchronous messaging (e.g., like message and user visit record consumers).
- File Storage & OSS: There is an OSS service implementation to handle cloud storage or file management.
- External APIs: Modules such as demos/Pexels and demos/AI suggest integration with external services for images and chat features.
- Supporting Tools & Infrastructure:
- Docker / Kubernetes: Dockerfiles and docker-compose files in both city-bag-start and docs/dev-ops point to containerization and orchestration.

##### Relationships and Data Flow
- Client/Browser requests hit the city-bag-web module. These HTTP requests (RESTful API calls) are directed to corresponding controllers.
- The controllers in city-bag-web then make calls to the service layer (either directly or via API calls to city-bag-start, if the latter is acting as a gateway).
- The city-bag-start module acts as the application starter, loading core configurations (AOP, thread pools, scheduling, Redis, Mybatis configurations) and then invoking services from city-bag-service for actual business logic.
- Within the service layer (city-bag-service), business logic is executed, which may involve:
- Database interactions via mappers (MyBatis)
- Use of caching via Redis and Redisson
- Asynchronous messaging via RabbitMQ for tasks such as like-message processing and user visit record handling
- File and image processing using OSS services and photo building strategies
- Integration with third-party APIs, like Pexels for images and AI modules for chat functionality.
- The persistence layer is backed by a MySQL database, with supporting SQL scripts provided in the docs.
- External services like OSS, RabbitMQ, and Redis are clearly separated and connected to the main business layer.

##### Architectural Patterns and Design Principles
- Modularization: Each module has a defined responsibility (API handling, business logic, configuration/startup) and communicates through clearly defined interfaces.
- Use of AOP: There is cross-cutting concern management (logging, token verification) via aspects.
- Containerization & DevOps: Include a container (Docker) layer and deployment orchestration to show how the application is packaged and launched.

## Diagram (Mermaid)

```mermaid
graph TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        Client["Client (Browser)"]:::client
    end

    %% Frontend/API Gateway Layer
    subgraph "Frontend/API Gateway"
        Web["city-bag-web"]:::frontend
    end

    %% Application & Service Layer
    subgraph "Application & Service Layer"
        Start["city-bag-start"]:::service
        Service["city-bag-service"]:::service
        Config["AOP & Config"]:::service
    end

    %% Persistence & External Services Layer
    subgraph "Persistence & External Services"
        MySQL["MySQL Database"]:::infra
        subgraph "Cache (Redis)"
            RedisConf1["RedisClientConfig.java"]:::infra
            RedisConf2["RedisClientConfigProperties.java"]:::infra
            RedisService["Redis Service Implementation"]:::infra
        end
        subgraph "Message Broker (RabbitMQ)"
            RabbitMQConfig["RabbitMQConfig.java"]:::infra
            RabbitMQConsumer["RabbitMQ Consumers"]:::infra
        end
        OSS["OSS Service Implementation"]:::infra
        Pexels["Pexels Integration"]:::infra
        AI["AI Service Integration"]:::infra
    end

    %% DevOps & Documentation Layer
    subgraph "DevOps & Documentation"
        Docker["Dockerfile (city-bag-start)"]:::devops
        Compose["Docker-compose Files"]:::devops
        DeployScripts["Deployment Scripts"]:::devops
        UML["UML & Documentation"]:::doc
    end

    %% Connections
    Client -->|"HTTP_Request"| Web
    Web -->|"API_call"| Start
    Web -->|"API_call"| Service
    Start -->|"Bootstraps"| Service
    Start -->|"Loads_Config"| Config
    Service -->|"DB_Operations"| MySQL
    Service -->|"Cache_Operations"| RedisService
    Service -->|"Message_Handling"| RabbitMQConsumer
    Service -->|"File_Processing"| OSS
    Service -->|"Image_Request"| Pexels
    Service -->|"Chat_Integration"| AI
    RedisService -->|"Uses"| RedisConf1
    RedisService -->|"Uses"| RedisConf2
    RabbitMQConsumer -->|"ConfiguredBy"| RabbitMQConfig

    %% Click Events
    click Web "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-web/"
    click Service "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/"
    click Start "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-start/"
    click MySQL "https://github.com/hamster-yhz/city-bag/tree/main/docs/dev-ops/mysql/sql/"
    click RedisConf1 "https://github.com/hamster-yhz/city-bag/blob/main/city-bag-start/src/main/java/com/op/citybag/config/RedisClientConfig.java"
    click RedisConf2 "https://github.com/hamster-yhz/city-bag/blob/main/city-bag-start/src/main/java/com/op/citybag/config/RedisClientConfigProperties.java"
    click RedisService "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/src/main/java/com/op/citybag/demos/redis/"
    click RabbitMQConfig "https://github.com/hamster-yhz/city-bag/blob/main/city-bag-service/src/main/java/com/op/citybag/demos/rabbitmq/RabbitMQConfig.java"
    click RabbitMQConsumer "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/src/main/java/com/op/citybag/demos/consumer/"
    click OSS "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/src/main/java/com/op/citybag/demos/oss/"
    click Pexels "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/src/main/java/com/op/citybag/demos/Pexels/"
    click AI "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-service/src/main/java/com/op/citybag/demos/AI/"
    click Config "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-start/src/main/java/com/op/citybag/aop/"
    click Docker "https://github.com/hamster-yhz/city-bag/tree/main/city-bag-start/Dockerfile"
    click Compose "https://github.com/hamster-yhz/city-bag/blob/main/docs/dev-ops/docker-compose-*.yml"
    click DeployScripts "https://github.com/hamster-yhz/city-bag/tree/main/docs/dev-ops/app/"
    click UML "https://github.com/hamster-yhz/city-bag/tree/main/docs/dev-ops/uml/"

    %% Styles
    classDef client fill:#F7C6C7,stroke:#333,stroke-width:2px;
    classDef frontend fill:#B3E5FC,stroke:#333,stroke-width:2px;
    classDef service fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef infra fill:#FFE082,stroke:#333,stroke-width:2px;
    classDef devops fill:#D1C4E9,stroke:#333,stroke-width:2px;
    classDef doc fill:#E0E0E0,stroke:#333,stroke-width:2px;
    class Client client;
    class Web frontend;
    class Start service;
    class Service service;
    class Config service;
    class MySQL infra;
    class RedisConf1 infra;
    class RedisConf2 infra;
    class RedisService infra;
    class RabbitMQConfig infra;
    class RabbitMQConsumer infra;
    class OSS infra;
    class Pexels infra;
    class AI infra;
    class Docker devops;
    class Compose devops;
    class DeployScripts devops;
    class UML doc;
```
