|
| 1 | +# Collab Platform |
| 2 | + |
| 3 | +A microservices-based collaboration platform with real-time chat, authentication, and workspace management. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +This is a monorepo containing multiple services and shared libraries: |
| 8 | + |
| 9 | +### Services |
| 10 | + |
| 11 | +- **auth** - Authentication service (Fastify + Prisma + PostgreSQL) |
| 12 | +- **chat** - Real-time chat service (Fastify + WebSocket + RabbitMQ + Redis) |
| 13 | +- **storage** - File storage service |
| 14 | +- **analytics** - Analytics service |
| 15 | + |
| 16 | +### Libraries |
| 17 | + |
| 18 | +- **@collab/prisma** - Shared Prisma client with database models |
| 19 | +- **@collab/plugins** - Shared plugins (Prometheus metrics) |
| 20 | +- **@collab/events** - Event envelope types |
| 21 | +- **@collab/types** - Shared TypeScript types |
| 22 | +- **@collab/redis-utils** - Redis utilities and key helpers |
| 23 | + |
| 24 | +## Tech Stack |
| 25 | + |
| 26 | +- **Runtime**: Node.js |
| 27 | +- **Framework**: Fastify |
| 28 | +- **Database**: PostgreSQL (via Prisma) |
| 29 | +- **Message Queue**: RabbitMQ |
| 30 | +- **Cache**: Redis |
| 31 | +- **Metrics**: Prometheus |
| 32 | +- **TypeScript**: Full type safety across services |
| 33 | +- **Monorepo**: Yarn workspaces |
| 34 | + |
| 35 | +## Getting Started |
| 36 | + |
| 37 | +### Prerequisites |
| 38 | + |
| 39 | +- Node.js 18+ |
| 40 | +- Docker & Docker Compose |
| 41 | +- PostgreSQL |
| 42 | +- Redis |
| 43 | +- RabbitMQ |
| 44 | + |
| 45 | +### Installation |
| 46 | + |
| 47 | +```bash |
| 48 | +# Install dependencies |
| 49 | +yarn install |
| 50 | + |
| 51 | +# Generate Prisma clients |
| 52 | +yarn workspace @collab/prisma prisma:generate |
| 53 | + |
| 54 | +# Start infrastructure (PostgreSQL, Redis, RabbitMQ) |
| 55 | +docker-compose -f infra/docker/docker-compose.yml up -d |
| 56 | + |
| 57 | +# Set up environment variables |
| 58 | +cp .env.example .env |
| 59 | +# Edit .env with your configuration |
| 60 | + |
| 61 | +# Run migrations |
| 62 | +yarn workspace @collab/prisma prisma:migrate dev |
| 63 | +``` |
| 64 | + |
| 65 | +### Development |
| 66 | + |
| 67 | +```bash |
| 68 | +# Run auth service |
| 69 | +yarn workspace auth dev |
| 70 | + |
| 71 | +# Run chat service |
| 72 | +yarn workspace chat dev |
| 73 | +``` |
| 74 | + |
| 75 | +### Environment Variables |
| 76 | + |
| 77 | +Each service requires specific environment variables. See `.env.example` files in each service directory. |
| 78 | + |
| 79 | +**Common variables:** |
| 80 | + |
| 81 | +- `DATABASE_URL` - PostgreSQL connection string |
| 82 | +- `REDIS_URL` - Redis connection string |
| 83 | +- `RABBITMQ_URL` - RabbitMQ connection string |
| 84 | +- `JWT_SECRET` - Secret for JWT token signing |
| 85 | +- `REFRESH_SECRET` - Secret for refresh tokens |
| 86 | + |
| 87 | +## Features |
| 88 | + |
| 89 | +### Authentication Service |
| 90 | + |
| 91 | +- User registration and login |
| 92 | +- JWT-based authentication |
| 93 | +- Refresh token rotation |
| 94 | +- Rate limiting |
| 95 | +- Prometheus metrics |
| 96 | + |
| 97 | +### Chat Service |
| 98 | + |
| 99 | +- Real-time WebSocket messaging |
| 100 | +- Channel-based chat |
| 101 | +- Message replay on reconnect |
| 102 | +- Typing indicators |
| 103 | +- Read receipts |
| 104 | +- RabbitMQ message distribution |
| 105 | +- Redis offset tracking |
| 106 | + |
| 107 | +## Project Structure |
| 108 | + |
| 109 | +``` |
| 110 | +collab-platform/ |
| 111 | +├── libs/ # Shared libraries |
| 112 | +│ ├── prisma/ # Database client and schemas |
| 113 | +│ ├── plugins/ # Fastify plugins (metrics) |
| 114 | +│ ├── events/ # Event types |
| 115 | +│ ├── types/ # TypeScript types |
| 116 | +│ └── redis-utils/ # Redis utilities |
| 117 | +├── services/ # Microservices |
| 118 | +│ ├── auth/ # Authentication service |
| 119 | +│ ├── chat/ # Chat service |
| 120 | +│ ├── storage/ # Storage service |
| 121 | +│ └── analytics/ # Analytics service |
| 122 | +├── infra/ # Infrastructure configs |
| 123 | +│ └── docker/ # Docker compose and configs |
| 124 | +└── tsconfig/ # TypeScript configurations |
| 125 | +``` |
| 126 | + |
| 127 | +## Metrics |
| 128 | + |
| 129 | +All services expose Prometheus metrics at `/metrics`: |
| 130 | + |
| 131 | +- HTTP request duration and counts |
| 132 | +- WebSocket connection metrics |
| 133 | +- RabbitMQ message metrics |
| 134 | +- Database query metrics |
| 135 | +- Authentication metrics |
| 136 | +- Custom business metrics |
| 137 | + |
| 138 | +## API Documentation |
| 139 | + |
| 140 | +### Auth Service (`/auth`) |
| 141 | + |
| 142 | +- `POST /register` - Register new user |
| 143 | +- `POST /login` - User login |
| 144 | +- `POST /refresh` - Refresh access token |
| 145 | +- `POST /logout` - Logout user |
| 146 | +- `GET /me` - Get current user |
| 147 | +- `GET /health` - Health check |
| 148 | +- `GET /metrics` - Prometheus metrics |
| 149 | + |
| 150 | +### Chat Service (`/chat`) |
| 151 | + |
| 152 | +- `GET /ws` - WebSocket connection endpoint |
| 153 | +- `GET /channels/:id/messages` - Get channel messages |
| 154 | +- `GET /health` - Health check |
| 155 | +- `GET /metrics` - Prometheus metrics |
| 156 | + |
| 157 | +## Development Guidelines |
| 158 | + |
| 159 | +1. **Type Safety**: All code is TypeScript with strict mode enabled |
| 160 | +2. **Code Style**: Follow existing patterns and use ESLint |
| 161 | +3. **Testing**: Write tests for new features |
| 162 | +4. **Documentation**: Update README and add JSDoc comments |
| 163 | +5. **Commits**: Use conventional commit messages |
| 164 | + |
| 165 | +## License |
| 166 | + |
| 167 | +MIT |
0 commit comments