# project-rewire/app architecture

> Architecture diagram of the GitHub repository project-rewire/app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/project-rewire/app
- Repository: https://github.com/project-rewire/app

## Overview

Rewire is a mobile addiction-recovery app combining onboarding and assessment, recovery tasks, an AI chat, community features, and emergency support. The user enters through the app navigation, authenticates, and can move into recovery activities; the backend includes profile, questionnaire, recommendation, and chat domains. Sampled code confirms authentication requests, chat persistence, and recommendation generation from AI profiles. Several feature branches are documented or visible in the tree but their detailed runtime wiring was not sampled, so those links are omitted or marked unverified.

Main entry points: [`frontend/App.js`](https://github.com/project-rewire/app/blob/main/frontend/App.js) (App navigation), [`frontend/app/hooks/jwt-auth-service.js`](https://github.com/project-rewire/app/blob/main/frontend/app/hooks/jwt-auth-service.js) (Auth provider), [`backend/rewire/recommendations/service.py`](https://github.com/project-rewire/app/blob/main/backend/rewire/recommendations/service.py) (Recommendation engine), [`frontend/app/screens/RebotChatInterface.js`](https://github.com/project-rewire/app/blob/main/frontend/app/screens/RebotChatInterface.js) (Rebot chat)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile experience"]
  node_app["App navigation<br/>[App.js]"]
  node_auth_config["API configuration<br/>[app.settings.ts]"]
  node_chat_store[("Chat history store<br/>[app.db.service.ts]")]
end

subgraph group_identity["Identity and assessment"]
  node_auth["Auth provider"]
  node_login["Login and signup<br/>[Login.js]"]
  node_questionnaire_ui["Questionnaire<br/>[Questionnaire.js]"]
  node_questionnaire_service["Questionnaire client"]
  node_profile_ui["User profile<br/>[Profile.js]"]
end

subgraph group_recovery["Recovery support"]
  node_tasks_ui["Recovery tasks<br/>[Tasks.js]"]
  node_recommendation_api["Task recommendations<br/>[views.py]"]
  node_recommendation_service["Recommendation engine<br/>[service.py]"]
  node_chat_ui["Rebot chat"]
  node_chat_socket["Chat WebSocket client<br/>[rebot-service.js]"]
  node_emergency["Emergency support<br/>[UrgeShield.js]"]
end

subgraph group_backend["Backend services"]
  node_questionnaire_api["Questionnaire API<br/>[views.py]"]
  node_profile_api["AI profile API<br/>[views.py]"]
  node_profile_data[("AI profile data<br/>[models.py]")]
  node_chat_route["Chat routing<br/>[routing.py]"]
  node_chat_consumer["Chat consumer<br/>[consumers.py]"]
  node_core_data[("Core recovery data<br/>[models.py]")]
end

subgraph group_community["Community"]
  node_community_ui["Community screens<br/>[Community.js]"]
  node_community_posts["Community posts"]
end

node_person(("App user"))
node_openai{{"OpenAI service"}}

node_person -->|"opens"| node_app
node_app -->|"routes to"| node_login
node_app -->|"provides auth"| node_auth
node_login -.->|"uses auth"| node_auth
node_auth -->|"reads endpoints"| node_auth_config
node_auth -.->|"authenticates with"| node_person
node_app -.->|"routes to"| node_questionnaire_ui
node_questionnaire_ui -.->|"uses"| node_questionnaire_service
node_questionnaire_service -.->|"submits assessment"| node_questionnaire_api
node_questionnaire_api -.->|"records profile"| node_profile_api
node_app -->|"routes to"| node_tasks_ui
node_tasks_ui -.->|"requests tasks"| node_recommendation_api
node_recommendation_api -.->|"generates tasks"| node_recommendation_service
node_recommendation_service -->|"reads profile"| node_profile_data
node_recommendation_service -->|"requests recommendations"| node_openai
node_app -->|"routes to"| node_chat_ui
node_chat_ui -->|"loads and saves"| node_chat_store
node_chat_ui -.->|"uses chat endpoint"| node_auth_config
node_chat_socket -->|"reads socket URL"| node_auth_config
node_chat_route -->|"routes to"| node_chat_consumer
node_chat_socket -.->|"exchanges messages"| node_chat_route
node_app -->|"routes to"| node_community_ui
node_community_ui -.->|"opens posts"| node_community_posts
node_app -.->|"routes to"| node_emergency
node_app -->|"routes to"| node_profile_ui
node_profile_api -.->|"persists profile"| node_profile_data

click node_app "https://github.com/project-rewire/app/blob/main/frontend/App.js"
click node_auth "https://github.com/project-rewire/app/blob/main/frontend/app/hooks/jwt-auth-service.js"
click node_login "https://github.com/project-rewire/app/blob/main/frontend/app/screens/Login.js"
click node_auth_config "https://github.com/project-rewire/app/blob/main/frontend/app/app.settings.ts"
click node_questionnaire_ui "https://github.com/project-rewire/app/blob/main/frontend/app/screens/Questionnaire.js"
click node_questionnaire_service "https://github.com/project-rewire/app/blob/main/frontend/app/hooks/questionnaire-service.js"
click node_questionnaire_api "https://github.com/project-rewire/app/blob/main/backend/rewire/questionnaire/views.py"
click node_profile_api "https://github.com/project-rewire/app/blob/main/backend/rewire/aiprofile/views.py"
click node_profile_data "https://github.com/project-rewire/app/blob/main/backend/rewire/aiprofile/models.py"
click node_tasks_ui "https://github.com/project-rewire/app/blob/main/frontend/app/screens/tabs/Tasks.js"
click node_recommendation_api "https://github.com/project-rewire/app/blob/main/backend/rewire/recommendations/views.py"
click node_recommendation_service "https://github.com/project-rewire/app/blob/main/backend/rewire/recommendations/service.py"
click node_chat_ui "https://github.com/project-rewire/app/blob/main/frontend/app/screens/RebotChatInterface.js"
click node_chat_store "https://github.com/project-rewire/app/blob/main/frontend/app/app.db.service.ts"
click node_chat_socket "https://github.com/project-rewire/app/blob/main/frontend/app/hooks/rebot-service.js"
click node_chat_route "https://github.com/project-rewire/app/blob/main/backend/rewire/rebot/routing.py"
click node_chat_consumer "https://github.com/project-rewire/app/blob/main/backend/rewire/rebot/consumers.py"
click node_community_ui "https://github.com/project-rewire/app/blob/main/frontend/app/screens/tabs/Community.js"
click node_community_posts "https://github.com/project-rewire/app/blob/main/frontend/app/screens/CommunityPostsScreen.js"
click node_emergency "https://github.com/project-rewire/app/blob/main/frontend/app/screens/UrgeShield.js"
click node_profile_ui "https://github.com/project-rewire/app/blob/main/frontend/app/screens/Profile.js"
click node_core_data "https://github.com/project-rewire/app/blob/main/backend/rewire/core/models.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_auth_config,node_chat_store,node_person toneBlue
class node_auth,node_login,node_questionnaire_ui,node_questionnaire_service,node_profile_ui toneAmber
class node_tasks_ui,node_recommendation_api,node_recommendation_service,node_chat_ui,node_chat_socket,node_emergency toneMint
class node_questionnaire_api,node_profile_api,node_profile_data,node_chat_route,node_chat_consumer,node_core_data toneRose
class node_community_ui,node_community_posts,node_openai toneIndigo
```

## Components

### Mobile experience

- [App navigation](https://github.com/project-rewire/app/blob/main/frontend/App.js): `frontend/App.js`
- [API configuration](https://github.com/project-rewire/app/blob/main/frontend/app/app.settings.ts): `frontend/app/app.settings.ts`
- [Chat history store](https://github.com/project-rewire/app/blob/main/frontend/app/app.db.service.ts): `frontend/app/app.db.service.ts`

### Identity and assessment

- [Auth provider](https://github.com/project-rewire/app/blob/main/frontend/app/hooks/jwt-auth-service.js): `frontend/app/hooks/jwt-auth-service.js`
- [Login and signup](https://github.com/project-rewire/app/blob/main/frontend/app/screens/Login.js): `frontend/app/screens/Login.js`
- [Questionnaire](https://github.com/project-rewire/app/blob/main/frontend/app/screens/Questionnaire.js): `frontend/app/screens/Questionnaire.js`
- [Questionnaire client](https://github.com/project-rewire/app/blob/main/frontend/app/hooks/questionnaire-service.js): `frontend/app/hooks/questionnaire-service.js`
- [User profile](https://github.com/project-rewire/app/blob/main/frontend/app/screens/Profile.js): `frontend/app/screens/Profile.js`

### Recovery support

- [Recovery tasks](https://github.com/project-rewire/app/blob/main/frontend/app/screens/tabs/Tasks.js): `frontend/app/screens/tabs/Tasks.js`
- [Task recommendations](https://github.com/project-rewire/app/blob/main/backend/rewire/recommendations/views.py): `backend/rewire/recommendations/views.py`
- [Recommendation engine](https://github.com/project-rewire/app/blob/main/backend/rewire/recommendations/service.py): `backend/rewire/recommendations/service.py`
- [Rebot chat](https://github.com/project-rewire/app/blob/main/frontend/app/screens/RebotChatInterface.js): `frontend/app/screens/RebotChatInterface.js`
- [Chat WebSocket client](https://github.com/project-rewire/app/blob/main/frontend/app/hooks/rebot-service.js): `frontend/app/hooks/rebot-service.js`
- [Emergency support](https://github.com/project-rewire/app/blob/main/frontend/app/screens/UrgeShield.js): `frontend/app/screens/UrgeShield.js`

### Backend services

- [Questionnaire API](https://github.com/project-rewire/app/blob/main/backend/rewire/questionnaire/views.py): `backend/rewire/questionnaire/views.py`
- [AI profile API](https://github.com/project-rewire/app/blob/main/backend/rewire/aiprofile/views.py): `backend/rewire/aiprofile/views.py`
- [AI profile data](https://github.com/project-rewire/app/blob/main/backend/rewire/aiprofile/models.py): `backend/rewire/aiprofile/models.py`
- [Chat routing](https://github.com/project-rewire/app/blob/main/backend/rewire/rebot/routing.py): `backend/rewire/rebot/routing.py`
- [Chat consumer](https://github.com/project-rewire/app/blob/main/backend/rewire/rebot/consumers.py): `backend/rewire/rebot/consumers.py`
- [Core recovery data](https://github.com/project-rewire/app/blob/main/backend/rewire/core/models.py): `backend/rewire/core/models.py`

### Community

- [Community screens](https://github.com/project-rewire/app/blob/main/frontend/app/screens/tabs/Community.js): `frontend/app/screens/tabs/Community.js`
- [Community posts](https://github.com/project-rewire/app/blob/main/frontend/app/screens/CommunityPostsScreen.js): `frontend/app/screens/CommunityPostsScreen.js`

### Other components

- **App user**
- **OpenAI service**

## Connections

- App user → App navigation: opens (evidence: `frontend/App.js`)
- App navigation → Login and signup: routes to (evidence: `frontend/App.js`)
- App navigation → Auth provider: provides auth (evidence: `frontend/App.js`)
- Login and signup → Auth provider: uses auth
- Auth provider → API configuration: reads endpoints (evidence: `frontend/app/hooks/jwt-auth-service.js`)
- Auth provider → App user: authenticates with
- App navigation → Questionnaire: routes to
- Questionnaire → Questionnaire client: uses
- Questionnaire client → Questionnaire API: submits assessment
- Questionnaire API → AI profile API: records profile
- App navigation → Recovery tasks: routes to (evidence: `frontend/App.js`)
- Recovery tasks → Task recommendations: requests tasks
- Task recommendations → Recommendation engine: generates tasks
- Recommendation engine → AI profile data: reads profile (evidence: `backend/rewire/recommendations/service.py`)
- Recommendation engine → OpenAI service: requests recommendations (evidence: `backend/rewire/recommendations/service.py`)
- App navigation → Rebot chat: routes to (evidence: `frontend/App.js`)
- Rebot chat → Chat history store: loads and saves (evidence: `frontend/app/screens/RebotChatInterface.js`)
- Rebot chat → API configuration: uses chat endpoint (evidence: `frontend/app/screens/RebotChatInterface.js`)
- Chat WebSocket client → API configuration: reads socket URL (evidence: `frontend/app/hooks/rebot-service.js`)
- Chat routing → Chat consumer: routes to (evidence: `backend/rewire/rebot/routing.py`)
- Chat WebSocket client → Chat routing: exchanges messages
- App navigation → Community screens: routes to (evidence: `frontend/App.js`)
- Community screens → Community posts: opens posts
- App navigation → Emergency support: routes to
- App navigation → User profile: routes to (evidence: `frontend/App.js`)
- AI profile API → AI profile data: persists profile
