# geek-sogang/career-piggybank architecture

> Architecture diagram of the GitHub repository geek-sogang/career-piggybank, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/geek-sogang/career-piggybank
- Repository: https://github.com/geek-sogang/career-piggybank

## Overview

#### 목적과 실행 진입점
커리어 저금통은 긱워커의 거래·정산 이력에서 소득 구조와 금융 행동을 파악하고, 입금별 예산 배분·세금 준비·예측·상품 연결을 지원하는 AI 생활금융 플랫폼이다. 백엔드는 FastAPI 앱인 `apps/api/app/main.py`로 실행되며, 모바일/웹 데모는 Expo Router의 `apps/mobile/app/_layout.tsx`와 `apps/mobile/app/index.tsx`에서 시작한다.

#### API 계층과 계약 경계
HTTP API는 라우트 계층이 담당하며, 은행 연결·배분·분류·코치·프로필·예측·상품 기능을 별도 엔드포인트로 노출한다. 입력/출력 계약은 Pydantic 스키마로 분리되어 있다.
- `apps/api/app/api/routes/bank.py`
- `apps/api/app/api/routes/allocations.py`
- `apps/api/app/schemas/allocation.py`

API는 오케스트레이션과 엔진을 호출할 뿐, 금융 계산 및 AI 판단의 직접 구현 위치가 아니다.

#### 사실·프로필 기반 금융 의사결정
원장/행동 데이터에서 FactSheet를 만들고 단일 사용자 프로필에 합성한 뒤, 소득 스트림·지출 성향·개인화를 계산한다. 이 프로필은 AI와 결정론 엔진이 공유하는 SSOT 경계다.
- `apps/api/app/engines/facts.py`
- `apps/api/app/profile/user_profile.py`
- `apps/api/app/profile/personalization_v2.py`

소득은 플랫폼 정산, 반복 발주처, 착수금·잔금 등의 스트림으로 분해하고 예측은 단일 날짜 대신 확률 구간을 다룬다.
- `apps/api/app/engines/income_streams.py`
- `apps/api/app/engines/forecast.py`

#### 결정론 금융 엔진과 안전 순서
금액 계산은 AI가 아니라 엔진이 수행한다. 입금 배분은 세금→경비→생활비→안전자금→목표자금의 정책 순서를 적용하며, 세금 봉투·배분 제안·페이싱 및 상품 적합성 veto를 결정론적으로 처리한다.
- `apps/api/app/engines/allocation_policy.py`
- `apps/api/app/engines/allocator.py`
- `apps/api/app/engines/tax_envelope.py`

상품 추천은 적합하지 않은 후보를 먼저 제외한 후에만 AI 판단으로 넘긴다.
- `apps/api/app/engines/product_match.py`

#### 로컬 LLM 에이전트와 오케스트레이션
Ollama 기반 EXAONE 모델을 외부 API 없이 사용한다. 모델 설정과 호출 경계는 core에 있고, 에이전트는 의도 라우팅·분류·명확화·봉투 추천·페이싱·코치 등 판단 역할을 분리한다.
- `apps/api/app/core/config.py`
- `apps/api/app/core/llm.py`
- `apps/api/app/agents/registry.py`

라이브 코치와 은행 흐름은 여러 에이전트/엔진을 조합하고, 애매하거나 위험한 판단은 질문·폴백·사용자 확인으로 전환한다.
- `apps/api/app/orchestration/coach_live.py`
- `apps/api/app/orchestration/bank_flow.py`

#### 승인·영속성·클라이언트 흐름
실제 잔액 이동이나 금융 실행은 제안 단계에서 발생하지 않으며 사용자 승인 뒤에만 반영된다. SQLite 저장소는 거래, 봉투 잔액, 배분 제안, 결정, 프로필 스냅샷 및 이벤트 로그의 영속 경계다.
- `apps/api/app/store/db.py`
- `apps/api/app/store/seed.py`

React Native 클라이언트는 API 어댑터를 통해 백엔드에 연결하고, 홈·커리어 동기화·봉투 제안·세금·상품·채팅 화면으로 결과를 표현한다.
- `apps/mobile/src/lib/api.ts`
- `apps/mobile/src/screens/Home.tsx`
- `apps/mobile/src/screens/EnvelopeSuggest.tsx`

