Dev.to WebDev 🛠 Dev 👁 0 📖 9 min read

Building a CRM with React and NestJS: Lessons from Developing KineCRM

Building a CRM with React and NestJS: Lessons from Developing KineCRM Building a CRM (Customer Relationship Management) application is an interesting challenge for any software developer. At first, it might look like a

Building a CRM with React and NestJS: Lessons from Developing KineCRM

Building a CRM with React and NestJS: Lessons from Developing KineCRM

Building a CRM (Customer Relationship Management) application is an interesting challenge for any software developer. At first, it might look like a simple application where users can add leads, save contact details, and manage customers. But once you start developing a real CRM, you quickly discover that there is much more involved.

You need to think about database structure, user permissions, sales workflows, API development, data relationships, background jobs, and a user interface that people can use every day.

While working on KineCRM, a CRM software platform designed to help businesses manage leads, contacts, and customer relationships, we have been exploring these challenges through practical development.

In this article, I'll share some of the technical considerations involved in building a CRM application using React, NestJS, PostgreSQL, and Prisma.

Whether you are planning to build your own CRM software or simply want to understand how a full-stack business application works, I hope these lessons will be useful.

1. Why Build a CRM Application?

Businesses receive enquiries from different sources. Some customers contact them through websites, others through social media, phone calls, referrals, or direct enquiries.

When all this information is managed manually, it becomes difficult to keep track of everything.

For example:

  • A sales representative forgets to follow up with a potential customer.
  • Customer contact information is stored in different spreadsheets.
  • Managers cannot easily see the progress of sales activities.
  • Multiple employees contact the same lead without knowing about each other.
  • Important customer conversations and meeting details get lost.

A CRM application helps organize this information in one place.

From a development perspective, building a CRM is also a good opportunity to work with different areas of software engineering, including relational databases, authentication, authorization, REST APIs, frontend state management, and background processing.

2. Choosing the Right Technology Stack

Before starting development, choosing a suitable technology stack is important.

For KineCRM, the application architecture uses the following technologies.

Frontend: React

React is used to build the user interface.

A CRM usually contains many screens, including:

  • Dashboard
  • Lead management
  • Contact management
  • Account management
  • Task management
  • Call and meeting activities
  • User management
  • Settings

React makes it easier to organize these screens into reusable components.

For example, instead of creating a separate table implementation for every module, developers can build reusable table components that support different datasets.

This approach helps maintain consistency and makes future changes easier.

Backend: NestJS

NestJS is used to develop the backend APIs.

One reason NestJS is useful for larger applications is its modular architecture.

Instead of putting all application logic into a single controller or service, we can organize functionality into separate modules.

For example:

  • Leads module
  • Contacts module
  • Accounts module
  • Users module
  • Tasks module
  • Authentication module
  • Notifications module

Each module can have its own controllers, services, validation, and business logic.

This structure makes the backend easier to understand and maintain as the application grows.

Database: PostgreSQL

A CRM application stores a lot of related information.

A lead may belong to a user, contain contact information, have multiple activities, and eventually become associated with an account.

PostgreSQL is a suitable choice for this kind of relational data.

It supports relationships, constraints, transactions, indexing, and other database features that are useful for business applications.

ORM: Prisma

Prisma helps manage database models and interact with PostgreSQL from the NestJS backend.

It provides a schema-based approach to defining models and relationships.

For example, a simplified lead model could look like this:

model Lead {
    id          String   @id @default(uuid())
    firstName   String
    lastName    String?
    email       String?
    phone       String?
    company     String?
    status      String
    createdAt   DateTime @default(now())
    updatedAt   DateTime @updatedAt

    ownerId     String
    owner       User     @relation(fields: [ownerId], references: [id])
}

This is a simplified example, but it demonstrates how a lead can be connected to its owner.

Using Prisma also makes it easier to maintain database models as the application evolves.

3. Designing the Database for a CRM

Database design is one of the most important parts of building CRM software.

A poorly designed database can create problems later when new features are introduced.

For example, storing all customer information, sales activities, and user details in a single table might seem convenient initially. However, it becomes difficult to maintain when the application grows.

A better approach is to divide the information into separate related models.

Leads

A lead represents a potential customer who has shown interest in a product or service.

Common lead fields include:

  • First name
  • Last name
  • Email address
  • Phone number
  • Company name
  • Lead source
  • Lead status
  • Priority
  • Assigned user

Lead sources can include website enquiries, referrals, social media, direct enquiries, and other channels.

Contacts

Contacts represent people with whom a business maintains a relationship.

Unlike leads, contacts may represent customers or people associated with an existing business relationship.

A contact can be connected to an account and assigned to a particular CRM user.

Accounts

Accounts represent organizations or businesses.

For example, if a company works with multiple customers, each customer organization can have its own account record.

Contacts can then be associated with the relevant account.

Activities

Activities help sales teams manage their daily work.

Examples include:

  • Tasks
  • Calls
  • Meetings
  • Follow-up reminders

Separating activities from leads and contacts makes it easier to display upcoming and completed activities across different CRM modules.

The main lesson here is simple: design the database around the actual business relationships instead of only thinking about individual screens.

4. Building REST APIs with NestJS

Once the database structure is ready, the next step is building APIs.

The frontend needs APIs to create, read, update, and delete CRM records.

For example, a lead management module may contain endpoints such as:

GET    /leads
GET    /leads/:id
POST   /leads
PATCH  /leads/:id
DELETE /leads/:id

Each endpoint should have a clear responsibility.

Use DTOs for Request Validation

Data validation is important in business applications.

For example, when creating a lead, the backend should validate the request before saving it.

NestJS provides DTOs and validation tools that help enforce these rules.

A simplified DTO could look like this:

import { IsEmail, IsOptional, IsString } from 'class-validator';

export class CreateLeadDto {
    @IsString()
    firstName: string;

    @IsOptional()
    @IsEmail()
    email?: string;

    @IsOptional()
    @IsString()
    phone?: string;
}

This helps prevent invalid data from entering the database.

It is also important to validate data on the backend even when the frontend already performs validation.

Frontend validation improves the user experience, while backend validation protects the application.

5. Implementing User Roles and Permissions

One of the more interesting challenges in CRM development is user access management.

Not every employee should have access to every record or operation.

For example:

  • An administrator may manage users and settings.
  • A sales manager may view team leads.
  • A sales representative may manage assigned leads.
  • Some users may only have permission to view specific modules.

A simple role-based access control system can help manage these requirements.

Instead of checking only whether a user is an administrator, permissions can be defined for individual modules.

For example:

Module View Create Edit Delete
Leads Yes Yes Yes No
Contacts Yes Yes Yes No
Users Yes No No No
Settings Yes No No No

This is only an example of a permission configuration.

In a real application, permissions should be checked on the backend for every protected operation. Hiding a button in React is not sufficient security.

A useful approach is to create reusable authorization logic so that permission checks remain consistent across different modules.

6. Managing Sales Activities

A CRM is not only about storing customer information.

It should also help users understand what needs to be done next.

Imagine a sales representative has 50 leads. Simply displaying those leads in a table does not tell them which customer needs attention today.

This is where activities become useful.

A CRM can connect tasks, calls, and meetings with leads or contacts.

For example:

  • Call a potential customer tomorrow.
  • Schedule a product demonstration.
  • Follow up after a meeting.
  • Send a reminder before an appointment.

Displaying upcoming and overdue activities can help users organize their work.

A useful dashboard can show:

  • Today's activities
  • Overdue tasks
  • Upcoming meetings
  • Open leads
  • Recently created contacts

The goal is to help users take action instead of simply storing information.

7. Building Reusable React Components

CRM applications contain many screens with similar interface elements.

For example, leads, contacts, and accounts may all need:

  • Search
  • Filters
  • Pagination
  • Sorting
  • Data tables
  • Create and edit forms
  • Status badges
  • Action buttons

Creating these components separately for every module increases development time and makes maintenance harder.

Reusable components provide a better solution.

For example, a reusable data table can accept:

  • Column definitions
  • Data
  • Loading state
  • Pagination information
  • Sorting configuration
  • Row actions

The same component can then be used across multiple CRM modules.

This reduces duplicated code and creates a consistent user experience.

However, reusable components should remain flexible. A component that tries to handle every possible situation can become harder to maintain than separate, focused components.

8. Handling Background Jobs with BullMQ

Some operations should not block the main API request.

Consider importing thousands of leads from a CSV file.

Processing every row during a normal HTTP request can take too long and create performance problems.

A better approach is to use background jobs.

BullMQ, together with Redis, can help process these tasks asynchronously.

A typical workflow looks like this:

  1. The user uploads a CSV file.
  2. The backend validates the file.
  3. The import request is added to a queue.
  4. A background worker processes the records.
  5. The system tracks import progress.
  6. The user can check the final result.

This approach can also be useful for sending notifications, generating reports, and processing other time-consuming operations.

Background jobs help keep the main application responsive.

9. Real-Time Notifications

Notifications are another useful feature in CRM software.

For example, a sales representative might receive a notification when a lead is assigned to them.

A manager might receive an update when an important sales activity is completed.

Socket.IO can be used to build real-time communication between the backend and frontend.

With NestJS, a WebSocket gateway can handle notification events and send updates to connected users.

However, real-time notifications also require careful attention to authentication and authorization.

Users should only receive notifications intended for them.

It is also useful to store notifications in the database so users can view them later, even if they were offline when the notification was generated.

10. Common Challenges When Building a CRM

Building a CRM has taught us that the difficult parts are often not the basic CRUD operations.

Some of the bigger challenges include:

Managing related data

Leads, contacts, accounts, users, and activities are connected. Maintaining these relationships requires careful database design.

Handling permissions

A multi-user CRM needs a reliable permission system. Access should be checked consistently across API endpoints.

Keeping the interface consistent

When multiple modules share similar functionality, reusable components help maintain a consistent experience.

Handling large datasets

As records increase, pagination, database indexing, efficient queries, and background processing become important.

Planning for future features

A CRM grows over time. Its architecture should allow new modules and integrations without requiring a complete rewrite.

These challenges are useful lessons for anyone building a SaaS application or a business management platform.

11. What Comes Next?

A CRM is never really a finished product. Businesses continue to change, and their requirements evolve.

There are many areas that can be improved over time:

  • Better sales reporting and analytics
  • More advanced lead filtering
  • Automated follow-up workflows
  • Calendar integrations
  • Improved notification management
  • External service integrations
  • Better data import and export tools

The important thing is to build these features around actual user requirements rather than adding functionality simply because it sounds interesting.

Conclusion

Building a CRM with React, NestJS, PostgreSQL, and Prisma involves much more than creating a few forms and database tables.

It requires thoughtful database design, a maintainable backend architecture, secure user permissions, reusable frontend components, and reliable ways to manage business activities.

Working on KineCRM has been an opportunity to explore these areas while developing a practical CRM platform for managing leads, contacts, and customer relationships.

If you are also building a SaaS application, my biggest suggestion is to start with a clear database structure, keep your modules organized, and make security and maintainability part of the development process from the beginning.

I'd also love to hear from other developers:

What has been the most challenging part of building a CRM or another business management application?

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.