# insideup/contest-7-be architecture

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

- Interactive diagram: https://gitdiagram.com/insideup/contest-7-be
- Repository: https://github.com/insideup/contest-7-be

## Overview

InsideUp is a FastAPI backend for user accounts, diaries, community posts and reactions, and emotion-based character responses. Requests enter through the registered v1 routers; account and community actions delegate to CRUD operations backed by SQLAlchemy, while authenticated routes use JWT-based user lookup. Emotion routes retrieve a user’s latest emotion from a separate chatbot service and map it to a character asset path. The README provides only a directory listing, so coverage of major product areas follows the source index; unsampled details and relationships are omitted.

Main entry points: [`app/core/database.py`](https://github.com/insideup/contest-7-be/blob/main/app/core/database.py) (SQLAlchemy session), [`app/crud/community_crud.py`](https://github.com/insideup/contest-7-be/blob/main/app/crud/community_crud.py) (Community operations), [`main.py`](https://github.com/insideup/contest-7-be/blob/main/main.py) (FastAPI app), [`app/api/v1/character_emotion.py`](https://github.com/insideup/contest-7-be/blob/main/app/api/v1/character_emotion.py) (Emotion routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API routes"]
  node_app["FastAPI app<br/>[main.py]"]
  node_user_api["User routes<br/>[user.py]"]
  node_diary_api["Diary routes<br/>[diary.py]"]
  node_community_api["Community routes<br/>[community.py]"]
  node_emotion_api["Emotion routes"]
end

subgraph group_domain["Product workflows"]
  node_user_crud["Account operations<br/>[user_crud.py]"]
  node_diary_crud["Diary operations<br/>[diary_crud.py]"]
  node_community_crud["Community operations<br/>[community_crud.py]"]
  node_character_map["Character mapping"]
  node_user_schema["User schemas<br/>[user_schema.py]"]
  node_diary_schema["Diary schemas<br/>[diary_schema.py]"]
  node_post_schema["Post schemas<br/>[post_schema.py]"]
  node_emotion_schema["Emotion response schema"]
end

subgraph group_persistence["Persistence"]
  node_database["SQLAlchemy session<br/>[database.py]"]
  node_users[("User records<br/>[user_model.py]")]
  node_diaries[("Diary records<br/>[diary_model.py]")]
  node_posts[("Post records<br/>[post_model.py]")]
  node_comments[("Comment records<br/>[comment_model.py]")]
  node_other_models[("Reaction and emotion models")]
end

subgraph group_identity["Identity and configuration"]
  node_db_config["Database configuration<br/>[config.py]"]
  node_auth["JWT user service<br/>[user.py]"]
end

node_client(("API client"))
node_chatbot["Chatbot emotion API"]
node_sql_store[("SQL database")]

node_client -->|"sends requests"| node_app
node_app -->|"registers routes"| node_user_api
node_app -->|"registers routes"| node_diary_api
node_app -->|"registers routes"| node_community_api
node_app -->|"registers routes"| node_emotion_api
node_user_api -->|"calls"| node_user_crud
node_diary_api -->|"calls"| node_diary_crud
node_community_api -->|"calls"| node_community_crud
node_user_api -->|"validates with"| node_user_schema
node_diary_api -->|"uses"| node_diary_schema
node_community_api -->|"uses"| node_post_schema
node_emotion_api -->|"returns"| node_emotion_schema
node_emotion_api -->|"authenticates via"| node_auth
node_emotion_api -->|"fetches latest emotion"| node_chatbot
node_emotion_api -->|"maps emotion"| node_character_map
node_user_api -->|"uses token service"| node_auth
node_user_crud -->|"creates and updates"| node_users
node_diary_crud -->|"queries and writes"| node_diaries
node_community_crud -->|"queries and writes"| node_posts
node_community_crud -->|"queries and writes"| node_comments
node_community_crud -->|"counts reactions"| node_other_models
node_community_crud -->|"ensures guest user"| node_users
node_auth -->|"loads user"| node_users
node_user_crud -->|"accepts payload"| node_user_schema
node_diary_crud -->|"uses payload"| node_diary_schema
node_community_crud -->|"accepts payload"| node_post_schema
node_database -->|"reads connection settings"| node_db_config
node_database -->|"connects to"| node_sql_store
node_users -->|"declares table on"| node_database
node_diaries -->|"declares table on"| node_database
node_posts -->|"declares table on"| node_database
node_comments -->|"declares table on"| node_database
node_other_models -.->|"declares tables on"| node_database

click node_app "https://github.com/insideup/contest-7-be/blob/main/main.py"
click node_user_api "https://github.com/insideup/contest-7-be/blob/main/app/api/v1/user.py"
click node_diary_api "https://github.com/insideup/contest-7-be/blob/main/app/api/v1/diary.py"
click node_community_api "https://github.com/insideup/contest-7-be/blob/main/app/api/v1/community.py"
click node_emotion_api "https://github.com/insideup/contest-7-be/blob/main/app/api/v1/character_emotion.py"
click node_user_crud "https://github.com/insideup/contest-7-be/blob/main/app/crud/user_crud.py"
click node_diary_crud "https://github.com/insideup/contest-7-be/blob/main/app/crud/diary_crud.py"
click node_community_crud "https://github.com/insideup/contest-7-be/blob/main/app/crud/community_crud.py"
click node_character_map "https://github.com/insideup/contest-7-be/blob/main/app/services/character_services.py"
click node_user_schema "https://github.com/insideup/contest-7-be/blob/main/app/schemas/user_schema.py"
click node_diary_schema "https://github.com/insideup/contest-7-be/blob/main/app/schemas/diary_schema.py"
click node_post_schema "https://github.com/insideup/contest-7-be/blob/main/app/schemas/post_schema.py"
click node_emotion_schema "https://github.com/insideup/contest-7-be/blob/main/app/schemas/character_emotion_schema.py"
click node_database "https://github.com/insideup/contest-7-be/blob/main/app/core/database.py"
click node_users "https://github.com/insideup/contest-7-be/blob/main/app/models/user_model.py"
click node_diaries "https://github.com/insideup/contest-7-be/blob/main/app/models/diary_model.py"
click node_posts "https://github.com/insideup/contest-7-be/blob/main/app/models/post_model.py"
click node_comments "https://github.com/insideup/contest-7-be/blob/main/app/models/comment_model.py"
click node_other_models "https://github.com/insideup/contest-7-be/tree/main/app/models"
click node_db_config "https://github.com/insideup/contest-7-be/blob/main/app/core/config.py"
click node_auth "https://github.com/insideup/contest-7-be/blob/main/app/services/user.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_user_api,node_diary_api,node_community_api,node_emotion_api,node_client toneBlue
class node_user_crud,node_diary_crud,node_community_crud,node_character_map,node_user_schema,node_diary_schema,node_post_schema,node_emotion_schema,node_sql_store toneAmber
class node_database,node_users,node_diaries,node_posts,node_comments,node_other_models,node_chatbot toneMint
class node_db_config,node_auth toneRose
```

## Components

### API routes

- [FastAPI app](https://github.com/insideup/contest-7-be/blob/main/main.py): `main.py`
- [User routes](https://github.com/insideup/contest-7-be/blob/main/app/api/v1/user.py): `app/api/v1/user.py`
- [Diary routes](https://github.com/insideup/contest-7-be/blob/main/app/api/v1/diary.py): `app/api/v1/diary.py`
- [Community routes](https://github.com/insideup/contest-7-be/blob/main/app/api/v1/community.py): `app/api/v1/community.py`
- [Emotion routes](https://github.com/insideup/contest-7-be/blob/main/app/api/v1/character_emotion.py): `app/api/v1/character_emotion.py`

### Product workflows

- [Account operations](https://github.com/insideup/contest-7-be/blob/main/app/crud/user_crud.py): `app/crud/user_crud.py`
- [Diary operations](https://github.com/insideup/contest-7-be/blob/main/app/crud/diary_crud.py): `app/crud/diary_crud.py`
- [Community operations](https://github.com/insideup/contest-7-be/blob/main/app/crud/community_crud.py): `app/crud/community_crud.py`
- [Character mapping](https://github.com/insideup/contest-7-be/blob/main/app/services/character_services.py): `app/services/character_services.py`
- [User schemas](https://github.com/insideup/contest-7-be/blob/main/app/schemas/user_schema.py): `app/schemas/user_schema.py`
- [Diary schemas](https://github.com/insideup/contest-7-be/blob/main/app/schemas/diary_schema.py): `app/schemas/diary_schema.py`
- [Post schemas](https://github.com/insideup/contest-7-be/blob/main/app/schemas/post_schema.py): `app/schemas/post_schema.py`
- [Emotion response schema](https://github.com/insideup/contest-7-be/blob/main/app/schemas/character_emotion_schema.py): `app/schemas/character_emotion_schema.py`

### Persistence

- [SQLAlchemy session](https://github.com/insideup/contest-7-be/blob/main/app/core/database.py): `app/core/database.py`
- [User records](https://github.com/insideup/contest-7-be/blob/main/app/models/user_model.py): `app/models/user_model.py`
- [Diary records](https://github.com/insideup/contest-7-be/blob/main/app/models/diary_model.py): `app/models/diary_model.py`
- [Post records](https://github.com/insideup/contest-7-be/blob/main/app/models/post_model.py): `app/models/post_model.py`
- [Comment records](https://github.com/insideup/contest-7-be/blob/main/app/models/comment_model.py): `app/models/comment_model.py`
- [Reaction and emotion models](https://github.com/insideup/contest-7-be/tree/main/app/models): `app/models`

### Identity and configuration

- [Database configuration](https://github.com/insideup/contest-7-be/blob/main/app/core/config.py): `app/core/config.py`
- [JWT user service](https://github.com/insideup/contest-7-be/blob/main/app/services/user.py): `app/services/user.py`

### Other components

- **API client**
- **Chatbot emotion API**
- **SQL database**

## Connections

- API client → FastAPI app: sends requests
- FastAPI app → User routes: registers routes (evidence: `main.py`)
- FastAPI app → Diary routes: registers routes (evidence: `main.py`)
- FastAPI app → Community routes: registers routes (evidence: `main.py`)
- FastAPI app → Emotion routes: registers routes (evidence: `main.py`)
- User routes → Account operations: calls (evidence: `app/api/v1/user.py`)
- Diary routes → Diary operations: calls (evidence: `app/api/v1/diary.py`)
- Community routes → Community operations: calls (evidence: `app/api/v1/community.py`)
- User routes → User schemas: validates with (evidence: `app/api/v1/user.py`)
- Diary routes → Diary schemas: uses (evidence: `app/api/v1/diary.py`)
- Community routes → Post schemas: uses (evidence: `app/api/v1/community.py`)
- Emotion routes → Emotion response schema: returns (evidence: `app/api/v1/character_emotion.py`)
- Emotion routes → JWT user service: authenticates via (evidence: `app/api/v1/character_emotion.py`)
- Emotion routes → Chatbot emotion API: fetches latest emotion (evidence: `app/api/v1/character_emotion.py`)
- Emotion routes → Character mapping: maps emotion (evidence: `app/api/v1/character_emotion.py`)
- User routes → JWT user service: uses token service (evidence: `app/api/v1/user.py`)
- Account operations → User records: creates and updates (evidence: `app/crud/user_crud.py`)
- Diary operations → Diary records: queries and writes (evidence: `app/crud/diary_crud.py`)
- Community operations → Post records: queries and writes (evidence: `app/crud/community_crud.py`)
- Community operations → Comment records: queries and writes (evidence: `app/crud/community_crud.py`)
- Community operations → Reaction and emotion models: counts reactions (evidence: `app/crud/community_crud.py`)
- Community operations → User records: ensures guest user (evidence: `app/crud/community_crud.py`)
- JWT user service → User records: loads user (evidence: `app/services/user.py`)
- Account operations → User schemas: accepts payload (evidence: `app/crud/user_crud.py`)
- Diary operations → Diary schemas: uses payload (evidence: `app/crud/diary_crud.py`)
- Community operations → Post schemas: accepts payload (evidence: `app/crud/community_crud.py`)
- SQLAlchemy session → Database configuration: reads connection settings (evidence: `app/core/database.py`)
- SQLAlchemy session → SQL database: connects to (evidence: `app/core/database.py`)
- User records → SQLAlchemy session: declares table on (evidence: `app/models/user_model.py`)
- Diary records → SQLAlchemy session: declares table on (evidence: `app/models/diary_model.py`)
- Post records → SQLAlchemy session: declares table on (evidence: `app/models/post_model.py`)
- Comment records → SQLAlchemy session: declares table on (evidence: `app/models/comment_model.py`)
- Reaction and emotion models → SQLAlchemy session: declares tables on (evidence: `app/models/diary_model.py`)
