Leadsmart
  1. Docs
Leadsmart
  • API Reference
  • Docs
    • LeadSmart API Documentation
    • Services
    • Middleware
    • Integrations
    • Database
    • Architecture
  • Authentication
    • Register
      POST
    • Update User
      PATCH
    • Login
      POST
    • Logout
      POST
    • Reset Password
      POST
    • Change Email
      POST
    • Request Password Reset
      POST
    • Request Email Change
      POST
    • Verify Email
      GET
  • Companies
    • Create Company
      POST
    • Join Company
      POST
    • Get All User Company
      GET
    • Get user Company
      GET
    • Update Company
      PATCH
    • Deactivate Company
      PATCH
    • Activate Company
      PATCH
    • Reset Invite Code
      PATCH
  • Members
    • Create a Member
      POST
    • Get All Member
      GET
    • Get Single Member
      GET
    • Update Member
      PATCH
    • Deactivate Member
      PATCH
    • Activate Member
      PATCH
  • Agendas
    • Create Company Agenda
    • Get All Agendas
    • Get Single Agenda
    • Get Agenda with Appoint
    • Get Available Slots
    • Update Agenda
    • Delete Agenda
    • Activate Agenda
    • Create Agenda Integration
    • Delete Agenda Integration
  • Appointments
    • Create Appointment
    • Get All Appointments
    • Get Appointment
    • Add Members
    • Delete Members
    • Update Appointment
    • Update Date
  • Plans
    • Get Single Plan
    • Get All Plans
    • Create Plan
    • Delete Plan
    • Update Plan
  • Plans Duration
    • Get Single Plan Duration
    • Create Plan Duration
    • Delete Plan Duration
    • Update Plan Duration
  • Company Roles
    • Get Single Company Role
    • Get All Company Roles
    • Create Company Role
    • Delete Company Role
    • Update Company Role
  • Clients
    • Get All Clients
    • Create Client
    • Get Client By Id
    • Update Client
    • Delete Client
  • Client Threads
    • Get All By Client
    • Get All By Instance
    • Create Client Thread
    • Get Client By Id
    • Update Client
    • Delete Client Thread
  • Admin
    • Get All Plans Duration
    • Get All Plans
    • Create Plan
    • Get All Members
    • Get All Companies
  • Chatwoot Accounts
    • Get Chatwoot Account
    • Update Chatwoot Account
    • Delete Chatwoot Account
    • Create Chatwoot Account
  • Integrations
    • Tokens
      • Fetch All Tokens
      • Fetch Token
      • Update Token
      • Remove Token
    • Google
      • Create Auth URL
      • Regenerate Auth URL
      • Renew Google Webhook
    • External Calendar
      • Create External Event
      • Update External Event
      • Delete External Event
      • Validate Calendar Id
      • Fetch External Calendars
  • Messaging
    • Instances
      • Create Instance
      • Get All Instance
      • Get Instance
      • Update Instance
      • Connect Instance
      • Disconnect Instance
      • Activate Instance
      • Deactivate Instance
    • Message
      • Send Message
  • AI Keys
    • Get All AI Keys
    • Get AI Keys By ID
    • Create AI Key
    • Update AI Key
    • Delete AI Key
  • Agent Prompts
    • Get All Agent Prompts
    • Get Agent Prompt By ID
    • Create Agent Prompt
    • Update Agent Prompt
    • Delete Agent Prompt
  • Agent Configuration
    • Get All Agent Configurations
    • Get Agent Configuration By ID
    • Create Agent Configuration
    • Update Agent Configuration
    • Delete Configuration Prompt
  • Agent Prompt Versions
    • Get All Agent Prompt Versions
    • Get Agent Prompt Version By ID
    • Create Agent Prompt Version
    • Update Agent Prompt Version
    • Delete Agent Prompt Version
  1. Docs

Architecture

System Architecture#

LeadSmart API follows a layered architecture pattern with clear separation of concerns:
┌─────────────────┐
│    API Layer    │ Routes, Request Validation
├─────────────────┤
│ Controller Layer│ Business Logic Coordination
├─────────────────┤
│  Service Layer  │ Core Business Logic
├─────────────────┤
│    Data Layer   │ Database Access, Models
└─────────────────┘

Layers#

1.
API Layer: Routes and request validation using Zod schemas
2.
Controller Layer: Coordinates business logic and handles HTTP responses
3.
Service Layer: Core business logic implementation
4.
Data Layer: Database models and data access using Sequelize

Project Structure#

src/
├── configs/        # Application configuration
├── controllers/    # Request handlers
├── database/       # Database models and migrations
├── exceptions/     # Custom error classes
├── integrations/   # External service integrations
├── jobs/           # Scheduled tasks and cron jobs
├── messaging/      # Messaging service implementations
├── middlewares/    # Express middlewares
├── responses/      # Standardized response formatters
├── routes/         # API route definitions
├── schemas/        # Request validation schemas
├── services/       # Business logic services
├── types/          # TypeScript type definitions
└── utils/          # Utility functions

Key Components#

Express Application#

The main Express application is configured in src/configs/app.ts with middleware setup and security configurations.

Database#

The application uses PostgreSQL with Sequelize ORM. The database models are defined in src/database/models/ and represent the application's data entities.

Authentication#

User authentication is handled using JWT (JSON Web Tokens) with refresh token functionality for extended sessions.

Job Scheduling#

Scheduled tasks are managed using node-cron, including:
Google Calendar webhook renewal
WhatsApp connection health checks
Database connection health checks

Messaging#

The application integrates with WhatsApp for messaging capabilities, managed through the @whiskeysockets/baileys library.

Error Handling#

A centralized error handling middleware (errorHandler.middleware.ts) processes all application errors and returns standardized error responses.

Request Flow#

1.
Request Received: Express route handles incoming request
2.
Middleware Processing: Authentication, rate limiting, etc.
3.
Request Validation: Zod schemas validate request data
4.
Controller Processing: Controller method orchestrates business logic
5.
Service Execution: Service methods perform core business operations
6.
Database Interaction: Sequelize models handle data persistence
7.
Response Formatting: Standardized response is returned to client
Modificado em 2025-04-24 22:32:06
Página anterior
Database
Próxima página
Register
Built with