{"id":39146040,"url":"https://github.com/sourcecode081017/im-chat-golang-react","last_synced_at":"2026-01-17T21:35:24.092Z","repository":{"id":288645878,"uuid":"968326526","full_name":"sourcecode081017/im-chat-golang-react","owner":"sourcecode081017","description":"An Instant messaging application written in Go lang and React","archived":false,"fork":false,"pushed_at":"2025-04-19T01:48:44.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-19T06:57:47.914Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcecode081017.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-17T22:21:52.000Z","updated_at":"2025-04-18T18:22:55.000Z","dependencies_parsed_at":"2025-04-20T12:16:25.019Z","dependency_job_id":null,"html_url":"https://github.com/sourcecode081017/im-chat-golang-react","commit_stats":null,"previous_names":["sourcecode081017/im-chat-golang-react"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sourcecode081017/im-chat-golang-react","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcecode081017%2Fim-chat-golang-react","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcecode081017%2Fim-chat-golang-react/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcecode081017%2Fim-chat-golang-react/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcecode081017%2Fim-chat-golang-react/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcecode081017","download_url":"https://codeload.github.com/sourcecode081017/im-chat-golang-react/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcecode081017%2Fim-chat-golang-react/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28518628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-17T18:55:29.170Z","status":"ssl_error","status_checked_at":"2026-01-17T18:55:03.375Z","response_time":85,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-17T21:35:23.414Z","updated_at":"2026-01-17T21:35:24.079Z","avatar_url":"https://github.com/sourcecode081017.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# im-chat-golang-react\n\nAn Instant messaging application written in Go lang and React with WebSocket support, real-time messaging, and channel-based communication.\n\n## Features\n\n✅ **WebSocket Communication**: Real-time bidirectional communication between clients and server  \n✅ **User Management**: Create and manage users with UUID-based identification  \n✅ **Direct Messaging**: Send messages directly between users  \n✅ **Channel Support**: Create and subscribe to channels for group communication  \n✅ **Automatic Subscriber Management**: Channel creators are automatically added as subscribers  \n✅ **PostgreSQL Database**: Persistent storage with GORM ORM  \n✅ **Transaction Safety**: Database operations use transactions for data consistency  \n✅ **RESTful API**: Clean API endpoints for all operations  \n\n## Tech Stack\n\n### Backend\n- **Go** - Primary programming language\n- **Gin** - HTTP web framework\n- **Gorilla WebSocket** - WebSocket implementation\n- **GORM** - ORM for database operations\n- **PostgreSQL** - Primary database\n- **Docker** - Containerization\n\n### Database Schema\n\n#### Users Table\n- `id` (primary key)\n- `created_at`, `updated_at`, `deleted_at`\n- `username` (unique, not null)\n- `user_uuid` (UUID, unique, not null)\n- `email` (optional, unique)\n- `first_name`, `last_name` (optional)\n\n#### Channels Table\n- `id` (primary key)\n- `created_at`, `updated_at`, `deleted_at`\n- `channel_uuid` (UUID, unique, indexed)\n- `name` (required)\n- `description` (optional)\n- `created_by` (user UUID)\n\n#### Channel Subscribers (Join Table)\n- `channel_id` (foreign key to channels.id)\n- `user_id` (foreign key to users.id)\n\n#### Chat Messages Table\n- `id` (primary key)\n- `sender_id` (UUID, not null, indexed)\n- `recipient_id` (UUID, not null, indexed)\n- `content` (text, not null)\n- `message_type` (default: 'direct')\n\n## Getting Started\n\n### Prerequisites\n- Go 1.21 or higher\n- PostgreSQL\n- Docker (optional)\n\n### Environment Variables\n\nCreate a `.env` file in the `server` directory:\n\n```env\nPG_HOST=localhost\nPG_PORT=5432\nPG_USER=your_username\nPG_PASSWORD=your_password\nPG_DB=chat_db\n```\n\n### Running with Docker\n\n```bash\ncd server\ndocker-compose up\n```\n\n### Running Locally\n\n1. Install dependencies:\n```bash\ncd server\ngo mod download\n```\n\n2. Run the server:\n```bash\ngo run main.go\n```\n\nThe server will start on `http://localhost:8080`\n\n## API Documentation\n\n### User Endpoints\n\n#### Create a User\n**POST** `/user`\n\n```json\n{\n  \"username\": \"john_doe\",\n  \"email\": \"john@example.com\",\n  \"firstName\": \"John\",\n  \"lastName\": \"Doe\"\n}\n```\n\n**Response:**\n```json\n{\n  \"message\": \"User john_doe created successfully\"\n}\n```\n\n#### Get All Users\n**GET** `/users`\n\n**Response:**\n```json\n{\n  \"users\": [\n    {\n      \"ID\": 1,\n      \"username\": \"john_doe\",\n      \"userId\": \"550e8400-e29b-41d4-a716-446655440000\",\n      \"email\": \"john@example.com\",\n      \"firstName\": \"John\",\n      \"lastName\": \"Doe\"\n    }\n  ]\n}\n```\n\n### Channel Endpoints\n\n#### Create a Channel\n**POST** `/channel`\n\nCreates a new channel and automatically adds the creator as a subscriber.\n\n**Request:**\n```json\n{\n  \"name\": \"General Discussion\",\n  \"description\": \"A channel for general discussions\",\n  \"createdBy\": \"550e8400-e29b-41d4-a716-446655440000\"\n}\n```\n\n**Response (200 OK):**\n```json\n{\n  \"message\": \"Channel General Discussion created successfully\",\n  \"channel\": {\n    \"ID\": 1,\n    \"CreatedAt\": \"2026-01-03T10:00:00Z\",\n    \"UpdatedAt\": \"2026-01-03T10:00:00Z\",\n    \"channelId\": \"660e8400-e29b-41d4-a716-446655440000\",\n    \"name\": \"General Discussion\",\n    \"description\": \"A channel for general discussions\",\n    \"createdBy\": \"550e8400-e29b-41d4-a716-446655440000\",\n    \"subscribers\": [\n      {\n        \"ID\": 1,\n        \"username\": \"john_doe\",\n        \"userId\": \"550e8400-e29b-41d4-a716-446655440000\"\n      }\n    ]\n  }\n}\n```\n\n**Error Responses:**\n- `400 Bad Request` - Invalid input or missing createdBy field\n- `500 Internal Server Error` - Failed to create channel (e.g., user not found)\n\n**Notes:**\n- The `createdBy` user must exist in the database before creating a channel\n- Channel creator is automatically added to the subscribers list\n- Channel creation is performed in a database transaction for atomicity\n\n#### Get a Channel\n**GET** `/channel/:channelId`\n\nRetrieves a channel by its UUID along with all its subscribers.\n\n**Response:**\n```json\n{\n  \"channel\": {\n    \"ID\": 1,\n    \"channelId\": \"660e8400-e29b-41d4-a716-446655440000\",\n    \"name\": \"General Discussion\",\n    \"description\": \"A channel for general discussions\",\n    \"subscribers\": [...]\n  }\n}\n```\n\n#### Get User's Channels\n**GET** `/user/:userId/channels`\n\nRetrieves all channels that a user is subscribed to.\n\n**Response:**\n```json\n{\n  \"channels\": [\n    {\n      \"ID\": 1,\n      \"channelId\": \"660e8400-e29b-41d4-a716-446655440000\",\n      \"name\": \"General Discussion\",\n      \"subscribers\": [...]\n    }\n  ]\n}\n```\n\n### Message Endpoints\n\n#### Get Messages Between Users\n**GET** `/messages/:userId/:recipientId`\n\nRetrieves all messages exchanged between two users, ordered by creation time.\n\n**Response:**\n```json\n{\n  \"messages\": [\n    {\n      \"senderId\": \"550e8400-e29b-41d4-a716-446655440000\",\n      \"recipientId\": \"660e8400-e29b-41d4-a716-446655440000\",\n      \"content\": \"Hello!\",\n      \"messageType\": \"direct\"\n    }\n  ]\n}\n```\n\n### WebSocket Endpoint\n\n#### Connect to WebSocket\n**GET** `/connect/:clientId`\n\nUpgrades HTTP connection to WebSocket for real-time communication.\n\n**WebSocket Message Format:**\n```json\n{\n  \"type\": \"message\",\n  \"content\": \"Hello, World!\",\n  \"channelId\": \"channel-uuid\",\n  \"recipientId\": \"user-uuid\",\n  \"senderId\": \"sender-uuid\"\n}\n```\n\n### Health Check\n\n#### Health Check\n**GET** `/health`\n\n**Response:**\n```json\n{\n  \"status\": \"UP\"\n}\n```\n\n## Example Usage with cURL\n\n### Create a User\n```bash\ncurl -X POST http://localhost:8080/user \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"username\": \"john_doe\",\n    \"email\": \"john@example.com\",\n    \"firstName\": \"John\",\n    \"lastName\": \"Doe\"\n  }'\n```\n\n### Create a Channel\n```bash\ncurl -X POST http://localhost:8080/channel \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"General Discussion\",\n    \"description\": \"A channel for general discussions\",\n    \"createdBy\": \"550e8400-e29b-41d4-a716-446655440000\"\n  }'\n```\n\n### Get a Channel\n```bash\ncurl http://localhost:8080/channel/660e8400-e29b-41d4-a716-446655440000\n```\n\n### Get User's Channels\n```bash\ncurl http://localhost:8080/user/550e8400-e29b-41d4-a716-446655440000/channels\n```\n\n### Get All Users\n```bash\ncurl http://localhost:8080/users\n```\n\n### Get Messages Between Users\n```bash\ncurl http://localhost:8080/messages/550e8400-e29b-41d4-a716-446655440000/660e8400-e29b-41d4-a716-446655440000\n```\n\n## Project Structure\n\n```\nim-chat-golang-react/\n├── server/\n│   ├── db/\n│   │   └── postgres/\n│   │       ├── pg_conn.go      # Database connection and migrations\n│   │       └── pg_db.go        # Database query methods\n│   ├── models/\n│   │   └── models.go           # Data models (User, Channel, Message)\n│   ├── websocket/\n│   │   ├── ws_server.go        # WebSocket server and HTTP handlers\n│   │   ├── ws_client.go        # WebSocket client management\n│   │   └── ws_hub.go           # WebSocket hub for broadcasting\n│   ├── main.go                 # Application entry point\n│   ├── go.mod\n│   ├── go.sum\n│   ├── Dockerfile\n│   ├── docker-compose.yaml\n│   └── .env\n└── README.md\n```\n\n## Architecture\n\n### WebSocket Server\n- Handles WebSocket connections and upgrades\n- Manages client connections through a Hub\n- Routes messages to appropriate recipients\n- Persists messages to the database\n\n### Database Layer\n- Uses GORM for object-relational mapping\n- Implements repository pattern for data access\n- Supports transactions for complex operations\n- Auto-migrates database schema on startup\n\n### Models\n- **User**: User account information\n- **Channel**: Group communication channels with many-to-many relationship to users\n- **ChatMessage**: Persistent message storage\n- **Message**: Wire format for WebSocket communication\n\n## Development\n\n### Building the Application\n```bash\ncd server\ngo build -o chat-server\n```\n\n### Running Tests\n```bash\ngo test ./...\n```\n\n### Code Verification\nThe codebase has been verified to compile successfully with no errors.\n\n## Future Enhancements\n\n- [ ] Add endpoint to add/remove subscribers from a channel\n- [ ] Add endpoint to list all channels\n- [ ] Add pagination for channel and message lists\n- [ ] Add search/filter functionality for channels and users\n- [ ] Add channel permissions/roles (admin, moderator, member)\n- [ ] Add WebSocket events for channel subscriptions\n- [ ] Implement message read receipts\n- [ ] Add file/image sharing capabilities\n- [ ] Implement user presence (online/offline status)\n- [ ] Add authentication and authorization (JWT)\n- [ ] Build React frontend\n\n## License\n\nThis project is licensed under the terms specified in the LICENSE file.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcecode081017%2Fim-chat-golang-react","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcecode081017%2Fim-chat-golang-react","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcecode081017%2Fim-chat-golang-react/lists"}