Skip to content

Refactor backend into modular clean architecture for Socket.IO - #1

Open
APK-Arjun-Developer wants to merge 1 commit into
mainfrom
codex/refactor-node.js-project-for-scalability-and-maintainability
Open

Refactor backend into modular clean architecture for Socket.IO#1
APK-Arjun-Developer wants to merge 1 commit into
mainfrom
codex/refactor-node.js-project-for-scalability-and-maintainability

Conversation

@APK-Arjun-Developer

Copy link
Copy Markdown
Owner

Motivation

  • Replace the single-file socket server anti-pattern with a maintainable, testable modular architecture following Clean/Layered principles.
  • Separate transport, business logic, and persistence to make the codebase easier to extend and harder to entangle.
  • Provide a clear composition root and shared utilities for consistent validation, error handling and logging across socket handlers.
  • Prepare the code for production hardening and horizontal scaling (adapter-ready design).

Description

  • Reorganized the project under src/ and added a composition entrypoint src/main.ts with socket/register-handlers.ts wiring Auth, Group, and Chat modules.
  • Implemented per-feature layers: repositories (src/modules/*/*.repository.ts), services (src/modules/*/*.service.ts) and socket handlers (src/modules/*/*.socket-handler.ts) and centralized session storage in src/socket/socket-context.ts.
  • Added infrastructure and config modules including src/infrastructure/db/sqlite.ts for DB bootstrapping and src/config/env.ts / src/config/logger.ts for environment and logging concerns, and domain types in src/domain/entities.ts.
  • Introduced shared error and validation utilities (src/shared/errors/app-error.ts, src/shared/validation/socket-schemas.ts) and a socket error wrapper src/socket/socket-error-wrapper.ts to standardize error responses; updated package.json scripts and tsconfig.json for the new src layout.
  • Added REFACTOR_GUIDE.md documenting folder structure, layer responsibilities, socket event architecture, before/after example, scaling suggestions and a best-practices checklist.

Testing

  • Ran a TypeScript build with npm run build (invokes tsc -p tsconfig.json) and the build completed successfully.
  • Performed a smoke start by running node dist/main.js, observed the server startup log ([INFO] Server started { port: 3000 }) and terminated the process; the run succeeded as a basic runtime check.
  • The new composition and handlers were exercised by the smoke start; no automated unit/integration tests were added in this change.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant