A modern, type-safe fullstack chat application built with Effect, featuring real-time messaging, room-based conversations, and user authentication. This monorepo showcases functional programming patterns with Effect while delivering a complete chat experience.
- Real-time Chat: WebSocket-based messaging with instant delivery
- Room-based Conversations: Create and join chat rooms for organized discussions
- User Authentication: Secure JWT-based authentication system
- Invitation System: Invite users to join rooms and conversations
- Type-Safe: Built with TypeScript and Effect for robust error handling
- Functional Architecture: Effect-based services for predictable, testable code
- Database Integration: PostgreSQL with Effect SQL for reliable data persistence
- Modern Frontend: Next.js 15 with React 19 and Tailwind CSS
This monorepo contains the following applications and packages:
@hive/server: Effect-based backend API server with WebSocket support@hive/web: Next.js frontend application with modern UI
@hive/eslint-config: Shared ESLint configurations@hive/typescript-config: Shared TypeScript configurations
- Backend Framework: Effect for functional programming and error handling
- HTTP Server: Effect Platform with Node.js runtime
- Database: PostgreSQL with Effect SQL
- Real-time: WebSocket integration for live messaging
- Frontend: Next.js 15 with React 19
- Styling: Tailwind CSS for modern UI
- Monorepo: Turborepo for efficient development
- Type Safety: TypeScript throughout
- Node.js 18+
- PostgreSQL database
- pnpm package manager
# Clone the repository
git clone <your-repo-url>
cd fullstack-effect-hive
# Install dependencies
pnpm install
# Set up environment variables
cp .env.example .env.localCreate a .env.local file in the root directory:
# Database
DATABASE_URL="postgresql://user:password@localhost:5432/hive_db"
# Server
PORT=3001
JWT_SECRET="your-super-secret-jwt-key-change-this-in-production"
# Frontend (optional, for production builds)
NEXT_PUBLIC_API_URL="http://localhost:3001"# Run database migrations
pnpm --filter @hive/server db:migrate# Start both server and web apps in development mode
pnpm dev
# Or run them separately:
pnpm --filter @hive/server dev # Start the Effect server on port 3001
pnpm --filter @hive/web dev # Start the Next.js app on port 3000
# Build all apps
pnpm build
# Lint all code
pnpm lint
# Type checking
pnpm check-typesThe application follows a clean architecture with Effect-based services:
- Server: Effect HTTP API with WebSocket support for real-time features
- Database: PostgreSQL with Effect SQL for type-safe queries
- Frontend: Next.js with modern React patterns
- Real-time: WebSocket connections for live messaging
The server exposes RESTful endpoints for:
- User management (registration, authentication)
- Room creation and management
- Message handling
- Invitation system
The Next.js frontend connects to the Effect server via:
-
HTTP requests for data operations
-
WebSocket connections for real-time updates
-
JWT-based authentication
if (Effect.isSuccess(result)) { // Login successful, user redirected to dashboard } else { // Handle login error console.error("Login failed:", result.error); } };
### Password Reset
```typescript
import { forgotPasswordRoute } from "@repo/auth/forgot-password-route";
import { resetPasswordRoute } from "@repo/auth/reset-password-route";
// Use in your API routes
export const POST = forgotPasswordRoute;
export const PUT = resetPasswordRoute;
The application uses Effect for functional error handling and side effects throughout:
import { Effect } from "effect";
// All operations are wrapped in Effect for predictable error handling
const userResult = yield * findUserByEmail(email);
// HTTP API with Effect Platform
const api = HttpApi.make("ChatAPI").add(
HttpApiGroup.make("users").add(
HttpApiEndpoint.post("register")`/users`.addSuccess(UserSchema),
),
);
// WebSocket real-time messaging
const realtimeBus = yield * RealtimeBus;
yield * realtimeBus.broadcast(roomId, message);Business logic is organized in service layers with Effect:
// User service with Effect
export const UserService = Effect.gen(function* () {
const db = yield* DatabaseService;
const auth = yield* AuthService;
return {
createUser: (data: UserCreate) =>
Effect.gen(function* () {
// Implementation with proper error handling
}),
authenticateUser: (credentials: LoginCredentials) =>
Effect.gen(function* () {
// JWT token generation and validation
}),
};
});apps/
βββ server/ # Effect-based backend
β βββ src/
β β βββ api/routes/ # HTTP API routes
β β βββ auth/ # Authentication services
β β βββ config/ # Configuration management
β β βββ invitation/ # Invitation system
β β βββ message/ # Message handling
β β βββ realtime/ # WebSocket real-time features
β β βββ room/ # Room management
β β βββ user/ # User services
β β βββ index.ts # Server entry point
β β βββ migrate.ts # Database migrations
β βββ package.json
βββ web/ # Next.js frontend
βββ app/ # Next.js app router
βββ public/ # Static assets
βββ package.json
packages/
βββ eslint-config/ # Shared ESLint configs
βββ typescript-config/ # Shared TypeScript configs
- Database Models: Add SQL schema files in
apps/server/src/*/Model.sql - Services: Implement Effect-based services in respective directories
- API Routes: Add HTTP endpoints in
apps/server/src/api/routes/ - Frontend: Build React components in
apps/web/app/ - Real-time: Extend WebSocket functionality in
apps/server/src/realtime/ - Build: Run
pnpm buildto compile all applications
- UserService: User registration, authentication, and profile management
- RoomService: Chat room creation, membership, and management
- MessageService: Message sending, retrieval, and real-time delivery
- InvitationService: Room invitation creation and acceptance
- AuthService: JWT token generation and validation
- RealtimeBus: WebSocket-based real-time messaging
GET /- Health checkPOST /users- User registrationPOST /auth/login- User authenticationGET /rooms- List user's roomsPOST /rooms- Create new roomGET /rooms/:id/messages- Get room messagesPOST /rooms/:id/messages- Send messagePOST /rooms/:id/invitations- Invite user to room
join-room- Join a chat roomleave-room- Leave a chat roomsend-message- Send a message to roommessage-received- Receive new messages in real-time
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.
- Effect Documentation - Functional programming framework
- Next.js Documentation - React framework
- Tailwind CSS - Utility-first CSS framework
- PostgreSQL - Database
- Turborepo Documentation - Monorepo build system
- WebSocket API - Real-time communication