How spacebarchat/server works
Main Components
The system architecture should be divided into four main server components:
a. HTTP API Server (src/api)
• Entry point: src/api/Server.ts
• REST endpoints organized by resource types (users, guilds, channels, etc.)
• Middleware chain (Authentication, CORS, RateLimit, etc.)
b. WebSocket Gateway Server (src/gateway)
• Entry point: src/gateway/Server.ts
• Event handling system
• Opcodes handling (Heartbeat, Identify, etc.)
• Connection management
c. CDN Server (src/cdn)
• Entry point: src/cdn/Server.ts
• File storage systems (FileStorage, S3Storage)
• Asset routes (attachments, avatars, etc.)
d. Utility and Database Layer (src/util)
• Entity models
• Database migrations
• Shared utilities
External Integrations
Connections to:
• Multiple database types (PostgreSQL, MySQL, MariaDB)
• External services (email providers, OAuth connections)
• Storage systems (local/S3)
Key Relationships and Flows
a. Client Communication Flow:
• Client → API Server (REST calls)
• Client ↔ Gateway Server (WebSocket)
• Client → CDN Server (Asset requests)
b. Internal Communication:
• API Server ↔ Database
• Gateway Server ↔ Database
• CDN Server ↔ Storage Systems
Authentication and Security Layer
• Authentication middleware
• Rate limiting
• CORS handling
• MFA systems (TOTP, WebAuthn)
Feature Modules
Related components:
• User Management
• Guild/Server Management
• Messaging Systems
• Voice/WebRTC
• OAuth2/Applications
Data Flow Patterns
• Real-time communication (WebSocket)
• REST API calls
• File transfers
• Database operations
Scaling Components
Areas that can be horizontally scaled:
• API servers
• Gateway nodes
• CDN endpoints
• Database clusters
Supporting Systems
Auxiliary components:
• Email service integration
• Translation/localization system
• Configuration management
• Migration handling
• Rectangles for services
• Clouds for external services
• Hexagons for security components
Remember to:
• Related components visually
• Primary and secondary data flows
• Scalability points
• Security boundaries
• External service dependencies
This architecture should emphasize the project's goal of being a drop-in replacement for Discord's backend while maintaining compatibility with existing clients and bots.