Home Projects Portfolio Dashboard Export PDF Log in

Scaling Data Entities in the beauty-appointment-system

Designing a booking platform requires robust data modeling, especially when handling dynamic service offerings and time-sensitive schedules. Recently, in the beauty-appointment-system project, we focused on refining our domain entities to support more complex scheduling logic using TypeScript and TypeORM.

The Challenge

Our initial data structures were becoming too tightly coupled. As the system grew, we needed a cleaner separation between service descriptions and their availability blocks. The goal was to move toward a schema that allows services to be independent of specific schedules while remaining queryable through our persistence layer.

Refactoring the Domain

We moved away from monolithic entity definitions to a more modular approach. By splitting the concerns into distinct entities, we improve maintainability and follow the data modeling patterns typical of Hibernate-style ORMs.

@Entity()
export class Service {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @OneToMany(() => Schedule, (schedule) => schedule.service)
  schedules: Schedule[];
}

@Entity()
export class Schedule {
  @PrimaryGeneratedColumn()
  id: number;

  @Column('timestamp')
  startTime: Date;

  @ManyToOne(() => Service, (service) => service.schedules)
  service: Service;
}

This refactoring allows us to easily associate multiple schedule slots with a single service, facilitating better lookups and cleaner queries when checking for available appointments.

The Result

By leveraging the power of decorators in TypeScript with TypeORM, we achieved a declarative way to define relationships. This not only makes the code easier to read but also allows the ORM to manage complex join operations automatically, reducing the boilerplate required to fetch related service data.

Actionable Takeaway

When designing your entity relationships, prioritize decoupling your core business entities from their temporal data. Use one-to-many relationships to manage associated records like schedules or logs, keeping your primary entities lightweight and focused.


Generated with Gitvlg.com

Scaling Data Entities in the beauty-appointment-system
SOFIA DESIREE BARTOLI

SOFIA DESIREE BARTOLI

Author

Share: