# myselfanandvp/lexta architecture

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

- Interactive diagram: https://gitdiagram.com/myselfanandvp/lexta
- Repository: https://github.com/myselfanandvp/lexta

## Overview

1. **Overall shape**
   - This is a two-tier full-stack app: a React single-page frontend and a Django backend.
   - The backend is not just REST; it also runs an ASGI stack for WebSockets, which is central to the chat flow.

2. **Frontend boundary**
   - `frontend/` is a Vite-based React app.
   - Its main responsibilities are UI rendering, route protection, REST calls, and maintaining the live chat socket connection.
   - State is split into Redux slices for auth, chat, and theme, so UI state is centralized rather than spread across components.

3. **Frontend page structure**
   - The visible app is organized around two main screens: an auth page and a chat page.
   - Shared UI lives in `components/common` such as navbar, footer, and loader.
   - `Protectedroutes.jsx` indicates access control at the routing layer, meaning authenticated state gates navigation before users reach chat views.

4. **Frontend data flows**
   - REST traffic is handled through `src/api/api.js`.
   - Realtime messaging is handled separately by `src/service/chatSocketManager.js`, which isolates WebSocket lifecycle and message handling from the page components.
   - The chat page therefore consumes two backend channels: HTTP for initial state/history and WebSocket for live updates.

5. **Backend application boundary**
   - `backend/` is a Django project with two domain apps: `accounts` and `chat`.
   - `backend/backend/settings.py`, `urls.py`, `asgi.py`, and `wsgi.py` define the platform-level wiring.
   - The presence of both `asgi.py` and Channels routing shows that the backend is designed to serve both synchronous HTTP and asynchronous socket traffic.

6. **Accounts subsystem**
   - `backend/apps/accounts` owns identity and authentication concerns.
   - It contains custom auth logic, serializers, views, URL routing, and a custom user manager/model setup.
   - The API surface exposed in the README—register, login, refresh, logout—maps to this app and likely feeds JWT-based session handling.

7. **Chat subsystem**
   - `backend/apps/chat` owns room and message domain logic.
   - It includes Django models plus serializers and views for room/message REST endpoints.
   - It also contains `consumers.py`, `routing.py`, and `middleware.py`, which means realtime chat is handled as a separate socket path rather than through the REST views.

8. **Realtime message flow**
   - The typical flow is: client loads room history over HTTP, then opens a WebSocket to `ws://.../ws/chat/<room_id>/`.
   - The socket connection is authenticated using JWT during handshake, via custom middleware in the chat layer.
   - Once connected, messages can be broadcast through the Channels stack to other clients in the same room.

9. **Persistence and shared infrastructure**
   - PostgreSQL is the durable store for users, rooms, and messages.
   - Redis acts as the Channels layer / pub-sub backbone and possibly session/cache support.
   - This makes the system horizontally friendlier for realtime fanout than a pure in-process websocket setup.

10. **Deployment/runtime model**
   - `docker-compose.yml` orchestrates the full stack: frontend, backend, PostgreSQL, and Redis.
   - Separate Dockerfiles for frontend and backend imply isolated build/runtime environments.
   - The README’s port layout shows the frontend served on `5173` and backend on `9000`, with the backend also exposing admin and API endpoints.

11. **Operational and developer boundary**
   - Backend startup and management flow through Django tooling (`manage.py`, migrations, superuser creation, tests).
   - `backend/main.py` and `backend/pyproject.toml` suggest the backend is packaged and managed with modern Python tooling, while `uv.lock` pins dependencies.
   - This repo is therefore structured for containerized local development and repeatable deployment rather than a monolithic ad hoc runtime.

12. **What an architecture diagram should emphasize**
   - Put the browser/client at the top, split into HTTP API calls and WebSocket chat traffic.
   - Show the frontend as a React/Vite SPA with Redux state and a dedicated socket manager.
   - Show the backend as Django/DRF plus Channels, with `accounts` and `chat` as separate domain modules.
   - End the data flows at PostgreSQL for persistence and Redis for realtime coordination.

Main entry points: [`frontend/src/main.jsx`](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/main.jsx) (React SPA), [`frontend/src/store/store.js`](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/store.js) (Redux store), [`backend/backend/settings.py`](https://github.com/myselfanandvp/lexta/blob/main/backend/backend/settings.py) (Django app), [`docker-compose.yml`](https://github.com/myselfanandvp/lexta/blob/main/docker-compose.yml) (Compose stack)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_browser(("Browser<br/>user agent"))
  node_frontend["React SPA<br/>vite app<br/>[main.jsx]"]
  node_auth_page["Auth page<br/>screen<br/>[Authpage.jsx]"]
  node_chat_page["Chat page<br/>screen<br/>[ChatPage.jsx]"]
  node_protected_routes{{"Route guard<br/>routing"}}
  node_store["Redux store<br/>state<br/>[store.js]"]
  node_auth_slice["Auth state<br/>redux slice<br/>[AuthSlice.js]"]
  node_chat_slice["Chat state<br/>redux slice<br/>[ChatSlice.js]"]
  node_theme_slice["Theme state<br/>redux slice<br/>[ThemeSlice.js]"]
  node_api_client["API client<br/>http client<br/>[api.js]"]
  node_socket_mgr["Socket manager<br/>websocket client"]
  node_shared_ui["Shared UI<br/>components<br/>[Navbar.jsx]"]
end

subgraph group_server["Server"]
  node_django_app["Django app<br/>backend platform<br/>[settings.py]"]
  node_backend_urls{{"URL wiring<br/>routing<br/>[urls.py]"}}
  node_asgi_stack["ASGI stack<br/>channels runtime<br/>[asgi.py]"]
  node_accounts[("Accounts<br/>domain app<br/>[models.py]")]
  node_chat[("Chat domain<br/>domain app<br/>[models.py]")]
  node_chat_ws{{"WS routing<br/>channels routes<br/>[routing.py]"}}
  node_chat_consumer["Chat consumer<br/>websocket handler<br/>[consumers.py]"]
  node_jwt_mw["JWT middleware<br/>channels auth<br/>[middleware.py]"]
end

subgraph group_infra["Infra"]
  node_postgres[("PostgreSQL<br/>database")]
  node_redis[("Redis<br/>pubsub/cache")]
  node_compose["Compose stack<br/>orchestration<br/>[docker-compose.yml]"]
  node_dockerfiles["Dockerfiles<br/>build/runtime"]
end

node_browser -->|"uses"| node_frontend
node_frontend -->|"renders"| node_auth_page
node_frontend -->|"renders"| node_chat_page
node_frontend -->|"gates"| node_protected_routes
node_auth_page -->|"reads/writes"| node_store
node_chat_page -->|"reads/writes"| node_store
node_store -->|"contains"| node_auth_slice
node_store -->|"contains"| node_chat_slice
node_store -->|"contains"| node_theme_slice
node_frontend -->|"calls"| node_api_client
node_chat_page -->|"opens"| node_socket_mgr
node_frontend -->|"uses"| node_shared_ui
node_api_client -->|"HTTP"| node_django_app
node_django_app -->|"routes"| node_backend_urls
node_django_app -->|"serves"| node_asgi_stack
node_backend_urls -->|"includes"| node_accounts
node_backend_urls -->|"includes"| node_chat
node_accounts -->|"persists"| node_postgres
node_chat -->|"persists"| node_postgres
node_socket_mgr -->|"WebSocket"| node_asgi_stack
node_asgi_stack -->|"dispatches"| node_chat_ws
node_chat_ws -->|"authenticates"| node_jwt_mw
node_chat_ws -->|"creates"| node_chat_consumer
node_chat_consumer -->|"fanout"| node_redis
node_chat_consumer -->|"reads/writes"| node_postgres
node_compose -->|"runs"| node_frontend
node_compose -->|"runs"| node_django_app
node_compose -->|"runs"| node_postgres
node_compose -->|"runs"| node_redis
node_dockerfiles -->|"builds"| node_frontend
node_dockerfiles -->|"builds"| node_django_app

click node_frontend "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/main.jsx"
click node_auth_page "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/Authpage.jsx"
click node_chat_page "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/ChatPage.jsx"
click node_protected_routes "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/utils/Protectedroutes.jsx"
click node_store "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/store.js"
click node_auth_slice "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/AuthSlice.js"
click node_chat_slice "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/ChatSlice.js"
click node_theme_slice "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/ThemeSlice.js"
click node_api_client "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/api/api.js"
click node_socket_mgr "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/service/chatSocketManager.js"
click node_shared_ui "https://github.com/myselfanandvp/lexta/blob/main/frontend/src/components/common/Navbar.jsx"
click node_django_app "https://github.com/myselfanandvp/lexta/blob/main/backend/backend/settings.py"
click node_backend_urls "https://github.com/myselfanandvp/lexta/blob/main/backend/backend/urls.py"
click node_asgi_stack "https://github.com/myselfanandvp/lexta/blob/main/backend/backend/asgi.py"
click node_accounts "https://github.com/myselfanandvp/lexta/blob/main/backend/apps/accounts/models.py"
click node_chat "https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/models.py"
click node_chat_ws "https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/routing.py"
click node_chat_consumer "https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/consumers.py"
click node_jwt_mw "https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/middleware.py"
click node_compose "https://github.com/myselfanandvp/lexta/blob/main/docker-compose.yml"
click node_dockerfiles "https://github.com/myselfanandvp/lexta/blob/main/Dockerfile.frontend"

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_browser,node_frontend,node_auth_page,node_chat_page,node_protected_routes,node_store,node_auth_slice,node_chat_slice,node_theme_slice,node_api_client,node_socket_mgr,node_shared_ui toneBlue
class node_django_app,node_backend_urls,node_asgi_stack,node_accounts,node_chat,node_chat_ws,node_chat_consumer,node_jwt_mw toneAmber
class node_postgres,node_redis,node_compose,node_dockerfiles toneMint
```

## Components

### Client

Browser-facing React application

- **Browser**: user agent · End user entry point for the app
- [React SPA](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/main.jsx): vite app · Single-page frontend for auth and chat · `frontend/src/main.jsx`
- [Auth page](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/Authpage.jsx): screen · Login and registration entry · `frontend/src/pages/Authpage.jsx`
- [Chat page](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/ChatPage.jsx): screen · Room view and live messaging UI · `frontend/src/pages/ChatPage.jsx`
- [Route guard](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/pages/utils/Protectedroutes.jsx): routing · Authenticated navigation gate · `frontend/src/pages/utils/Protectedroutes.jsx`
- [Redux store](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/store.js): state · Central client state container · `frontend/src/store/store.js`
- [Auth state](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/AuthSlice.js): redux slice · Authentication state and session data · `frontend/src/store/AuthSlice.js`
- [Chat state](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/ChatSlice.js): redux slice · Rooms, messages, and chat UI state · `frontend/src/store/ChatSlice.js`
- [Theme state](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/store/ThemeSlice.js): redux slice · UI theme preferences · `frontend/src/store/ThemeSlice.js`
- [API client](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/api/api.js): http client · REST request layer · `frontend/src/api/api.js`
- [Socket manager](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/service/chatSocketManager.js): websocket client · WebSocket lifecycle and live message handling · `frontend/src/service/chatSocketManager.js`
- [Shared UI](https://github.com/myselfanandvp/lexta/blob/main/frontend/src/components/common/Navbar.jsx): components · Navbar, footer, and loader primitives · `frontend/src/components/common/Navbar.jsx`

### Server

Django application with REST and Channels

- [Django app](https://github.com/myselfanandvp/lexta/blob/main/backend/backend/settings.py): backend platform · HTTP and ASGI application boundary · `backend/backend/settings.py`
- [URL wiring](https://github.com/myselfanandvp/lexta/blob/main/backend/backend/urls.py): routing · Top-level Django request routing · `backend/backend/urls.py`
- [ASGI stack](https://github.com/myselfanandvp/lexta/blob/main/backend/backend/asgi.py): channels runtime · Async entrypoint for socket traffic · `backend/backend/asgi.py`
- [Accounts](https://github.com/myselfanandvp/lexta/blob/main/backend/apps/accounts/models.py): domain app · Identity, auth, and user management · `backend/apps/accounts/models.py`
- [Chat domain](https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/models.py): domain app · Rooms, messages, REST views, and realtime consumers · `backend/apps/chat/models.py`
- [WS routing](https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/routing.py): channels routes · WebSocket path and consumer wiring · `backend/apps/chat/routing.py`
- [Chat consumer](https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/consumers.py): websocket handler · Realtime message fanout and room participation · `backend/apps/chat/consumers.py`
- [JWT middleware](https://github.com/myselfanandvp/lexta/blob/main/backend/apps/chat/middleware.py): channels auth · Authenticates socket handshakes · `backend/apps/chat/middleware.py`

### Infra

Containerized runtime and data services

- **PostgreSQL**: database · Durable persistence for users, rooms, and messages
- **Redis**: pubsub/cache · Channels layer and realtime coordination backend
- [Compose stack](https://github.com/myselfanandvp/lexta/blob/main/docker-compose.yml): orchestration · Local multi-service runtime definition · `docker-compose.yml`
- [Dockerfiles](https://github.com/myselfanandvp/lexta/blob/main/Dockerfile.frontend): build/runtime · Separate container builds for frontend and backend · `Dockerfile.frontend`

## Connections

- Browser → React SPA: uses · User interacts with the SPA
- React SPA → Auth page: renders · Initial auth entry flow
- React SPA → Chat page: renders · Main chat experience
- React SPA → Route guard: gates · Blocks unauthenticated navigation
- Auth page → Redux store: reads/writes · Uses centralized auth state
- Chat page → Redux store: reads/writes · Uses centralized chat and theme state
- Redux store → Auth state: contains · Authentication slice
- Redux store → Chat state: contains · Chat slice
- Redux store → Theme state: contains · Theme slice
- React SPA → API client: calls · HTTP requests for auth and chat history
- Chat page → Socket manager: opens · Live room connection
- React SPA → Shared UI: uses · Shared layout and status components
- API client → Django app: HTTP · REST traffic to backend
- Django app → URL wiring: routes · Dispatches API requests
- Django app → ASGI stack: serves · Async entrypoint for websocket traffic
- URL wiring → Accounts: includes · Auth endpoints
- URL wiring → Chat domain: includes · Chat REST endpoints
- Accounts → PostgreSQL: persists · Users and credentials metadata
- Chat domain → PostgreSQL: persists · Rooms and messages
- Socket manager → ASGI stack: WebSocket · Connects to chat socket endpoint
- ASGI stack → WS routing: dispatches · Routes websocket paths
- WS routing → JWT middleware: authenticates · Validates socket handshake
- WS routing → Chat consumer: creates · Hands off to room consumer
- Chat consumer → Redis: fanout · Realtime channel layer coordination
- Chat consumer → PostgreSQL: reads/writes · Stores and loads chat data
- Compose stack → React SPA: runs · Frontend container/service
- Compose stack → Django app: runs · Backend container/service
- Compose stack → PostgreSQL: runs · Database service
- Compose stack → Redis: runs · Redis service
- Dockerfiles → React SPA: builds · Frontend image
- Dockerfiles → Django app: builds · Backend image
