# jing-jung/2-jing-jung-community-be architecture

> Architecture diagram of the GitHub repository jing-jung/2-jing-jung-community-be, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jing-jung/2-jing-jung-community-be
- Repository: https://github.com/jing-jung/2-jing-jung-community-be

## Overview

This is a FastAPI backend for an Animal Crossing-themed community, combining account and post APIs, live room chat, restaurant recommendations, and turnip trading. A client request enters the application or a feature router, then reaches business logic and persistence; WebSocket chat also broadcasts through Redis. The source excerpts show these core paths, while CVR analysis and weight optimization are present in the tree but their behavior and wiring are not shown. README-described scaling and observability integrations are preserved where supported, but deployment infrastructure is outside this runtime map.

Main entry points: [`app/main.py`](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/main.py) (FastAPI Application), [`app/services/controllers.py`](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py) (Community Logic), [`app/routers/routes.py`](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/routes.py) (Community Routes), [`app/core/cache.py`](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/cache.py) (Redis Cache)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API Runtime"]
  node_app["FastAPI Application<br/>[main.py]"]
  node_community_api["Community Routes<br/>[routes.py]"]
  node_chat_api["Recommendation API<br/>[chat.py]"]
  node_cvr["CVR Analyzer<br/>[cvr_analyzer.py]"]
  node_weights["Weight Optimizer"]
end

subgraph group_community["Community Features"]
  node_controllers["Community Logic<br/>[controllers.py]"]
  node_models["Community Models<br/>[model.py]"]
  node_sessions["Session &amp; Auth<br/>[controllers.py]"]
  node_posts["Posts &amp; Comments<br/>[controllers.py]"]
  node_turnips["Turnip Market<br/>[controllers.py]"]
end

subgraph group_engagement["Realtime &amp; Discovery"]
  node_websocket["Room Chat<br/>[main.py]"]
  node_recommendations["Restaurant Recommender<br/>[chat.py]"]
end

subgraph group_platform["Platform Services"]
  node_config["Configuration<br/>[config.py]"]
  node_database_manager["Database Manager<br/>[database.py]"]
  node_db_session["DB Session Factory<br/>[db.py]"]
  node_cache["Redis Cache<br/>[cache.py]"]
  node_security["Security Utilities<br/>[security.py]"]
  node_dependencies["API Dependencies<br/>[dependencies.py]"]
  node_logging["Structured Logging<br/>[logging.py]"]
  node_metrics["Prometheus Metrics<br/>[metrics.py]"]
end

node_client(("Community Client"))
node_mysql[("MySQL Database")]
node_redis_service[("Redis Service")]

node_client -->|"sends requests"| node_app
node_app -->|"registers routes"| node_community_api
node_app -->|"registers routes"| node_chat_api
node_community_api -->|"calls"| node_controllers
node_community_api -->|"gets sessions"| node_db_session
node_community_api -->|"reads cache"| node_cache
node_controllers -->|"queries"| node_mysql
node_db_session -->|"opens sessions"| node_mysql
node_models -->|"uses base"| node_db_session
node_controllers -->|"authenticates users"| node_sessions
node_controllers -->|"handles content"| node_posts
node_controllers -->|"handles trades"| node_turnips
node_app -->|"hosts endpoint"| node_websocket
node_websocket -->|"opens sessions"| node_database_manager
node_websocket -->|"checks sessions"| node_cache
node_websocket -->|"publishes messages"| node_redis_service
node_chat_api -->|"gets recommendations"| node_recommendations
node_cache -->|"reads and writes"| node_redis_service
node_app -->|"uses manager"| node_database_manager
node_app -->|"serves metrics"| node_metrics
node_database_manager -->|"loads settings"| node_config
node_cache -->|"loads settings"| node_config
node_security -->|"loads settings"| node_config
node_logging -->|"loads settings"| node_config

