Skip to content

MinKyeom/MSA_Project

Repository files navigation

MSA λΈ”λ‘œκ·Έ ν”Œλž«νΌ

λ¬Έμ„œ μ–Έμ–΄ 선택 | Select language: ν•œκΈ€ (kor) Β· English (eng)


πŸ‡°πŸ‡· ν•œκΈ€ 버전

데이터 ꡬ쑰

λ°μ΄ν„°λ² μ΄μŠ€ μ»¨ν…Œμ΄λ„ˆ μš©λ„
Auth DB msa-db-auth (PostgreSQL 15) μΈμ¦Β·κΆŒν•œ, κ΄€λ¦¬μž, OAuth2 연동 정보
User DB msa-db-user (PostgreSQL 15) μ‚¬μš©μž ν”„λ‘œν•„Β·μ •λ³΄
Post DB msa-db-post (PostgreSQL 15) κ²Œμ‹œκΈ€, λŒ“κΈ€, μΉ΄ν…Œκ³ λ¦¬Β·νƒœκ·Έ
Search DB msa-db-search (pgvector/pg15) 벑터 검색 인덱슀 (sentence-transformers μž„λ² λ”©)

챗봇 λŒ€ν™”Β·νŒŒμΌ 등은 data/chatbot 디렉터리에 λ³Όλ₯¨μœΌλ‘œ μ €μž₯λ©λ‹ˆλ‹€.


μ•„ν‚€ν…μ²˜ ꡬ성도

flowchart TB
    subgraph Client
        Browser[λΈŒλΌμš°μ €]
    end
    subgraph Nginx["Nginx (호슀트)"]
        N[":443 / :80"]
    end
    subgraph Frontend
        Next["Next.js\n:3000"]
    end
    subgraph Gateway["API Gateway :8085"]
        GW[Spring Cloud Gateway]
    end
    subgraph Backend["λ°±μ—”λ“œ μ„œλΉ„μŠ€"]
        Auth[auth-service :8084]
        User[user-service :8081]
        Post[post-service :8082]
        AI[fastapi-ai :8000]
        Search[search-service :8010]
        Mail[mail-service :8083]
    end
    subgraph Data["데이터·인프라"]
        Redis[Redis :6379]
        Kafka[Kafka :9092]
        DBA[db-auth]
        DBU[db-user]
        DBP[db-post]
        DBS[db-search]
    end
    Browser --> N
    N -->|"/"| Next
    N -->|"/user/,/auth/,/api/,/chat"| GW
    GW --> Auth
    GW --> User
    GW --> Post
    GW --> AI
    GW --> Search
    Auth --> Redis
    Auth --> DBA
    User --> DBU
    User --> Kafka
    Post --> DBP
    Post --> Kafka
    AI --> Redis
    Search --> DBS
    Search --> Kafka
    Mail --> Kafka
Loading

μ‹œμŠ€ν…œ μ•„ν‚€ν…μ²˜

  • 단일 μ§„μž…μ : Nginx β†’ API Gateway(Spring Cloud Gateway). λͺ¨λ“  APIλŠ” Gatewayλ₯Ό 거쳐 JWT 검증·Trace ID λΆ€μ—¬ ν›„ 각 λ§ˆμ΄ν¬λ‘œμ„œλΉ„μŠ€λ‘œ λΌμš°νŒ…λ©λ‹ˆλ‹€.
  • ν”„λ‘ νŠΈμ—”λ“œ: Next.js 14 (App Router). Nginxμ—μ„œ /λŠ” Next.js(3000)둜 직접 ν”„λ‘μ‹œλ©λ‹ˆλ‹€.
  • 이벀트 λ“œλ¦¬λΈ: νšŒμ›κ°€μž…Β·κ²Œμ‹œκΈ€ λ“± μ΄λ²€νŠΈλŠ” Kafka둜 λ°œν–‰λ˜λ©°, Mail μ„œλΉ„μŠ€Β·Search 인덱싱 등이 κ΅¬λ…ν•©λ‹ˆλ‹€.
  • 인프라: Redis(μΊμ‹œΒ·Refresh TokenΒ·λž­ν‚Ή), Kafka(KRaft 단일 λ…Έλ“œ), PostgreSQL 4μ’…(μ„œλΉ„μŠ€λ³„ DB 뢄리).

