How myselfanandvp/lexta works
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: main.jsx React SPA · store.js Redux store · settings.py Django app · docker-compose.yml Compose stack
Components 24
Client
Browser-facing React application
- Browser · End user entry point for the app
- React SPA · Single-page frontend for auth and chat
frontend/src/main.jsx - Auth page · Login and registration entry
frontend/src/pages/Authpage.jsx - Chat page · Room view and live messaging UI
frontend/src/pages/ChatPage.jsx - Route guard · Authenticated navigation gate
frontend/src/pages/utils/Protectedroutes.jsx - Redux store · Central client state container
frontend/src/store/store.js - Auth state · Authentication state and session data
frontend/src/store/AuthSlice.js - Chat state · Rooms, messages, and chat UI state
frontend/src/store/ChatSlice.js - Theme state · UI theme preferences
frontend/src/store/ThemeSlice.js - API client · REST request layer
frontend/src/api/api.js - Socket manager · WebSocket lifecycle and live message handling
frontend/src/service/chatSocketManager.js - Shared UI · Navbar, footer, and loader primitives
frontend/src/components/common/Navbar.jsx
Server
Django application with REST and Channels
- Django app · HTTP and ASGI application boundary
backend/backend/settings.py - URL wiring · Top-level Django request routing
backend/backend/urls.py - ASGI stack · Async entrypoint for socket traffic
backend/backend/asgi.py - Accounts · Identity, auth, and user management
backend/apps/accounts/models.py - Chat domain · Rooms, messages, REST views, and realtime consumers
backend/apps/chat/models.py - WS routing · WebSocket path and consumer wiring
backend/apps/chat/routing.py - Chat consumer · Realtime message fanout and room participation
backend/apps/chat/consumers.py - JWT middleware · Authenticates socket handshakes
backend/apps/chat/middleware.py
Infra
Containerized runtime and data services
- PostgreSQL · Durable persistence for users, rooms, and messages
- Redis · Channels layer and realtime coordination backend
- Compose stack · Local multi-service runtime definition
docker-compose.yml - Dockerfiles · Separate container builds for frontend and backend
Dockerfile.frontend
Connections 31
- 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