Hackmate Server
HackMate Server Backend API server for HackMate - A terminal-based social network for developers and hackers. Tech Stack - Framework: Fastify (Node.js) - Database: MongoDB (with Mo...
Technical Architecture & Engineering Overview
Detailed system design and core implementation
The system is organized into three concentric layers. The API layer (src/api/controllers and src/api/routes) handles HTTP request routing, delegating to core services (core/services/*.service.ts) that encapsulate business rules such as authentication, matching, profile management, chat handling, network interactions, project lifecycle, group coordination, and notification processing. All services are pure TypeScript classes injected into controllers, enabling isolated unit testing.
The infrastructure layer (infrastructure/*) provides adapters for external resources: MongoDB models (infrastructure/database/models), Redis client configuration, and a dedicated Socket.IO service (infrastructure/socket/socket.service.ts). This layer abstracts persistence and real‑time messaging, allowing the core to remain agnostic of implementation details.
Data flow follows a clear path: client → Fastify → route → controller → service → repository/model → database. Validation occurs early using Zod schemas defined in shared/validators, guaranteeing type safety before business logic execution. Errors are funneled through a global error handler that normalizes validation errors, MongoDB duplicate key conflicts, JWT failures, and unexpected exceptions into consistent HTTP responses.
Security guardrails include Helmet for HTTP header hardening, CORS configuration, rate limiting via express-rate-limit (adapted for Fastify), and JWT verification middleware applied to all non‑auth routes. Passwords are hashed with Argon2, and OTP email verification leverages a centralized EmailService.
The build topology uses a standard TypeScript compilation pipeline (npm run build) producing JavaScript output consumed by src/start.ts. Development mode (npm run dev) employs hot‑reload, while production runs the compiled bundle with environment‑driven configuration. Health checks (GET /health) and a root status endpoint provide operational visibility.
System Diagrams & Flow Visualizations
Interactive Mermaid architecture & execution flows
Core System Features
Key capabilities & architectural features
Secure JWT + Argon2 authentication with email OTP verification
Secure JWT + Argon2 authentication with email OTP verification
User profile management with skills, bio, and social links
User profile management with skills, bio, and social links
Real‑time direct and group chat powered by Socket.IO
Real‑time direct and group chat powered by Socket.IO
Friend/network system with follow, request, accept, reject, and block actions
Friend/network system with follow, request, accept, reject, and block actions
Project posting, application workflow, and applicant management
Project posting, application workflow, and applicant management
Group creation, joining, invitation handling, and moderation
Group creation, joining, invitation handling, and moderation
Notification system with read/unread tracking and push via WebSocket
Notification system with read/unread tracking and push via WebSocket
Comprehensive admin panel for user, message, group, project, and activity management
Comprehensive admin panel for user, message, group, project, and activity management
Rate limiting, CORS, and Helmet security hardening
Rate limiting, CORS, and Helmet security hardening
Centralized Zod schema validation ensuring type‑safe request payloads
Centralized Zod schema validation ensuring type‑safe request payloads
Engineering Challenges & Solutions
Problem statements & resolution strategies
Balancing RESTful API design with real‑time Socket.IO events required careful event naming and idempotency handling
Balancing RESTful API design with real‑time Socket.IO events required careful event naming and idempotency handling
Managing MongoDB schema evolution without migrations introduced complexity in versioned data models
Managing MongoDB schema evolution without migrations introduced complexity in versioned data models
Ensuring JWT token revocation for logout scenarios while maintaining statelessness
Ensuring JWT token revocation for logout scenarios while maintaining statelessness
Configuring rate limiting that protects against abuse without degrading legitimate traffic
Configuring rate limiting that protects against abuse without degrading legitimate traffic
Scaling Socket.IO connections in a serverless or containerized environment demands external session stores and load‑balancer sticky sessions
Scaling Socket.IO connections in a serverless or containerized environment demands external session stores and load‑balancer sticky sessions
API Reference & Endpoints
REST API surface & route documentation
| METHOD | ENDPOINT PATH | DESCRIPTION | COPY |
|---|---|---|---|
| GET | /users | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /users/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /users/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| PUT | /users/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /stats | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /messages | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /messages/user/:userId | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /messages/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /groups | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /groups/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /groups/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /projects | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /projects/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /projects/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /friend-requests | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /friend-requests/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /notifications | Endpoint defined in src/api/routes/admin.routes.ts | |
| DELETE | /notifications/:id | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /activity | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /search | Endpoint defined in src/api/routes/admin.routes.ts | |
| GET | /history/:userId | Endpoint defined in src/api/routes/chat.routes.ts | |
| GET | /history/group/:groupId | Endpoint defined in src/api/routes/chat.routes.ts | |
| GET | /conversations | Endpoint defined in src/api/routes/chat.routes.ts | |
| POST | / | Endpoint defined in src/api/routes/group.routes.ts | |
| GET | / | Endpoint defined in src/api/routes/group.routes.ts | |
| GET | /:id | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /:id/join | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /:id/accept | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /:id/reject | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /:id/kick | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /:id/leave | Endpoint defined in src/api/routes/group.routes.ts | |
| POST | /request | Endpoint defined in src/api/routes/network.routes.ts | |
| GET | /requests | Endpoint defined in src/api/routes/network.routes.ts | |
| POST | /accept | Endpoint defined in src/api/routes/network.routes.ts | |
| POST | /reject | Endpoint defined in src/api/routes/network.routes.ts | |
| GET | /friends | Endpoint defined in src/api/routes/network.routes.ts | |
| POST | /block | Endpoint defined in src/api/routes/network.routes.ts | |
| DELETE | /friend/:userId | Endpoint defined in src/api/routes/network.routes.ts | |
| POST | /:id/read | Endpoint defined in src/api/routes/notification.routes.ts | |
| POST | /:id/apply | Endpoint defined in src/api/routes/project.routes.ts | |
| DELETE | /:id | Endpoint defined in src/api/routes/project.routes.ts | |
| GET | /health | Endpoint defined in src/app.ts |
Key Code Modules & Architecture
Core file entrypoints and service responsibilities
scriptsModule component managing scripts source logic
srcModule component managing src source logic
src/apiModule component managing api source logic
src/api/controllersModule component managing controllers source logic
src/api/routesModule component managing routes source logic
src/configModule component managing config source logic
src/coreModule component managing core source logic
src/core/servicesModule component managing services source logic
src/infrastructure/database/modelsModule component managing models source logic
src/typesModule component managing types source logic
src/shared/utilsModule component managing utils source logic
User Journey Pipeline
- 1User Access & Preset Selection: User opens client interface and configures request parameters or task workflow presets.
- 2Client Payload Dispatch: Front-end components (React) serialize input objects and send HTTP/WebSocket requests to `/users`.
- 3Middleware & Validation Check: API Gateway evaluates CORS headers, authorization tokens, and input validation schemas.
- 4Service & Inference Execution: Service controllers dispatch request frames to model inference engine (Local Engine) or storage layer.
- 5Response Delivery & State Synchronization: Serialized output payload is returned to the client and rendered in the visual workspace.
Execution Code Flow
- 1Client or caller initiates request to application entrypoint
- 2Backend router validates request parameters and applies middleware
- 3Database ORM/client executes storage query
- 4Application serializes JSON/audio/data response back to client
System FAQ & Technical Specifications
Frequently asked questions and core architecture details
Q: What technologies are used in Hackmate Server?
Hackmate Server is engineered using modern full-stack frameworks.
Q: What core engineering problem does Hackmate Server solve?
HackMate Server Backend API server for HackMate - A terminal-based social network for developers and hackers. Tech Stack - Framework: Fastify (Node.js) - Database: MongoDB (with Mo...
Q: How is 'Balancing RESTful API design with real‑time Socket.IO events required careful event naming and idempotency handling' resolved in Hackmate Server?
Resolved through specialized system architecture and resilient state handling.
Related Systems & Case Studies
Explore similar technical architectures and projects