# hxni786/hxnix-social-media-app architecture

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

- Interactive diagram: https://gitdiagram.com/hxni786/hxnix-social-media-app
- Repository: https://github.com/hxni786/hxnix-social-media-app

## Overview

#### Purpose and topology
HXNIX is a mobile social-feed system: an Expo/React Native client consumes a Node/Express REST API backed by MySQL. The app supports authentication-oriented UI plus post listing, detail, creation, and deletion. Production mobile builds can target a configured remote API; local devices require a LAN-accessible backend.

#### Entry points and navigation
- Expo Router bootstraps the client and route shell through `frontend/app/_layout.js` and the feed landing route `frontend/app/index.js`.
- Post detail is a dynamic file route at `frontend/app/post/[id].js`.
- The server process starts from `backend/server.js`, exposing health and API endpoints, conventionally on port 5000.

#### Client application layer
- Screen-level behavior is organized in `frontend/src/pages/FeedScreen.js`, `frontend/src/pages/PostDetailScreen.js`, and authentication screens under `frontend/src/pages/`.
- Shared authenticated-user state is centralized in `frontend/src/context/AuthContext.js`, separating session concerns from route/UI composition.
- Reusable feed presentation is primarily `frontend/src/components/ui/PostCard.js`; app-wide visual framing is `frontend/src/components/layout/AppHeader.js`.
- API host selection is a client boundary in `frontend/src/config.js`; it must resolve to an address reachable from the device.

#### Client-to-server data flow
- Screens invoke the post transport abstraction in `frontend/src/services/postService.js`.
- Requests cross an HTTP/JSON REST boundary to the Express server. Main read flow is feed/detail screen → post service → `GET /api/posts` or `GET /api/posts/:id` → rendered state.
- Mutation flow is client create/delete action → post service → server controller/model → MySQL; feed state is refreshed after deletion rather than relying on realtime push infrastructure.

#### Express API and request pipeline
- `backend/server.js` assembles Express, database initialization, route mounting, health checking, and global error handling.
- Post endpoints are declared in `backend/routes/postRoutes.js` and handled in `backend/controllers/postController.js`, keeping HTTP route definitions separate from application operations.
- Authentication endpoints are isolated in `backend/routes/authRoutes.js`; `backend/middleware/authMiddleware.js` is the authorization boundary for protected operations.
- Unhandled failures are normalized by `backend/middleware/errorHandler.js`.

#### Persistence and domain model
- MySQL connectivity/configuration is established in `backend/config/db.js`, driven by backend environment variables (`DB_HOST`, `DB_PORT`, `DB_USER`, `DB_PASSWORD`, `DB_NAME`).
- `backend/models/Post.js` owns post persistence and initial-data seeding when the posts table is empty. Posts include title, body, and user association per the API contract.
- `backend/models/User.js` represents the user persistence domain used by the authentication route family.
- Database availability is a hard server-side infrastructure dependency; the health endpoint provides a lightweight operational check.

#### Material runtime and deployment boundaries
- Mobile runtime: React Native under Expo SDK 54, configured by `frontend/app.json`; EAS build configuration is `frontend/eas.json`.
- Backend runtime: Node.js 18+ with Express; MySQL 8+ is the relational store.
- The client and API are independently deployable. Client configuration determines the API origin, while backend secrets and DB connectivity remain server-side in `backend/.env`.

