A simple chat application backend implemented in PHP using the Slim framework and Doctrine ORM. Users can create chat groups, join them, and send messages. This application uses an SQLite database for data storage.
- Create chat groups
- Join existing chat groups
- Send messages within groups
- List all messages in a group
- Lightweight and easy to set up
- PHP 8.3 or higher
- Composer
- Docker (optional, for containerized setup)
- SQLite (included in the project)
-
Clone the repository:
git clone https://github.com/antevgen/chat.git cd chat
-
Install dependencies using Composer:
composer install
-
Set up the environment configuration: Copy the example environment file:
cp .env.example .env
Adjust the
.env
file according to your local configuration if necessary. -
Start the application using Docker (optional): If you have Docker installed, you can start the application and its dependencies using Docker Compose:
docker-compose up -d --build
-
Access the application: Open your browser and navigate to
http://chat.local:8082
(or the configured APP_URL).
To interact with the API, you can use tools like Postman or curl.
Here are the available API endpoints for the chat application:
- URL:
POST /groups
- Description: Creates a new chat group.
- Request Body:
{ "name": "Group Name", "user_id": 123 }
- Responses:
201 Created
: Group created successfully.422 Unprocessable Entity
: Validation error details.
- URL:
GET /groups
- Description: Retrieves a paginated list of chat groups.
- Query Parameters:
page
(optional): Page number for pagination, default is1
.limit
(optional): Number of items per page, default is10
.
- Responses:
200 OK
: List of groups with pagination.
- URL:
POST /groups/{id}/members
- Description: Joins a specified group by group ID.
- Request Body:
{ "user_id": 123 }
- Responses:
200 OK
: Successfully joined group.409 Conflict
: User is already a member.404 Not Found
: Group not found.
- URL:
POST /groups/{id}/messages
- Description: Sends a message to a specified group by group ID.
- Request Body:
{ "user_id": 123, "message": "Hello, everyone!" }
- Responses:
201 Created
: Message sent successfully.404 Not Found
: Group or user not found.
- URL:
GET /groups/{id}/messages
- Description: Retrieves all messages in a specified group by group ID.
- Query Parameters:
page
(optional): Page number for pagination, default is1
.limit
(optional): Number of items per page, default is10
.
- Responses:
200 OK
: List of messages in the group with pagination.
To run the tests for the application, use the following command:
composer test
Ensure you have PHPUnit installed as a development dependency.
This project adheres to the PSR-12 coding standard. You can check the code quality using PHP_CodeSniffer:
composer code-style
For static analysis, you can use PHPStan:
composer stan
This project is open-source and available under the MIT License.