# burakorkmez/x-clone-rn architecture

> Architecture diagram of the GitHub repository burakorkmez/x-clone-rn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/burakorkmez/x-clone-rn
- Repository: https://github.com/burakorkmez/x-clone-rn

## Overview

##### Project type and purpose
- This is a full-stack mobile application (“X Clone”) comprised of:
- A React Native Expo frontend (mobile folder)
- A Node.js/Express backend API (backend folder)
- MongoDB for data persistence
- Clerk for authentication
- Cloudinary for media storage
- Arcjet for security/bot detection
- The README confirms it’s a tutorial, but the architecture is production-grade: REST API, external services, mobile client.

##### File structure
- Top-level directories:
- backend: Node/Express REST API
- mobile: React Native (Expo) project
- backend/src:
- config: environment, DB, external-service clients (Clerk via arcjet.js, Cloudinary)
- controllers: business logic (user, post, comment, notification)
- middleware: auth, Arcjet protection, file upload
- models: Mongoose schemas for User, Post, Comment, Notification
- routes: REST endpoints mapped to controllers
- server.js: app entry, Express setup, route registration
- mobile:
- app: Next.js-like routing (React Navigation) with auth flow and tabs
- components: UI building blocks (PostCard, NotificationCard, modals)
- data: sample static data
- hooks: custom React Query / fetch wrappers for posts, comments, notifications, auth
- utils/api.ts: HTTP client pointing at backend API
- assets: fonts & images
- config files: babel, metro, Tailwind CSS setup
- Deployment/config files:
- backend/vercel.json for serverless configuration
- mobile/app.json for Expo
- .env instructions in README

##### Extract insights from README
- Full-stack mobile: React Native + Express/MongoDB
- Features: authentication (via Clerk), image upload (Cloudinary), rate-limiting & bot detection (Arcjet)
- Auth flow: mobile obtains a Clerk session, calls backend passing Clerk tokens
- Backend interacts with MongoDB, Cloudinary, Arcjet, Clerk APIs

a. Main components
- Mobile Client (Expo/React Native)
- Backend API (Express.js)
- Database (MongoDB Atlas)
- Authentication Provider (Clerk)
- Media Storage (Cloudinary)
- Security/Bot Service (Arcjet)
b. Relationships & interactions
1. Mobile ↔ Backend over HTTPS (REST endpoints defined in routes)
2. Backend ↔ MongoDB via Mongoose (db.js config)
3. Backend ↔ Cloudinary for image uploads
4. Backend ↔ Clerk for session validation (auth.middleware.js)
5. Backend ↔ Arcjet for rate-limiting and bot detection (arcjet.middleware.js)
c. Architectural patterns & design principles
- Layered Architecture:
– Presentation: Mobile screens & components
– API Layer: Express routes → middleware → controllers
– Domain/Data Layer: Mongoose models
- Separation of concerns: config, routes, controllers, models, middleware
- Use of external managed services to offload functionality (Auth, media, security)
d. Key technologies & libraries
- Frontend: React Native, Expo, Tailwind CSS, NativeWind, React Navigation
- Data fetching: custom hooks wrapping fetch/React Query patterns
- Backend: Node.js, Express.js, Mongoose, Cloudinary SDK, Arcjet SDK, Clerk SDK
- Deployment: Vercel (backend), Expo (mobile)

##### Detailed breakdown
- Mobile Client:
- Auth Stack & Protected Routes
- Tab Navigator (Home, Messages, Notifications, Profile, Search)
- Components & Hooks layer
- Backend API:
- server.js (entry) → route registration
- Middleware layer (auth, Arcjet, upload)
- Controller layer (user, post, comment, notification)
- Model layer (Mongoose schemas)
- Infrastructure & services:
- MongoDB Atlas (collections: users, posts, comments, notifications)
- Cloudinary (image storage, URLs)
- Clerk (OAuth flows)
- Arcjet (rate-limit & bot detection)
- Data flows:
- New Post: Mobile → POST /posts → upload.middleware → Cloudinary → save Post model → response
- Comments: Mobile → POST /comments → Comment model → Notification controller → save notification
- Notifications: Mobile → GET /notifications → Notification.controller → list
- Auth calls: Mobile → Clerk SDK → backend auth middleware

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Mobile Client (Expo)"
        direction TB
        Nav["Navigation & Screens"]:::compute
        UIComp["UI Components"]:::compute
        Hooks["Data Fetching & Auth Hooks"]:::compute
        APIUtil["API Client Utility"]:::compute
    end

    subgraph "Backend API (Express)"
        direction TB
        Server["server.js"]:::compute
        subgraph "Middleware Layer"
            AuthMW["Auth Middleware"]:::compute
            BotMW["Arcjet Middleware"]:::compute
            UploadMW["Upload Middleware"]:::compute
        end
        subgraph "Controllers"
            UserCtrl["user.controller.js"]:::compute
            PostCtrl["post.controller.js"]:::compute
            CommentCtrl["comment.controller.js"]:::compute
            NotifCtrl["notification.controller.js"]:::compute
        end
        subgraph "Models"
            UserModel["user.model.js"]:::datastore
            PostModel["post.model.js"]:::datastore
            CommentModel["comment.model.js"]:::datastore
            NotifModel["notification.model.js"]:::datastore
        end
        subgraph "Routes"
            UserRoute["user.route.js"]:::compute
            PostRoute["post.route.js"]:::compute
            CommentRoute["comment.route.js"]:::compute
            NotifRoute["notification.route.js"]:::compute
        end
    end

    DB["MongoDB Atlas"]:::datastore
    Cloud["Cloudinary"]:::datastore
    Clerk["Clerk (Auth)"]:::external
    Arcjet["Arcjet (Security)"]:::external

    Nav -->|HTTPS Requests| Server
    UIComp -->|UI Events| Server
    Hooks -->|Data Fetch| Server
    APIUtil -->|HTTP Client| Server

    Server --> AuthMW
    Server --> BotMW
    Server --> UploadMW

    AuthMW -->|Validates via Clerk SDK| Clerk
    BotMW -->|Checks via Arcjet SDK| Arcjet
    UploadMW -->|Uploads to| Cloud

    Server --> UserRoute
    Server --> PostRoute
    Server --> CommentRoute
    Server --> NotifRoute

    UserRoute --> UserCtrl
    PostRoute --> PostCtrl
    CommentRoute --> CommentCtrl
    NotifRoute --> NotifCtrl

    UserCtrl --> UserModel
    PostCtrl --> PostModel
    CommentCtrl --> CommentModel
    NotifCtrl --> NotifModel

    UserCtrl --> DB
    PostCtrl --> DB
    CommentCtrl --> DB
    NotifCtrl --> DB

    classDef compute fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef datastore fill:#DFFFE0,stroke:#028A0F,stroke-width:1px
    classDef external fill:#FFF0D6,stroke:#D97706,stroke-width:1px

    click Nav "https://github.com/burakorkmez/x-clone-rn/tree/master/mobile/app/"
    click UIComp "https://github.com/burakorkmez/x-clone-rn/tree/master/mobile/components/"
    click Hooks "https://github.com/burakorkmez/x-clone-rn/tree/master/mobile/hooks/"
    click APIUtil "https://github.com/burakorkmez/x-clone-rn/blob/master/mobile/utils/api.ts"
    click Server "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/server.js"
    click AuthMW "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/middleware/auth.middleware.js"
    click BotMW "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/middleware/arcjet.middleware.js"
    click UploadMW "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/middleware/upload.middleware.js"
    click UserCtrl "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/controllers/user.controller.js"
    click PostCtrl "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/controllers/post.controller.js"
    click CommentCtrl "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/controllers/comment.controller.js"
    click NotifCtrl "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/controllers/notification.controller.js"
    click UserModel "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/models/user.model.js"
    click PostModel "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/models/post.model.js"
    click CommentModel "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/models/comment.model.js"
    click NotifModel "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/models/notification.model.js"
    click UserRoute "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/routes/user.route.js"
    click PostRoute "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/routes/post.route.js"
    click CommentRoute "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/routes/comment.route.js"
    click NotifRoute "https://github.com/burakorkmez/x-clone-rn/blob/master/backend/src/routes/notification.route.js"
```
