-
Notifications
You must be signed in to change notification settings - Fork 0
공유 자전거 서비스 설계 ‐ Sample
LeeJongSeon edited this page Oct 22, 2024
·
2 revisions
graph TB
subgraph "Client Layer"
iOS["iOS App"]
Bike["자전거(MQTT Client)"]
end
subgraph "Backend Layer"
API["Spring Boot Application"]
MQTT["MQTT Broker<br/>(Mosquitto)"]
end
subgraph "Database Layer"
DB[(Single Database<br/>H2 or MySQL)]
end
iOS --> API
Bike --> MQTT
MQTT --> API
API --> DB
-- 사용자 테이블
CREATE TABLE users (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
name VARCHAR(100),
phone VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 결제수단 테이블
CREATE TABLE payment_methods (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
card_number VARCHAR(255) NOT NULL,
is_default BOOLEAN DEFAULT false,
FOREIGN KEY (user_id) REFERENCES users(id)
);
-- 스테이션 테이블
CREATE TABLE stations (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
latitude DOUBLE NOT NULL,
longitude DOUBLE NOT NULL,
is_temporary BOOLEAN DEFAULT false,
created_by BIGINT, -- 임시 스테이션을 만든 사용자 ID
FOREIGN KEY (created_by) REFERENCES users(id)
);
-- 자전거 테이블
CREATE TABLE bikes (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
qr_code VARCHAR(100) UNIQUE NOT NULL,
battery_level INTEGER NOT NULL,
status VARCHAR(20) NOT NULL, -- AVAILABLE, IN_USE, MAINTENANCE
current_station_id BIGINT,
FOREIGN KEY (current_station_id) REFERENCES stations(id)
);
-- 대여 테이블
CREATE TABLE rentals (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT NOT NULL,
bike_id BIGINT NOT NULL,
start_station_id BIGINT NOT NULL,
end_station_id BIGINT,
start_time TIMESTAMP NOT NULL,
end_time TIMESTAMP,
status VARCHAR(20) NOT NULL, -- ACTIVE, PAUSED, COMPLETED
total_amount INTEGER,
FOREIGN KEY (user_id) REFERENCES users(id),
FOREIGN KEY (bike_id) REFERENCES bikes(id),
FOREIGN KEY (start_station_id) REFERENCES stations(id),
FOREIGN KEY (end_station_id) REFERENCES stations(id)
);
-- 결제 테이블
CREATE TABLE payments (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
rental_id BIGINT NOT NULL,
amount INTEGER NOT NULL,
status VARCHAR(20) NOT NULL, -- PENDING, COMPLETED, FAILED
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (rental_id) REFERENCES rentals(id)
);
샘플 프로젝트를 위한 추천 기술 스택:
- 데이터베이스
- 개발/테스트: H2 Database (인메모리 DB)
- 데모용 배포: MySQL (무료, 설정 간편)
- 백엔드
- Spring Boot 3.x
- Spring Security + JWT
- Spring Data JPA
- Lombok
- MapStruct (객체 매핑)
- MQTT
- Mosquitto (가볍고 설정이 간단한 MQTT 브로커)
- Spring Integration MQTT
- API 문서화
- SpringDoc OpenAPI (Swagger)
프로젝트 구조:
src/
├── main/
│ ├── java/
│ │ └── com/
│ │ └── bikeshare/
│ │ ├── BikeShareApplication.java
│ │ ├── config/
│ │ │ ├── SecurityConfig.java
│ │ │ └── MqttConfig.java
│ │ ├── controller/
│ │ │ ├── AuthController.java
│ │ │ ├── BikeController.java
│ │ │ ├── StationController.java
│ │ │ └── RentalController.java
│ │ ├── model/
│ │ │ ├── entity/
│ │ │ └── dto/
│ │ ├── repository/
│ │ └── service/
│ └── resources/
│ ├── application.yml
│ └── data.sql
- 제외된 요소들
- 서비스 이중화
- 캐시 서버
- 메시지 큐
- 별도의 모니터링 시스템
- 로그 수집 시스템
🍎 말고 🍅