feat: 3-System 분리 프로젝트 초기 코드 작성

TK-FB(공장관리+신고)와 M-Project(부적합관리)를 3개 독립 시스템으로
분리하기 위한 전체 코드 구조 작성.
- SSO 인증 서비스 (bcrypt + pbkdf2 이중 해시 지원)
- System 1: 공장관리 (TK-FB 기반, 신고 코드 제거)
- System 2: 신고 (TK-FB에서 workIssue 코드 추출)
- System 3: 부적합관리 (M-Project 기반)
- Gateway 포털 (path-based 라우팅)
- 통합 docker-compose.yml 및 배포 스크립트

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-02-09 14:40:11 +09:00
commit 550633b89d
824 changed files with 1071683 additions and 0 deletions

8
gateway/Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY html/ /usr/share/nginx/html/
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

150
gateway/html/login.html Normal file
View File

@@ -0,0 +1,150 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>로그인 - TK 공장관리</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #f0f2f5;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.login-box {
background: white;
border-radius: 12px;
padding: 40px;
width: 100%;
max-width: 400px;
box-shadow: 0 4px 20px rgba(0,0,0,0.08);
}
.login-box h1 {
text-align: center;
color: #1a56db;
font-size: 22px;
margin-bottom: 6px;
}
.login-box .sub {
text-align: center;
color: #6b7280;
font-size: 13px;
margin-bottom: 28px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
display: block;
font-size: 13px;
font-weight: 500;
color: #374151;
margin-bottom: 6px;
}
.form-group input {
width: 100%;
padding: 10px 14px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 14px;
outline: none;
transition: border-color 0.2s;
}
.form-group input:focus {
border-color: #1a56db;
box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.btn-submit {
width: 100%;
padding: 12px;
background: #1a56db;
color: white;
border: none;
border-radius: 8px;
font-size: 15px;
font-weight: 500;
cursor: pointer;
margin-top: 8px;
}
.btn-submit:hover { background: #1e40af; }
.btn-submit:disabled { background: #93c5fd; cursor: not-allowed; }
.error-msg {
color: #dc2626;
font-size: 13px;
text-align: center;
margin-top: 12px;
display: none;
}
</style>
</head>
<body>
<div class="login-box">
<h1>TK 공장관리 시스템</h1>
<p class="sub">통합 로그인</p>
<form id="loginForm" onsubmit="handleLogin(event)">
<div class="form-group">
<label for="username">사용자명</label>
<input type="text" id="username" name="username" required autofocus autocomplete="username">
</div>
<div class="form-group">
<label for="password">비밀번호</label>
<input type="password" id="password" name="password" required autocomplete="current-password">
</div>
<button type="submit" class="btn-submit" id="submitBtn">로그인</button>
<p class="error-msg" id="errorMsg"></p>
</form>
</div>
<script>
async function handleLogin(e) {
e.preventDefault();
const btn = document.getElementById('submitBtn');
const errEl = document.getElementById('errorMsg');
errEl.style.display = 'none';
btn.disabled = true;
btn.textContent = '로그인 중...';
try {
const res = await fetch('/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
username: document.getElementById('username').value,
password: document.getElementById('password').value
})
});
const data = await res.json();
if (!res.ok || !data.success) {
throw new Error(data.error || '로그인에 실패했습니다');
}
// 토큰과 유저 정보 저장
localStorage.setItem('sso_token', data.access_token);
localStorage.setItem('sso_user', JSON.stringify(data.user));
if (data.refresh_token) {
localStorage.setItem('sso_refresh_token', data.refresh_token);
}
// 포털로 이동
const redirect = new URLSearchParams(location.search).get('redirect');
window.location.href = redirect || '/';
} catch (err) {
errEl.textContent = err.message;
errEl.style.display = '';
} finally {
btn.disabled = false;
btn.textContent = '로그인';
}
}
// 이미 로그인 되어있으면 포털로
if (localStorage.getItem('sso_token')) {
window.location.href = '/';
}
</script>
</body>
</html>

211
gateway/html/portal.html Normal file
View File