Main entry points: [`backend/server.js`](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/server.js) (Express server), [`frontend/src/pages/FeedScreen.js`](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/pages/FeedScreen.js) (Feed and detail screens), [`frontend/src/services/postService.js`](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/services/postService.js) (Post service), [`backend/routes/postRoutes.js`](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/routes/postRoutes.js) (Post routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Expo Mobile Client"]
  node_expo_router["Expo Router shell<br/>client entry<br/>[_layout.js]"]
  node_feed_route["Feed route<br/>file route<br/>[index.js]"]
  node_post_route["Post detail route<br/>dynamic file route<br/>[&#91;id&#93;.js]"]
  node_screens["Feed and detail screens<br/>screen layer<br/>[FeedScreen.js]"]
  node_auth_screens["Authentication screens<br/>screen layer"]
  node_auth_context["Auth session state<br/>React context<br/>[AuthContext.js]"]
  node_post_card["Post card<br/>UI component<br/>[PostCard.js]"]
  node_api_config["API origin config<br/>client boundary<br/>[config.js]"]
  node_post_service["Post service<br/>HTTP transport<br/>[postService.js]"]
end

subgraph group_api["Express API"]
  node_server["Express server<br/>Node process<br/>[server.js]"]
  node_post_routes["Post routes<br/>REST routes<br/>[postRoutes.js]"]
  node_post_controller["Post controller<br/>[postController.js]"]
  node_auth_routes["Auth routes<br/>REST routes<br/>[authRoutes.js]"]
  node_auth_middleware["Authorization middleware<br/>[authMiddleware.js]"]
  node_error_handler["Global error handler<br/>middleware<br/>[errorHandler.js]"]
end

subgraph group_data["Persistence"]
  node_db_config["MySQL connection<br/>database config<br/>[db.js]"]
  node_post_model["Post model<br/>persistence model<br/>[Post.js]"]
  node_user_model["User model<br/>persistence model<br/>[User.js]"]
  node_mysql[("MySQL 8+<br/>relational database")]
end

node_expo_router -->|"mounts"| node_feed_route
node_expo_router -->|"mounts"| node_post_route
node_feed_route -->|"renders"| node_screens
node_post_route -->|"renders detail"| node_screens
node_auth_screens -->|"uses session"| node_auth_context
node_screens -->|"renders posts"| node_post_card
node_screens -->|"loads and mutates posts"| node_post_service
node_post_service -->|"resolves origin"| node_api_config
node_post_service -->|"HTTP/JSON REST"| node_server
node_server -->|"mounts"| node_post_routes
node_server -->|"mounts"| node_auth_routes
node_server -->|"uses"| node_error_handler
node_server -->|"initializes"| node_db_config
node_post_routes -->|"authorizes protected actions"| node_auth_middleware
node_post_routes -->|"dispatches"| node_post_controller
node_post_controller -->|"reads and writes"| node_post_model
node_auth_routes -->|"uses"| node_user_model
node_db_config -->|"connects"| node_mysql
node_post_model -->|"persists posts"| node_mysql
node_user_model -->|"persists users"| node_mysql

click node_expo_router "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/_layout.js"
click node_feed_route "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/index.js"
click node_post_route "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/post/%5Bid%5D.js"
click node_screens "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/pages/FeedScreen.js"
click node_auth_context "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/context/AuthContext.js"
click node_post_card "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/components/ui/PostCard.js"
click node_api_config "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/config.js"
click node_post_service "https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/services/postService.js"
click node_server "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/server.js"
click node_post_routes "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/routes/postRoutes.js"
click node_post_controller "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/controllers/postController.js"
click node_auth_routes "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/routes/authRoutes.js"
click node_auth_middleware "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/middleware/authMiddleware.js"
click node_error_handler "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/middleware/errorHandler.js"
click node_db_config "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/config/db.js"
click node_post_model "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/models/Post.js"
click node_user_model "https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/models/User.js"

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_expo_router,node_feed_route,node_post_route,node_screens,node_auth_screens,node_auth_context,node_post_card,node_api_config,node_post_service toneBlue
class node_server,node_post_routes,node_post_controller,node_auth_routes,node_auth_middleware,node_error_handler toneAmber
class node_db_config,node_post_model,node_user_model,node_mysql toneMint
```

## Components

### Expo Mobile Client

- [Expo Router shell](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/_layout.js): client entry · Bootstraps route composition. · `frontend/app/_layout.js`
- [Feed route](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/index.js): file route · `frontend/app/index.js`
- [Post detail route](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/app/post/%5Bid%5D.js): dynamic file route · `frontend/app/post/[id].js`
- [Feed and detail screens](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/pages/FeedScreen.js): screen layer · `frontend/src/pages/FeedScreen.js`
- **Authentication screens**: screen layer
- [Auth session state](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/context/AuthContext.js): React context · `frontend/src/context/AuthContext.js`
- [Post card](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/components/ui/PostCard.js): UI component · `frontend/src/components/ui/PostCard.js`
- [API origin config](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/config.js): client boundary · Must resolve to a device-reachable API address. · `frontend/src/config.js`
- [Post service](https://github.com/hxni786/hxnix-social-media-app/blob/main/frontend/src/services/postService.js): HTTP transport · `frontend/src/services/postService.js`

### Express API

- [Express server](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/server.js): Node process · Assembles database initialization, routes, health checks, and error handling. · `backend/server.js`
- [Post routes](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/routes/postRoutes.js): REST routes · GET /api/posts and /api/posts/:id plus post mutations. · `backend/routes/postRoutes.js`
- [Post controller](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/controllers/postController.js): controller · `backend/controllers/postController.js`
- [Auth routes](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/routes/authRoutes.js): REST routes · `backend/routes/authRoutes.js`
- [Authorization middleware](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/middleware/authMiddleware.js): middleware · Protects authorized operations. · `backend/middleware/authMiddleware.js`
- [Global error handler](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/middleware/errorHandler.js): middleware · Normalizes unhandled failures. · `backend/middleware/errorHandler.js`

### Persistence

- [MySQL connection](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/config/db.js): database config · Uses server-side DB environment variables. · `backend/config/db.js`
- [Post model](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/models/Post.js): persistence model · Persists posts and seeds an empty posts table. · `backend/models/Post.js`
- [User model](https://github.com/hxni786/hxnix-social-media-app/blob/main/backend/models/User.js): persistence model · `backend/models/User.js`
- **MySQL 8+**: relational database

## Connections

- Expo Router shell → Feed route: mounts
- Expo Router shell → Post detail route: mounts
- Feed route → Feed and detail screens: renders
- Post detail route → Feed and detail screens: renders detail
- Authentication screens → Auth session state: uses session
- Feed and detail screens → Post card: renders posts
- Feed and detail screens → Post service: loads and mutates posts
- Post service → API origin config: resolves origin
- Post service → Express server: HTTP/JSON REST
- Express server → Post routes: mounts
- Express server → Auth routes: mounts
- Express server → Global error handler: uses
- Express server → MySQL connection: initializes
- Post routes → Authorization middleware: authorizes protected actions
- Post routes → Post controller: dispatches
- Post controller → Post model: reads and writes
- Auth routes → User model: uses
- MySQL connection → MySQL 8+: connects
- Post model → MySQL 8+: persists posts
- User model → MySQL 8+: persists users