Main entry points: [`apps/api/app/profile/user_profile.py`](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/profile/user_profile.py) (User profile SSOT), [`apps/api/app/api/routes/bank.py`](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/api/routes/bank.py) (Bank & allocation routes), [`apps/api/app/engines/allocator.py`](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/allocator.py) (Deposit allocator), [`apps/api/app/store/db.py`](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/store/db.py) (SQLite store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile demo"]
  node_mobile_entry["Expo Router entry<br/>React Native entry<br/>[_layout.tsx]"]
  node_mobile_screens["Finance screens<br/>React Native screens<br/>[Home.tsx]"]
  node_mobile_api["API adapter<br/>mobile client<br/>[api.ts]"]
end

subgraph group_api["FastAPI backend"]
  node_api_app["FastAPI app<br/>API entry<br/>[main.py]"]
  node_api_routes["Bank &amp; allocation routes<br/>HTTP routes<br/>[bank.py]"]
  node_allocation_contract["Allocation contracts<br/>Pydantic schemas<br/>[allocation.py]"]
  node_bank_flow["Bank flow<br/>orchestration<br/>[bank_flow.py]"]
  node_coach_live["Live coach<br/>orchestration<br/>[coach_live.py]"]
end

subgraph group_decision["Financial decisioning"]
  node_facts["FactSheet builder<br/>financial facts<br/>[facts.py]"]
  node_profile["User profile SSOT<br/>profile aggregate<br/>[user_profile.py]"]
  node_personalization["Personalization<br/>profile analysis"]
  node_income_streams["Income streams<br/>income analysis<br/>[income_streams.py]"]
  node_forecast["Probabilistic forecast<br/>forecast engine<br/>[forecast.py]"]
  node_allocation_policy["Allocation policy<br/>policy engine"]
  node_allocator["Deposit allocator<br/>allocation engine<br/>[allocator.py]"]
  node_tax_envelope["Tax envelope<br/>tax engine<br/>[tax_envelope.py]"]
  node_product_match["Product suitability veto<br/>product engine<br/>[product_match.py]"]
end

subgraph group_ai["Local AI"]
  node_agent_registry["Agent registry<br/>agent routing<br/>[registry.py]"]
  node_local_llm{{"Ollama EXAONE<br/>local LLM boundary<br/>[llm.py]"}}
end

subgraph group_data["Approval &amp; storage"]
  node_sqlite_store[("SQLite store<br/>persistence<br/>[db.py]")]
  node_user_approval(("User approval<br/>execution gate"))
end

node_mobile_entry -->|"renders"| node_mobile_screens
node_mobile_screens -->|"requests"| node_mobile_api
node_mobile_api -->|"HTTP"| node_api_app
node_api_app -->|"mounts"| node_api_routes
node_api_routes -->|"validates"| node_allocation_contract
node_api_routes -->|"orchestrates"| node_bank_flow
node_api_routes -->|"starts coaching"| node_coach_live
node_bank_flow -->|"builds"| node_facts
node_facts -->|"composes"| node_profile
node_profile -->|"drives"| node_personalization
node_profile -->|"analyzes"| node_income_streams
node_income_streams -->|"forecasts"| node_forecast
node_profile -->|"input"| node_allocator
node_allocation_policy -->|"policy order"| node_allocator
node_tax_envelope -->|"tax reserve"| node_allocator
node_allocator -->|"proposes allocation"| node_user_approval
node_product_match -->|"eligible candidates only"| node_agent_registry
node_coach_live -->|"delegates judgment"| node_agent_registry
node_agent_registry -->|"invokes"| node_local_llm
node_bank_flow -->|"reads and records"| node_sqlite_store
node_profile -->|"profile snapshots"| node_sqlite_store
node_user_approval -->|"persists approved decision"| node_sqlite_store
node_sqlite_store -->|"ledger and behavior"| node_facts

click node_mobile_entry "https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/app/_layout.tsx"
click node_mobile_screens "https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/src/screens/Home.tsx"
click node_mobile_api "https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/src/lib/api.ts"
click node_api_app "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/main.py"
click node_api_routes "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/api/routes/bank.py"
click node_allocation_contract "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/schemas/allocation.py"
click node_bank_flow "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/orchestration/bank_flow.py"
click node_coach_live "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/orchestration/coach_live.py"
click node_facts "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/facts.py"
click node_profile "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/profile/user_profile.py"
click node_personalization "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/profile/personalization_v2.py"
click node_income_streams "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/income_streams.py"
click node_forecast "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/forecast.py"
click node_allocation_policy "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/allocation_policy.py"
click node_allocator "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/allocator.py"
click node_tax_envelope "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/tax_envelope.py"
click node_product_match "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/product_match.py"
click node_agent_registry "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/agents/registry.py"
click node_local_llm "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/core/llm.py"
click node_sqlite_store "https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/store/db.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mobile_entry,node_mobile_screens,node_mobile_api toneBlue
class node_api_app,node_api_routes,node_allocation_contract,node_bank_flow,node_coach_live toneAmber
class node_facts,node_profile,node_personalization,node_income_streams,node_forecast,node_allocation_policy,node_allocator,node_tax_envelope,node_product_match toneMint
class node_agent_registry,node_local_llm toneRose
class node_sqlite_store,node_user_approval toneIndigo
```

## Components

### Mobile demo

- [Expo Router entry](https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/app/_layout.tsx): React Native entry · `apps/mobile/app/_layout.tsx`
- [Finance screens](https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/src/screens/Home.tsx): React Native screens · Home and envelope suggestion views present outcomes. · `apps/mobile/src/screens/Home.tsx`
- [API adapter](https://github.com/geek-sogang/career-piggybank/blob/main/apps/mobile/src/lib/api.ts): mobile client · `apps/mobile/src/lib/api.ts`

### FastAPI backend

- [FastAPI app](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/main.py): API entry · `apps/api/app/main.py`
- [Bank & allocation routes](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/api/routes/bank.py): HTTP routes · Exposes banking and allocation endpoints. · `apps/api/app/api/routes/bank.py`
- [Allocation contracts](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/schemas/allocation.py): Pydantic schemas · `apps/api/app/schemas/allocation.py`
- [Bank flow](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/orchestration/bank_flow.py): orchestration · Combines agents and engines for bank workflows. · `apps/api/app/orchestration/bank_flow.py`
- [Live coach](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/orchestration/coach_live.py): orchestration · Falls back to questions or confirmation for uncertain decisions. · `apps/api/app/orchestration/coach_live.py`

### Financial decisioning

- [FactSheet builder](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/facts.py): financial facts · Derives facts from ledger and behavior data. · `apps/api/app/engines/facts.py`
- [User profile SSOT](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/profile/user_profile.py): profile aggregate · Shared profile boundary for AI and deterministic engines. · `apps/api/app/profile/user_profile.py`
- [Personalization](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/profile/personalization_v2.py): profile analysis · `apps/api/app/profile/personalization_v2.py`
- [Income streams](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/income_streams.py): income analysis · Separates platform, recurring-client, and milestone income. · `apps/api/app/engines/income_streams.py`
- [Probabilistic forecast](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/forecast.py): forecast engine · Models income timing as probability ranges. · `apps/api/app/engines/forecast.py`
- [Allocation policy](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/allocation_policy.py): policy engine · Applies tax, expenses, living, safety, then goals order. · `apps/api/app/engines/allocation_policy.py`
- [Deposit allocator](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/allocator.py): allocation engine · `apps/api/app/engines/allocator.py`
- [Tax envelope](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/tax_envelope.py): tax engine · `apps/api/app/engines/tax_envelope.py`
- [Product suitability veto](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/engines/product_match.py): product engine · Rejects unsuitable products before AI evaluation. · `apps/api/app/engines/product_match.py`

### Local AI

- [Agent registry](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/agents/registry.py): agent routing · Separates intent, classification, clarification, pacing, and coach roles. · `apps/api/app/agents/registry.py`
- [Ollama EXAONE](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/core/llm.py): local LLM boundary · Uses a local model without an external API. · `apps/api/app/core/llm.py`

### Approval & storage

- [SQLite store](https://github.com/geek-sogang/career-piggybank/blob/main/apps/api/app/store/db.py): persistence · Persists transactions, envelopes, proposals, decisions, profiles, and events. · `apps/api/app/store/db.py`
- **User approval**: execution gate · Only approved proposals can change balances or execute actions.

## Connections

- Expo Router entry → Finance screens: renders
- Finance screens → API adapter: requests
- API adapter → FastAPI app: HTTP
- FastAPI app → Bank & allocation routes: mounts
- Bank & allocation routes → Allocation contracts: validates
- Bank & allocation routes → Bank flow: orchestrates
- Bank & allocation routes → Live coach: starts coaching
- Bank flow → FactSheet builder: builds
- FactSheet builder → User profile SSOT: composes
- User profile SSOT → Personalization: drives
- User profile SSOT → Income streams: analyzes
- Income streams → Probabilistic forecast: forecasts
- User profile SSOT → Deposit allocator: input
- Allocation policy → Deposit allocator: policy order
- Tax envelope → Deposit allocator: tax reserve
- Deposit allocator → User approval: proposes allocation
- Product suitability veto → Agent registry: eligible candidates only
- Live coach → Agent registry: delegates judgment
- Agent registry → Ollama EXAONE: invokes
- Bank flow → SQLite store: reads and records
- User profile SSOT → SQLite store: profile snapshots
- User approval → SQLite store: persists approved decision
- SQLite store → FactSheet builder: ledger and behavior