@@ -0,0 +1,211 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TK 공장관리 시스템</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #f0f2f5;
min-height: 100vh;
display: flex;
flex-direction: column;
}
.header {
background: #1a56db;
color: white;
padding: 16px 24px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.header h1 { font-size: 20px; font-weight: 600; }
.user-info {
display: flex;
align-items: center;
gap: 12px;
font-size: 14px;
}
.user-info span { opacity: 0.9; }
.btn-logout {
background: rgba(255,255,255,0.2);
color: white;
border: none;
padding: 6px 14px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,0.3); }
.container {
max-width: 900px;
margin: 40px auto;
padding: 0 20px;
flex: 1;
}
.welcome {
text-align: center;
margin-bottom: 36px;
}
.welcome h2 { font-size: 26px; color: #1f2937; margin-bottom: 8px; }
.welcome p { color: #6b7280; font-size: 15px; }
.systems {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 20px;
}
.system-card {
background: white;
border-radius: 12px;
padding: 28px;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
transition: transform 0.2s, box-shadow 0.2s;
cursor: pointer;
text-decoration: none;
color: inherit;
border: 2px solid transparent;
}
.system-card:hover {
transform: translateY(-4px);
box-shadow: 0 8px 25px rgba(0,0,0,0.12);
}
.system-card.s1 { border-top: 4px solid #1a56db; }
.system-card.s2 { border-top: 4px solid #dc2626; }
.system-card.s3 { border-top: 4px solid #059669; }
.system-icon { font-size: 36px; margin-bottom: 14px; }
.system-card h3 { font-size: 18px; color: #1f2937; margin-bottom: 6px; }
.system-card p { color: #6b7280; font-size: 13px; line-height: 1.5; }
.system-card .badge {
display: inline-block;
margin-top: 12px;
padding: 3px 10px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
}
.s1 .badge { background: #dbeafe; color: #1d4ed8; }
.s2 .badge { background: #fee2e2; color: #dc2626; }
.s3 .badge { background: #d1fae5; color: #059669; }
.footer {
text-align: center;
padding: 20px;
color: #9ca3af;
font-size: 12px;
}
.login-prompt {
text-align: center;
padding: 60px 20px;
}
.login-prompt h2 { margin-bottom: 16px; color: #1f2937; }
.btn-login {
display: inline-block;
background: #1a56db;
color: white;
padding: 12px 32px;
border-radius: 8px;
text-decoration: none;
font-size: 15px;
font-weight: 500;
}
.btn-login:hover { background: #1e40af; }
.no-access {
opacity: 0.5;
pointer-events: none;
}
</style>
</head>
<body>
<div class="header">
<h1>TK 공장관리 시스템</h1>
<div class="user-info" id="userInfo" style="display:none">
<span id="userName"></span>
<span id="userRole"></span>
<button class="btn-logout" onclick="logout()">로그아웃</button>
</div>
</div>
<div class="container">
<!-- 로그인 전 -->
<div class="login-prompt" id="loginPrompt">
<h2>시스템에 접속하려면 로그인하세요</h2>
<a href="/login" class="btn-login">로그인</a>
</div>
<!-- 로그인 후 -->
<div id="dashboard" style="display:none">
<div class="welcome">
<h2 id="welcomeText">환영합니다</h2>
<p>사용할 시스템을 선택하세요</p>
</div>
<div class="systems">
<a href="/factory/" class="system-card s1" id="card-s1">
<div class="system-icon">&#127981;</div>
<h3>공장관리</h3>
<p>작업보고, 근태관리, TBM, 순회점검, 장비관리 등 현장 운영 전반</p>
<span class="badge">System 1</span>
</a>
<a href="/report/" class="system-card s2" id="card-s2">
<div class="system-icon">&#128680;</div>
<h3>신고 시스템</h3>
<p>안전/부적합 이슈 신고, 처리현황 추적, 부적합 자동 연동</p>
<span class="badge">System 2</span>
</a>
<a href="/nc/" class="system-card s3" id="card-s3">
<div class="system-icon">&#128203;</div>
<h3>부적합 관리</h3>
<p>부적합 이슈 접수, 처리, 리포트 생성, 프로젝트별 현황 관리</p>
<span class="badge">System 3</span>
</a>
</div>
</div>
</div>
<div class="footer">TK Factory Services v1.0</div>
<script src="/shared/nav-header.js"></script>
<script>
const TOKEN_KEY = 'sso_token';
const USER_KEY = 'sso_user';
function init() {
const token = localStorage.getItem(TOKEN_KEY);
const user = JSON.parse(localStorage.getItem(USER_KEY) || 'null');
if (token && user) {
showDashboard(user);
} else {
document.getElementById('loginPrompt').style.display = '';
document.getElementById('dashboard').style.display = 'none';
}
}
function showDashboard(user) {
document.getElementById('loginPrompt').style.display = 'none';
document.getElementById('dashboard').style.display = '';
document.getElementById('userInfo').style.display = 'flex';
document.getElementById('userName').textContent = user.name || user.username;
document.getElementById('userRole').textContent = '(' + (user.role || '') + ')';
document.getElementById('welcomeText').textContent =
(user.name || user.username) + '님, 환영합니다';
// 접근 권한에 따라 카드 비활성화
const access = user.system_access || {};
if (access.system1 === false) document.getElementById('card-s1').classList.add('no-access');
if (access.system2 === false) document.getElementById('card-s2').classList.add('no-access');
if (access.system3 === false) document.getElementById('card-s3').classList.add('no-access');
}
function logout() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
fetch('/auth/logout', { method: 'POST' }).catch(() => {});
location.reload();
}
init();
</script>
</body>
</html>

View File

@@ -0,0 +1,76 @@
/**
* 공유 네비게이션 헤더
*
* 각 시스템 페이지에서 import하여 통합 포털 네비게이션을 제공
* <script src="/shared/nav-header.js"></script>
*/
(function() {
const TOKEN_KEY = 'sso_token';
const USER_KEY = 'sso_user';
/**
* SSO 토큰 가져오기
*/
window.SSOAuth = {
getToken: function() {
return localStorage.getItem(TOKEN_KEY);
},
getUser: function() {
try {
return JSON.parse(localStorage.getItem(USER_KEY));
} catch {
return null;
}
},
isLoggedIn: function() {
return !!this.getToken();
},
logout: function() {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);
localStorage.removeItem('sso_refresh_token');
window.location.href = '/login';
},
/**
* 토큰을 Authorization 헤더에 포함한 fetch wrapper
*/
fetch: function(url, options) {
options = options || {};
options.headers = options.headers || {};
const token = this.getToken();
if (token) {
options.headers['Authorization'] = 'Bearer ' + token;
}
return fetch(url, options);
},
/**
* 토큰 유효성 확인 (SSO 서비스 호출)
*/
validate: async function() {
const token = this.getToken();
if (!token) return false;
try {
const res = await fetch('/auth/validate', {
headers: { 'Authorization': 'Bearer ' + token }
});
return res.ok;
} catch {
return false;
}
},
/**
* 로그인 안 되어있으면 로그인 페이지로 리다이렉트
*/
requireLogin: function() {
if (!this.isLoggedIn()) {
window.location.href = '/login?redirect=' + encodeURIComponent(window.location.pathname);
}
}
};
})();

96
gateway/nginx.conf Normal file
View File

@@ -0,0 +1,96 @@
server {
listen 80;
server_name _;
client_max_body_size 50M;
# ===== 포털/SSO 페이지 =====
root /usr/share/nginx/html;
location = / {
try_files /portal.html =404;
}
location = /login {
try_files /login.html =404;
}
# 공유 JS/CSS
location /shared/ {
alias /usr/share/nginx/html/shared/;
}
# ===== SSO Auth API =====
location /auth/ {
proxy_pass http://sso-auth:3000/api/auth/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ===== System 1: 공장관리 =====
location /factory/ {
proxy_pass http://system1-web:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /factory/api/ {
proxy_pass http://system1-api:3005/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /factory/fastapi/ {
proxy_pass http://system1-fastapi:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ===== System 2: 신고 =====
location /report/ {
proxy_pass http://system2-web:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /report/api/ {
proxy_pass http://system2-api:3005/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ===== System 3: 부적합관리 =====
location /nc/ {
proxy_pass http://system3-web:80/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /nc/api/ {
proxy_pass http://system3-api:8000/api/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# ===== Health Check =====
location /health {
return 200 '{"status":"ok","service":"gateway"}';
add_header Content-Type application/json;
}
}