click node_app "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/main.py"
click node_community_api "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/routes.py"
click node_chat_api "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/chat.py"
click node_cvr "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/cvr_analyzer.py"
click node_weights "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/optimize_weights.py"
click node_controllers "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py"
click node_models "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/models/model.py"
click node_sessions "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py"
click node_posts "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py"
click node_turnips "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py"
click node_websocket "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/main.py"
click node_recommendations "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/chat.py"
click node_config "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/config.py"
click node_database_manager "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/database.py"
click node_db_session "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/db.py"
click node_cache "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/cache.py"
click node_security "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/security.py"
click node_dependencies "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/dependencies.py"
click node_logging "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/logging.py"
click node_metrics "https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/metrics.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_app,node_community_api,node_chat_api,node_cvr,node_weights,node_client toneBlue
class node_controllers,node_models,node_sessions,node_posts,node_turnips,node_mysql,node_redis_service toneAmber
class node_websocket,node_recommendations toneMint
class node_config,node_database_manager,node_db_session,node_cache,node_security,node_dependencies,node_logging,node_metrics toneRose
```

## Components

### API Runtime

- [FastAPI Application](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/main.py): `app/main.py`
- [Community Routes](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/routes.py): `app/routers/routes.py`
- [Recommendation API](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/chat.py): `app/routers/chat.py`
- [CVR Analyzer](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/cvr_analyzer.py): `app/routers/cvr_analyzer.py`
- [Weight Optimizer](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/optimize_weights.py): `app/routers/optimize_weights.py`

### Community Features

- [Community Logic](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py): `app/services/controllers.py`
- [Community Models](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/models/model.py): `app/models/model.py`
- [Session & Auth](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py): `app/services/controllers.py`
- [Posts & Comments](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py): `app/services/controllers.py`
- [Turnip Market](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/services/controllers.py): `app/services/controllers.py`

### Realtime & Discovery

- [Room Chat](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/main.py): `app/main.py`
- [Restaurant Recommender](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/routers/chat.py): `app/routers/chat.py`

### Platform Services

- [Configuration](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/config.py): `app/core/config.py`
- [Database Manager](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/database.py): `app/core/database.py`
- [DB Session Factory](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/db.py): `app/db.py`
- [Redis Cache](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/cache.py): `app/core/cache.py`
- [Security Utilities](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/security.py): `app/core/security.py`
- [API Dependencies](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/dependencies.py): `app/core/dependencies.py`
- [Structured Logging](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/logging.py): `app/core/logging.py`
- [Prometheus Metrics](https://github.com/jing-jung/2-jing-jung-community-be/blob/main/app/core/metrics.py): `app/core/metrics.py`

### Other components

- **Community Client**
- **MySQL Database**
- **Redis Service**

## Connections

- Community Client → FastAPI Application: sends requests (evidence: `README.md`)
- FastAPI Application → Community Routes: registers routes (evidence: `app/main.py`)
- FastAPI Application → Recommendation API: registers routes (evidence: `app/main.py`)
- Community Routes → Community Logic: calls (evidence: `app/routers/routes.py`)
- Community Routes → DB Session Factory: gets sessions (evidence: `app/routers/routes.py`)
- Community Routes → Redis Cache: reads cache (evidence: `app/routers/routes.py`)
- Community Logic → MySQL Database: queries (evidence: `app/services/controllers.py`)
- DB Session Factory → MySQL Database: opens sessions (evidence: `app/db.py`)
- Community Models → DB Session Factory: uses base (evidence: `app/models/model.py`)
- Community Logic → Session & Auth: authenticates users (evidence: `app/services/controllers.py`)
- Community Logic → Posts & Comments: handles content (evidence: `app/services/controllers.py`)
- Community Logic → Turnip Market: handles trades (evidence: `app/services/controllers.py`)
- FastAPI Application → Room Chat: hosts endpoint (evidence: `app/main.py`)
- Room Chat → Database Manager: opens sessions (evidence: `app/main.py`)
- Room Chat → Redis Cache: checks sessions (evidence: `app/main.py`)
- Room Chat → Redis Service: publishes messages (evidence: `app/main.py`)
- Recommendation API → Restaurant Recommender: gets recommendations (evidence: `app/routers/chat.py`)
- Redis Cache → Redis Service: reads and writes (evidence: `app/core/cache.py`)
- FastAPI Application → Database Manager: uses manager (evidence: `app/main.py`)
- FastAPI Application → Prometheus Metrics: serves metrics (evidence: `app/main.py`)
- Database Manager → Configuration: loads settings (evidence: `app/core/database.py`)
- Redis Cache → Configuration: loads settings (evidence: `app/core/cache.py`)
- Security Utilities → Configuration: loads settings (evidence: `app/core/security.py`)
- Structured Logging → Configuration: loads settings (evidence: `app/core/logging.py`)
