Skip to content

DevNest is a backend-driven platform that simulates features commonly found in real-world applications, with a strong focus on scalability and clean architecture.

Notifications You must be signed in to change notification settings

johnvesslyalti/dev-nest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ DevNest

DevNest is a scalable backend platform inspired by X (Twitter), built with Node.js, TypeScript, Express, Prisma, PostgreSQL, and Redis.

It follows a clean, layered architecture and focuses on building production-ready social platform features with performance, scalability, and maintainability in mind.


🧠 Architecture Overview

DevNest strictly follows this flow:

Routes β†’ Controller β†’ Service β†’ Repository β†’ Database

Why this architecture?

  • βœ… Clear separation of concerns
  • βœ… Easy to test and refactor
  • βœ… Business logic isolated from HTTP & DB layers
  • βœ… Scales cleanly as features grow

πŸ›  Tech Stack

  • Node.js
  • TypeScript
  • Express.js
  • Prisma ORM
  • PostgreSQL
  • Redis (Caching & Queues)
  • BullMQ (Background Jobs)
  • Multer (File Uploads)
  • Vite + React (Frontend)
  • Tailwind CSS (Styling)
  • JWT Authentication (Access & Refresh Tokens)

πŸ“ Project Structure

src/
β”œβ”€β”€ modules/          # Feature-based texture (Controller, Service, Routes)
β”œβ”€β”€ middlewares/      # Auth, Rate Limiting, Validation, Error Handling
β”œβ”€β”€ jobs/             # Background workers (Email, Notifications)
β”œβ”€β”€ lib/              # Core utilities (Prisma, Redis, Logger)
β”œβ”€β”€ types/            # Global type definitions
β”œβ”€β”€ app.ts            # Express setup
└── server.ts         # Server entry point

frontend/             # React + Vite application
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ api/          # Axios client & API modules
β”‚   β”œβ”€β”€ components/   # Reusable UI components
β”‚   β”œβ”€β”€ context/      # React Context (Auth)
β”‚   β”œβ”€β”€ pages/        # Route pages
β”‚   └── main.tsx      # Frontend entry point

uploads/              # Static file storage (Images)

Each module follows:

module/
β”œβ”€β”€ module.routes.ts
β”œβ”€β”€ module.controller.ts
β”œβ”€β”€ module.service.ts
β”œβ”€β”€ module.repository.ts
└── module.types.ts

πŸ” Authentication

  • JWT-based authentication
  • Access & refresh token flow
  • Secure route protection via middleware
  • Authenticated user attached to req.user

⚑ Redis Caching Strategy

Redis is used as a shared caching layer across modules to improve performance and reduce database load.

Where Redis is used

  • User profile reads
  • Feed responses
  • Posts & interactions
  • Follow / block checks
  • Frequently accessed relational data

Cache Pattern Used

  • Read-through caching
  • Cache invalidation on write/update/delete
  • Fallback to database on cache miss

Example Flow

Request β†’ Redis β†’ Database (if cache miss) β†’ Redis update β†’ Response

Benefits

  • πŸš€ Faster response times
  • πŸ“‰ Reduced database queries
  • πŸ“ˆ Better scalability under load

🐦 Core Features

πŸ‘€ Users

  • Register & login
  • Profile management
  • Follow / unfollow users
  • Cached profile reads

πŸ“ Posts

  • Create posts
  • Fetch posts efficiently
  • Cached post lists

❀️ Likes

  • Like / unlike posts
  • Prevent duplicate likes
  • Cache-aware invalidation

πŸ’¬ Comments

  • Comment on posts
  • Delete own comments

🚫 Blocking (X-like Behavior)

  • Block users

  • Unblock users

  • View blocked users list

  • Blocking removes follow relationships

  • Blocked users cannot:

    • follow
    • like
    • comment
    • view feed content

πŸ“° Feed

  • Feed based on follow relationships
  • Block-aware feed filtering
  • Redis-cached feed responses

πŸ“¨ Background Jobs & Notifications

  • BullMQ + Redis based job queue
  • Asynchronous email sending (Welcome emails)
  • Notification generation (Likes, Follows)

πŸ›‘οΈ Security & Performance

  • Rate Limiting: Redis-based sliding window limiter protected endpoints.
  • JWT Auth: Secure access/refresh token rotation.
  • Helmet & CORS: Enhanced security headers.

πŸ–ΌοΈ Media Management

  • Image uploads via Multer
  • Static file serving for user avatars and post images

🧱 Database Design (Prisma)

Key models:

  • User
  • Post
  • Follow
  • BlockedUser
  • Like
  • Comment

Designed with:

  • Unique constraints
  • Indexes for performance
  • Cascade deletes
  • Proper relational modeling

βš™οΈ Setup & Installation

1️⃣ Clone the repository

git clone https://github.com/johnvesslyalti/dev-nest.git
cd dev-nest

2️⃣ Install dependencies

npm install

3️⃣ Setup environment variables

Create a .env file:

DATABASE_URL=postgresql://user:password@localhost:5432/devnest
REDIS_URL=redis://localhost:6379
JWT_SECRET=your_jwt_secret
REFRESH_TOKEN_SECRET=your_refresh_secret

4️⃣ Run Prisma

npx prisma generate
npx prisma migrate dev

5️⃣ Start Redis

redis-server

6️⃣ Start the Backend

npm run dev

7️⃣ Start the Frontend

Open a new terminal:

cd frontend
npm install
npm run dev

The app will be available at http://localhost:5173.


πŸ§ͺ Development Principles

  • ❌ No Prisma calls in controllers
  • ❌ No HTTP logic in services
  • ❌ No business logic in repositories
  • βœ… Repositories handle DB access
  • βœ… Services enforce business rules
  • βœ… Redis caching handled consistently per module

🚧 Future Enhancements

  • WebSocket-based real-time updates (Socket.io)
  • Retweets / reposts
  • Hashtags & trending topics
  • Direct messaging
  • API documentation (Swagger / OpenAPI)

πŸ‘¨β€πŸ’» Author

Johnvessly Alti Backend-focused Software Engineer Building scalable systems with clean architecture.


⭐ Contributing

Pull requests are welcome. Please open an issue before making major changes.


πŸ“„ License

MIT License

About

DevNest is a backend-driven platform that simulates features commonly found in real-world applications, with a strong focus on scalability and clean architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages