Skip to content

Implement modular monolith architecture for better code organization and maintainability - #12

Draft
indunil-k with Copilot wants to merge 14 commits into
mainfrom
copilot/fix-11
Draft

Implement modular monolith architecture for better code organization and maintainability#12
indunil-k with Copilot wants to merge 14 commits into
mainfrom
copilot/fix-11

Conversation

Copilot AI commented Aug 16, 2025

Copy link
Copy Markdown

This PR transforms the backend from a traditional layered architecture to a modular monolith architecture, organizing code by business domains rather than technical layers.

Architecture Transformation

Before (Layered Architecture):

src/
├── controllers/    # All controllers mixed together
├── services/       # All services mixed together  
├── routes/         # All routes mixed together
├── validators/     # All validators mixed together
└── middlewares/    # All middlewares mixed together

After (Domain-based Modules):

src/
└── modules/
    ├── user/           # Complete user domain
    ├── category/       # Complete category domain
    ├── provider/       # Complete provider domain
    ├── company/        # Complete company domain
    ├── service/        # Complete service domain
    └── shared/         # Reusable cross-cutting components

Key Changes

1. Domain-based Organization

Each business domain now has its own module containing all related functionality:

  • User Module: Authentication, profiles, user management
  • Category Module: Hierarchical category management
  • Provider Module: Service provider profiles and management
  • Company Module: Company/organization management
  • Service Module: Service listings and management
  • Shared Module: Common utilities, middlewares, types, and error handling

2. Enhanced Type Safety

  • Added comprehensive TypeScript interfaces for each domain
  • Created shared common types and domain-specific types
  • Implemented proper type exports through module index files

3. Centralized Error Handling

  • Created domain-specific error classes extending a base DomainError
  • Implemented centralized error handling middleware
  • Added proper HTTP status code mapping for different error types

4. Repository Pattern Foundation

  • Added repository interfaces for future data access abstraction
  • Prepared foundation for dependency injection and better testability

5. Clean Module Boundaries

Each module follows a consistent structure:

  • index.ts - Clean module exports
  • types.ts - Domain-specific TypeScript interfaces
  • *.controller.ts - HTTP request handling
  • *.service.ts - Business logic
  • *.route.ts - Route definitions
  • *.validator.ts - Input validation schemas

Benefits Achieved

  • Better Separation of Concerns: Code organized by business domain rather than technical function
  • Improved Maintainability: Changes are localized to specific domains
  • Enhanced Testability: Modules can be tested in isolation
  • Scalability Foundation: Individual modules can be extracted into microservices when needed
  • Developer Experience: Better code discoverability and organization
  • Type Safety: Comprehensive TypeScript coverage across all domains

Migration Safety

  • ✅ All existing functionality preserved
  • ✅ Build process working correctly
  • ✅ Import paths updated throughout codebase
  • ✅ No breaking changes to API endpoints
  • ✅ Removed duplicate/typo files (catagory → category)

The modular monolith architecture provides a solid foundation for scaling the application while maintaining clean separation of concerns and clear domain boundaries.

Fixes #11.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • binaries.prisma.sh
    • Triggering command: node scripts/postinstall.js (dns block)
    • Triggering command: node /home/REDACTED/work/backend/backend/node_modules/.bin/prisma -v (dns block)
    • Triggering command: node /home/REDACTED/work/backend/backend/node_modules/.bin/prisma generate (dns block)
  • checkpoint.prisma.io

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI commented Aug 16, 2025

Copy link
Copy Markdown
Author

@indunil-k 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI and others added 2 commits August 16, 2025 16:46
Co-authored-by: indunil-k <161734455+indunil-k@users.noreply.github.com>
Co-authored-by: indunil-k <161734455+indunil-k@users.noreply.github.com>
Copilot AI changed the title [WIP] let's follow modular monolith architecture to ensure modular monolithic architecture. Implement modular monolith architecture for better code organization and maintainability Aug 16, 2025
Copilot AI requested a review from indunil-k August 16, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

let's follow modular monolith architecture to ensure modular monolithic architecture.

4 participants