DEV Community

Adeyeye George
Adeyeye George

Posted on • Edited on

How I Built CampChat: A PHP-Powered Chat Engine That’s Changing the Game

Image description

As a developer, I’ve always been fascinated by the magic of real-time communication. There’s something thrilling about crafting a system where messages zip across the internet, connecting people instantly. But building a chat app from scratch? That’s a beast—encryption, scalability, bots, oh my! So, I rolled up my sleeves and created CampChat, an open-source, PHP-based chat engine that’s secure, scalable, and packed with features inspired by Telegram. It’s the kind of project that makes you lose sleep (in a good way). Let me take you through my journey of building it, why it’s a game-changer, and how you can start using it with a few lines of code.

Why I Built CampChat

It all started late one night, fueled by too much coffee and a frustration with existing chat solutions. I needed a backend that was lightweight, developer-friendly, and didn’t require a PhD in distributed systems to scale. Most frameworks were either too rigid or overly complex, and I wanted something that could power a community app, a support portal, or even a social platform without breaking a sweat. PHP, with its accessibility and vast ecosystem, felt like the perfect fit. So, I set out to build CampChat—a chat engine that combines modern tech like Slim Framework, MongoDB, Redis, and RabbitMQ with Telegram-style features like group chats, end-to-end encryption, and extensible bots.

The goal? Make it easy for developers like me (and you!) to spin up a secure, real-time chat system without reinventing the wheel. After months of coding, debugging, and more coffee, CampChat was born. It’s not just a tool—it’s my love letter to the developer community, and I’m excited to share it with you.

What Makes CampChat Special?

CampChat isn’t just another chat backend. It’s designed to be your Swiss Army knife for communication apps. Here’s what sets it apart:

Privacy First: End-to-end encryption for messages and media, because no one should snoop on your users’ chats.

Scales Like a Dream: Redis for caching and RabbitMQ for async event handling mean it can handle thousands of users without hiccups.

Bot Magic: Create bots with webhook support to automate tasks, like welcoming new group members or moderating chats.

Feature-Packed: Group permissions, message reactions, pinned messages, and media sharing make it feel like a modern social platform.

Open Source: Under the MIT license, it’s free to hack, tweak, and build upon.

Think of it as Telegram’s core, reimagined for developers who want control and flexibility. Whether you’re building a niche community or a customer support system, CampChat has your back.

My Struggles and Triumphs

Building CampChat wasn’t all smooth sailing. Early on, I wrestled with MongoDB’s schema design to balance performance and flexibility for storing users, groups, and messages. Getting RabbitMQ to handle bot events asynchronously was a headache—until I finally cracked the queue configuration. And don’t get me started on implementing end-to-end encryption without sacrificing speed! But every bug squashed and feature added felt like a small victory. When I sent my first encrypted group message and saw a bot respond via webhook, I did a little happy dance. This is the kind of project that reminds you why you love coding.

Let’s Get You Started

Enough about my journey—let’s get CampChat running on your machine. It’s surprisingly simple to set up, and I’ll walk you through the basics with some code examples to show off its power.

Setting Up CampChat

Clone the Repo:

git clone https://github.com/mitmelon/campchat.git
cd campchat
Enter fullscreen mode Exit fullscreen mode

Install Dependencies:

composer install
Enter fullscreen mode Exit fullscreen mode

Configure the Environment: Copy .env.example to .env and fill in your MongoDB, Redis, and RabbitMQ details:

MONGODB_URI=mongodb://localhost:27017
REDIS_HOST=localhost
REDIS_PORT=6379
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USER=campchat
RABBITMQ_PASS=1234567890
STORAGE_TYPE=local
STORAGE_PATH=/path/to/storage
Enter fullscreen mode Exit fullscreen mode

Set Up Storage:

mkdir -p /path/to/storage
chmod -R 775 /path/to/storage
Enter fullscreen mode Exit fullscreen mode

Run the Server:

composer start
Enter fullscreen mode Exit fullscreen mode

Start the Bot Worker: For bot event processing:

php src/Workers/BotWorker.php
Enter fullscreen mode Exit fullscreen mode

Your API is now live at http://localhost:8011/v1. Time to have some fun!

Code Examples: CampChat in Action

Here are a few examples to show how easy it is to integrate CampChat into your project. These use curl, but you can adapt them for any HTTP client in your preferred language.

1. Creating a User

Let’s create a user account to get started.

curl -X POST http://localhost:8011/v1/users/create \
-H "Content-Type: application/json" \
-d '{
  "first_name": "Bob",
  "last_name": "Jones",
  "username": "bobjones",
  "password": "mysecret123",
  "phone": "+1987654321",
  "dob": "1995-03-15",
  "country": "US",
  "gender": "male"
}
Enter fullscreen mode Exit fullscreen mode

Response:

json
{
  "ok": true,
  "result": {
    "id": "user1234567890abcdef"
  }
}
Enter fullscreen mode Exit fullscreen mode

This gives you a user ID to work with. Pro tip: Store it securely!

2. Creating a Group

Now, let’s create a group for Bob and his friends.

curl -X POST http://localhost:8011/v1/groups \
-H "Content-Type: application/json" \
-H "Authorization: Bearer jwt.token.here" \
-d '{
  "name": "Code Warriors",
  "creator_id": "user1234567890abcdef",
  "members": ["user456"],
  "permissions": {
    "locked": false,
    "allow_member_messages": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Response:

json
{
  "ok": true,
  "result": {
    "id": "group1234567890abcdef"
  }
}
Enter fullscreen mode Exit fullscreen mode

This sets up a group where everyone can chat freely.

3. Adding a Bot

Bots were my favorite part to build. Here’s how to create one that welcomes new group members.

curl -X POST http://localhost:8011/v1/bots \
-H "Content-Type: application/json" \
-H "Authorization: Bearer jwt.token.here" \
-d '{
  "user_id": "user1234567890abcdef",
  "name": "CodeBot",
  "commands": {
    "welcome": "Welcome to Code Warriors!"
  },
  "webhook_url": "https://your-server.com/bot-webhook"
}
Enter fullscreen mode Exit fullscreen mode

Response:

`json
{
  "ok": true,
  "result": {
    "id": "bot1234567890abcdef"
  }
}
Enter fullscreen mode Exit fullscreen mode

When someone types /welcome@CodeBot in the group, CampChat hits your webhook, and your bot can respond dynamically. I spent hours tweaking this to make bot interactions seamless—it’s a game-changer for automation.

What’s Next for CampChat?

CampChat is a living project, and I’m already dreaming up new features based on my own needs and community feedback. Imagine AI-powered bots that can moderate chats or generate witty responses, or maybe Stories and Reels for a social media vibe. I’m also working on 2FA, push notifications, and quantum-resistant encryption to keep CampChat future-proof. The possibilities are endless, and I’m excited to see where the community takes it.

Why You Should Jump In

Building CampChat was a labor of love, born from late-night coding sessions and a passion for solving real developer pain points. It’s not just a chat engine—it’s a foundation for your next big app, whether it’s a community platform, a support tool, or something totally new. The MIT license means you can hack it to your heart’s content, and the GitHub community is ready to welcome your ideas.

So, what are you waiting for? Clone the repo, fire up the server, and start building something awesome. I can’t wait to see what you create with CampChat. Drop by the GitHub repo to get started, share your thoughts, or even contribute a feature. Let’s build the future of communication together!

Top comments (0)