ν”„λ‘œμ νŠΈ ꡬ쑰

my-msa-project-new/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ gateway-service/   # Spring Cloud Gateway (JWT, λΌμš°νŒ…)
β”‚   β”œβ”€β”€ auth-service/      # λ‘œκ·ΈμΈΒ·νšŒμ›κ°€μž…Β·OAuth2Β·JWT
β”‚   β”œβ”€β”€ user-service/      # μ‚¬μš©μž ν”„λ‘œν•„
β”‚   β”œβ”€β”€ post-service/      # κ²Œμ‹œκΈ€Β·λŒ“κΈ€
β”‚   β”œβ”€β”€ smtp-service/      # Kafka μˆ˜μ‹  β†’ 이메일 λ°œμ†‘
β”‚   β”œβ”€β”€ fastapi-ai/        # AI 챗봇 (LangChain, Groq)
β”‚   └── search-service/    # FastAPI + pgvector 벑터 검색
β”œβ”€β”€ frontend/
β”‚   └── nextjs-app/        # Next.js 14 μ•±
β”œβ”€β”€ nginx/                 # Nginx μ„€μ • (별도 μ €μž₯μ†Œ/폴더)
β”‚   β”œβ”€β”€ sites-available/
β”‚   └── sites-enabled/
β”œβ”€β”€ monitoring/            # Loki Stack (Fluent Bit, Loki, Grafana)
β”œβ”€β”€ docs/                  # ν”„λ‘œμ νŠΈΒ·Nginx λ¬Έμ„œ
β”œβ”€β”€ data/                  # DB·챗봇 λ³Όλ₯¨ 마운트
β”œβ”€β”€ docker-compose.yml     # 메인 μ˜€μΌ€μŠ€νŠΈλ ˆμ΄μ…˜
└── .env.example           # ν™˜κ²½ λ³€μˆ˜ ν…œν”Œλ¦Ώ

μš”μ²­ 흐름

  1. μ‚¬μš©μž β†’ Nginx(HTTPS) β†’ κ²½λ‘œμ— 따라 λΆ„κΈ°
  2. / β†’ Next.js(3000): νŽ˜μ΄μ§€Β·μ •μ  μžμ‚°
  3. /user/, /auth/, /api/posts, /api/search, /chat β†’ API Gateway(8085)
  4. Gateway β†’ JWT 검증(ν•΄λ‹Ή 경둜) Β· Trace ID λΆ€μ—¬ β†’ ν•΄λ‹Ή μ„œλΉ„μŠ€λ‘œ ν”„λ‘μ‹œ
    • /user/** β†’ user-service:8081
    • /auth/** β†’ auth-service:8084
    • /api/posts/** β†’ post-service:8082
    • /api/search/** β†’ search-service:8010
    • /chat/** β†’ fastapi-ai:8000
  5. μ„œλΉ„μŠ€ β†’ 각 DBΒ·RedisΒ·Kafka μ‚¬μš© ν›„ 응닡 β†’ Gateway β†’ Nginx β†’ ν΄λΌμ΄μ–ΈνŠΈ

Nginx λΌμš°νŒ…

Nginx 섀정은 nginx/ 디렉터리에 있으며, μš΄μ˜μ€ sites-available/msa-project(ν™œμ„±: sites-enabled/msa-project)λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€.

location ν”„λ‘μ‹œ λŒ€μƒ λΉ„κ³ 
location / http://127.0.0.1:3000 Next.js
location /user/ http://msa-gateway (127.0.0.1:8085) Gateway β†’ user-service
location /auth/ http://msa-gateway Gateway β†’ auth-service
location /api/posts http://msa-gateway Gateway β†’ post-service
location /api/search http://msa-gateway Gateway β†’ search-service
location /chat http://msa-gateway AI 챗봇 (νƒ€μž„μ•„μ›ƒ 600s)
location /actuator http://msa-gateway ν—¬μŠ€μ²΄ν¬Β·λ°±μ˜€ν”ΌμŠ€
location /grafana/ http://127.0.0.1:3001 Grafana (monitoring ν”„λ‘œνŒŒμΌ)
  • μ—…μŠ€νŠΈλ¦Ό: upstream msa-gateway { server 127.0.0.1:8085 max_fails=2 fail_timeout=30s; keepalive 8; }
  • 개발 도메인 dev.minkowskim.com: / β†’ 4000, APIΒ·authΒ·userΒ·chat β†’ 9085(Gateway).

μžμ„Έν•œ μ„€λͺ…은 docs/nginx-aws-lightsail.mdλ₯Ό μ°Έκ³ ν•˜μ„Έμš”.


API λͺ…μ„Έ

Gateway κ²½λ‘œμ™€ λ°±μ—”λ“œ μ„œλΉ„μŠ€ λ§€ν•‘(운영: application-prod.yml κΈ°μ€€)은 λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

경둜 μ„œλΉ„μŠ€ μ„€λͺ…
/user, /user/** user-service:8081 μ‚¬μš©μž ν”„λ‘œν•„Β·μ •λ³΄
/auth, /auth/** auth-service:8084 λ‘œκ·ΈμΈΒ·νšŒμ›κ°€μž…Β·OAuth2Β·JWT·인증 메일
/api/posts, /api/posts/** post-service:8082 κ²Œμ‹œκΈ€Β·λŒ“κΈ€ CRUD
/chat, /chat/** fastapi-ai:8000 AI 챗봇 (SSE/슀트리밍)
/api/search, /api/search/** search-service:8010 λ²‘ν„°Β·ν‚€μ›Œλ“œ 검색

인증이 ν•„μš”ν•œ APIλŠ” Authorization: Bearer <JWT> λ˜λŠ” μΏ ν‚€(authToken)둜 μ „λ‹¬ν•©λ‹ˆλ‹€. 상세 μ—”λ“œν¬μΈνŠΈλŠ” 각 μ„œλΉ„μŠ€ μ†ŒμŠ€ 및 Gateway 섀정을 μ°Έκ³ ν•˜μ„Έμš”.


λΉ λ₯Έ μ‹œμž‘

μš”κ΅¬ 사항

  • Docker, Docker Compose
  • (선택) Nginx μ„€μΉ˜ 및 nginx/ μ„€μ • 배치

μ‹€ν–‰

# 1. ν™˜κ²½ λ³€μˆ˜ μ„€μ •
cp .env.example .env
# .env λ‚΄ DB λΉ„λ°€λ²ˆν˜Έ, JWT_SECRET, OAuth2, GROQ_API_KEY λ“± μˆ˜μ •

# 2. 전체 μŠ€νƒ 기동 (4GB λ©”λͺ¨λ¦¬ κΈ°μ€€)
docker compose up -d

# 3. (선택) λͺ¨λ‹ˆν„°λ§ μŠ€νƒ 기동
docker compose --profile monitoring up -d

μ„œλΉ„μŠ€ ꡬ성

μ„œλΉ„μŠ€ 포트 기술 μŠ€νƒ λΉ„κ³ 
api-gateway 8085 Spring Boot 3, Spring Cloud Gateway JWTΒ·Trace IDΒ·λΌμš°νŒ…
auth-service 8084 Spring Boot, JPA, OAuth2, Redis, Kafka κ΄€λ¦¬μž λΆ€νŠΈμŠ€νŠΈλž©
user-service 8081 Spring Boot, JPA, Kafka
post-service 8082 Spring Boot, JPA, WebClient, Kafka
mail-service 8083 Spring Boot, Kafka, Mail Kafka ꡬ독 β†’ SMTP
fastapi-ai 8000 FastAPI, LangChain, Groq, Redis 챗봇
search-service 8010 FastAPI, pgvector, Kafka 벑터 인덱싱
frontend 3000 Next.js 14
redis 6379 Redis Alpine
msa-kafka 9092 Apache Kafka 3.7 (KRaft)
db-auth / db-user / db-post / db-search 5434/5432/5433/5435 PostgreSQL 15, pgvector

λ°±μ˜€ν”ΌμŠ€Β·λͺ¨λ‹ˆν„°λ§

  • λ°±μ˜€ν”ΌμŠ€: Next.js /backoffice νŽ˜μ΄μ§€μ—μ„œ 관리 κΈ°λŠ₯ 제곡. Gateway /actuator둜 ν—¬μŠ€μ²΄ν¬ κ°€λŠ₯.
  • λͺ¨λ‹ˆν„°λ§: docker compose --profile monitoring up -d 둜 Fluent Bit β†’ Loki β†’ Grafana 기동. GrafanaλŠ” Nginxμ—μ„œ /grafana/둜 μ ‘κ·Ό κ°€λŠ₯(μ„€μ • μ‹œ 3001β†’ν”„λ‘μ‹œ).
  • Kafka UI(선택): docker compose --profile tools up -d 둜 8080μ—μ„œ Kafka UI μ‚¬μš© κ°€λŠ₯.

ν™˜κ²½ λ³€μˆ˜

.env.example을 볡사해 .envλ₯Ό λ§Œλ“€κ³  μ•„λž˜ ν•­λͺ©μ„ μ±„μ›λ‹ˆλ‹€.

ꡬ뢄 μ£Όμš” λ³€μˆ˜
DB POSTGRES_USER, POSTGRES_PASSWORD, DB_AUTH_NAME, DB_USER_NAME, DB_POST_NAME, DB_SEARCH_NAME
JWTΒ·κ΄€λ¦¬μž JWT_SECRET, ADMIN_USERNAME, ADMIN_PASSWORD
OAuth2 OAUTH2_GOOGLE_*, OAUTH2_KAKAO_*, COOKIE_DOMAIN, FRONTEND_URL
RedisΒ·Kafka SPRING_REDIS_HOST, REDIS_*, SPRING_KAFKA_BOOTSTRAP_SERVERS
SMTP MAIL_USERNAME, MAIL_PASSWORD
AI GROQ_API_KEY
ν”„λ‘ νŠΈ λΉŒλ“œ μ‹œ NEXT_PUBLIC_API_URL, NEXT_PUBLIC_AUTH_API_URL, NEXT_PUBLIC_*_API_URL
λͺ¨λ‹ˆν„°λ§ GRAFANA_ADMIN_PASSWORD

μ°Έκ³  λ¬Έμ„œ

λ¬Έμ„œ μ„€λͺ…
docs/PROJECT_UPDATES.md ν”„λ‘œμ νŠΈ μ—…λ°μ΄νŠΈΒ·λ³€κ²½ 이λ ₯
docs/nginx-aws-lightsail.md Nginx 디렉터리 ꡬ쑰, λΌμš°νŒ…, SSL, Lightsail μ°Έκ³ 
nginx/sites-available/msa-project 운영 Nginx μ„€μ • 파일
monitoring/docker-compose.monitoring.yml Loki Stack λͺ¨λ‹ˆν„°λ§ Compose

맨 μœ„λ‘œ Β· English (eng)


πŸ‡¬πŸ‡§ English Version

Language

Select language: ν•œκΈ€ (kor) Β· English (eng)


Data Structure

Database Container Purpose
Auth DB msa-db-auth (PostgreSQL 15) Authentication, authorization, admin, OAuth2
User DB msa-db-user (PostgreSQL 15) User profiles and info
Post DB msa-db-post (PostgreSQL 15) Posts, comments, categories, tags
Search DB msa-db-search (pgvector/pg15) Vector search index (sentence-transformers embeddings)

Chatbot conversations and files are stored under data/chatbot (volume).


Architecture Diagram

flowchart TB
    subgraph Client
        Browser[Browser]
    end
    subgraph Nginx["Nginx (Host)"]
        N[":443 / :80"]
    end
    subgraph Frontend
        Next["Next.js\n:3000"]
    end
    subgraph Gateway["API Gateway :8085"]
        GW[Spring Cloud Gateway]
    end
    subgraph Backend["Backend Services"]
        Auth[auth-service :8084]
        User[user-service :8081]
        Post[post-service :8082]
        AI[fastapi-ai :8000]
        Search[search-service :8010]
        Mail[mail-service :8083]
    end
    subgraph Data["Data & Infra"]
        Redis[Redis :6379]
        Kafka[Kafka :9092]
        DBA[db-auth]
        DBU[db-user]
        DBP[db-post]
        DBS[db-search]
    end
    Browser --> N
    N -->|"/"| Next
    N -->|"/user/,/auth/,/api/,/chat"| GW
    GW --> Auth
    GW --> User
    GW --> Post
    GW --> AI
    GW --> Search
    Auth --> Redis
    Auth --> DBA
    User --> DBU
    User --> Kafka
    Post --> DBP
    Post --> Kafka
    AI --> Redis
    Search --> DBS
    Search --> Kafka
    Mail --> Kafka
Loading

System Architecture

  • Single entry point: Nginx β†’ API Gateway (Spring Cloud Gateway). All API traffic is validated (JWT), tagged with Trace ID, then routed to microservices.
  • Frontend: Next.js 14 (App Router). Nginx proxies / to Next.js on port 3000.
  • Event-driven: User/post events are published to Kafka; Mail and Search services consume them.
  • Infrastructure: Redis (cache, refresh tokens, rankings), Kafka (KRaft single node), four PostgreSQL instances (one per domain).

Project Structure

my-msa-project-new/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ gateway-service/   # Spring Cloud Gateway (JWT, routing)
β”‚   β”œβ”€β”€ auth-service/      # Login, signup, OAuth2, JWT
β”‚   β”œβ”€β”€ user-service/      # User profiles
β”‚   β”œβ”€β”€ post-service/      # Posts, comments
β”‚   β”œβ”€β”€ smtp-service/      # Kafka β†’ email (SMTP)
β”‚   β”œβ”€β”€ fastapi-ai/        # AI chatbot (LangChain, Groq)
β”‚   └── search-service/    # FastAPI + pgvector search
β”œβ”€β”€ frontend/
β”‚   └── nextjs-app/        # Next.js 14 app
β”œβ”€β”€ nginx/                 # Nginx config (separate folder)
β”‚   β”œβ”€β”€ sites-available/
β”‚   └── sites-enabled/
β”œβ”€β”€ monitoring/            # Loki Stack (Fluent Bit, Loki, Grafana)
β”œβ”€β”€ docs/                  # Project and Nginx docs
β”œβ”€β”€ data/                  # DB and chatbot volumes
β”œβ”€β”€ docker-compose.yml     # Main orchestration
└── .env.example           # Environment template

Request Flow

  1. User β†’ Nginx (HTTPS) β†’ path-based routing.
  2. / β†’ Next.js (3000): pages and static assets.
  3. /user/, /auth/, /api/posts, /api/search, /chat β†’ API Gateway (8085).
  4. Gateway β†’ JWT validation (where applicable), Trace ID β†’ proxy to service:
    • /user/** β†’ user-service:8081
    • /auth/** β†’ auth-service:8084
    • /api/posts/** β†’ post-service:8082
    • /api/search/** β†’ search-service:8010
    • /chat/** β†’ fastapi-ai:8000
  5. Services β†’ DB / Redis / Kafka β†’ response β†’ Gateway β†’ Nginx β†’ client.

Nginx Routing

Nginx configuration lives under nginx/. Production uses sites-available/msa-project (enabled via sites-enabled/msa-project).

location Proxy target Notes
location / http://127.0.0.1:3000 Next.js
location /user/ http://msa-gateway (127.0.0.1:8085) Gateway β†’ user-service
location /auth/ http://msa-gateway Gateway β†’ auth-service
location /api/posts http://msa-gateway Gateway β†’ post-service
location /api/search http://msa-gateway Gateway β†’ search-service
location /chat http://msa-gateway AI chatbot (timeout 600s)
location /actuator http://msa-gateway Health checks, back office
location /grafana/ http://127.0.0.1:3001 Grafana (monitoring profile)
  • Upstream: upstream msa-gateway { server 127.0.0.1:8085 max_fails=2 fail_timeout=30s; keepalive 8; }
  • Dev domain dev.minkowskim.com: / β†’ 4000, API/auth/user/chat β†’ 9085 (Gateway).

See docs/nginx-aws-lightsail.md for details.


API Specification

Gateway path to backend mapping (production: application-prod.yml):

Path Service Description
/user, /user/** user-service:8081 User profile and info
/auth, /auth/** auth-service:8084 Login, signup, OAuth2, JWT, verification email
/api/posts, /api/posts/** post-service:8082 Post and comment CRUD
/chat, /chat/** fastapi-ai:8000 AI chatbot (SSE/streaming)
/api/search, /api/search/** search-service:8010 Vector and keyword search

Protected APIs use Authorization: Bearer <JWT> or cookie authToken. For endpoint details, see each service and Gateway config.


Quick Start

Requirements

  • Docker and Docker Compose
  • (Optional) Nginx with config from nginx/

Run

# 1. Environment
cp .env.example .env
# Edit .env: DB passwords, JWT_SECRET, OAuth2, GROQ_API_KEY, etc.

# 2. Start full stack (4GB memory oriented)
docker compose up -d

# 3. (Optional) Monitoring
docker compose --profile monitoring up -d

Service Composition

Service Port Stack Notes
api-gateway 8085 Spring Boot 3, Spring Cloud Gateway JWT, Trace ID, routing
auth-service 8084 Spring Boot, JPA, OAuth2, Redis, Kafka Admin bootstrap
user-service 8081 Spring Boot, JPA, Kafka
post-service 8082 Spring Boot, JPA, WebClient, Kafka
mail-service 8083 Spring Boot, Kafka, Mail Kafka β†’ SMTP
fastapi-ai 8000 FastAPI, LangChain, Groq, Redis Chatbot
search-service 8010 FastAPI, pgvector, Kafka Vector indexing
frontend 3000 Next.js 14
redis 6379 Redis Alpine
msa-kafka 9092 Apache Kafka 3.7 (KRaft)
db-auth / db-user / db-post / db-search 5434/5432/5433/5435 PostgreSQL 15, pgvector

Back Office & Monitoring

  • Back office: Next.js /backoffice; Gateway /actuator for health.
  • Monitoring: docker compose --profile monitoring up -d runs Fluent Bit β†’ Loki β†’ Grafana. Grafana is exposed via Nginx at /grafana/ (proxy to 3001).
  • Kafka UI (optional): docker compose --profile tools up -d exposes Kafka UI on 8080.

Environment Variables

Copy .env.example to .env and set:

Category Variables
DB POSTGRES_USER, POSTGRES_PASSWORD, DB_AUTH_NAME, DB_USER_NAME, DB_POST_NAME, DB_SEARCH_NAME
JWT & Admin JWT_SECRET, ADMIN_USERNAME, ADMIN_PASSWORD
OAuth2 OAUTH2_GOOGLE_*, OAUTH2_KAKAO_*, COOKIE_DOMAIN, FRONTEND_URL
Redis & Kafka SPRING_REDIS_HOST, REDIS_*, SPRING_KAFKA_BOOTSTRAP_SERVERS
SMTP MAIL_USERNAME, MAIL_PASSWORD
AI GROQ_API_KEY
Frontend build NEXT_PUBLIC_API_URL, NEXT_PUBLIC_*_API_URL
Monitoring GRAFANA_ADMIN_PASSWORD

References

Document Description
docs/PROJECT_UPDATES.md Project update and change history
docs/nginx-aws-lightsail.md Nginx layout, routing, SSL, Lightsail
nginx/sites-available/msa-project Production Nginx config
monitoring/docker-compose.monitoring.yml Loki Stack monitoring Compose

Back to top Β· ν•œκΈ€ (kor)

About

MSA Project

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors