Skip to content

Instantly share code, notes, and snippets.

@misostack
Last active December 20, 2025 07:21
Show Gist options
  • Select an option

  • Save misostack/baa7797e2a0b201f74d703db8450fdbe to your computer and use it in GitHub Desktop.

Select an option

Save misostack/baa7797e2a0b201f74d703db8450fdbe to your computer and use it in GitHub Desktop.
Clean Architecture

Clean Architecture

image

1. What is architecture?

Architecture is simply a set of attributes about how your code is laid out, organized, and how it interacts with other pieces or layers of the code.

Eg: MVC architecture

2. Layers of Software

Layers, in object oriented programming, are groups of specific classes that perform the similar functions

Usually, layers are broken up by concerns, which is a particular set of function or information. Our concerns can be many, depending on the application, but can include: database interaction, business rules, API interactions, or the view, or UI.

3. Good Architecture

  1. Testable
  2. Easy to Refactor
  3. Possible to Upgrade
  4. Reusable
  5. Less dependencies: Use Dependency Injection, Use Interfaces, not Concrete Classes, Use Adapters

4. Decoupling toolbox

Design Patterns, A Primer : A design pattern is a specific solution to a commonly occurring problem in software development. There are more than twenty three design patterns organized into three categories: Creational, Structural, and Behavioral

1.Factory

An object responsible for instantiating other objects

2.Repository

Not actually a GoF design pattern, this is an object responsible for transitioning data to and from its storage

3.Adapter

An object that encapsulates another object to make it conform to a desired API

4.Strategy

Encapsulates a behavior or a set of behaviors, allowing them to be used interchangeably

@misostack
Copy link
Author

Customers:

  • email - required, unique . Format : email format
  • firstName ( required ), lastName (optional), fullname( computed field )
  • dateOfBirth ( optional - date ). Format: yyyy/mm/dd
  • phoneNumber (optional, unique ) . Format : Vietnam phone number format
  • customerId ( required, unique ) . Format: YYMMDD-UUID
  • createdAt ( datetime, auto generated ). Format : UTC
  • updatedAt( datetime, auto generated ). Format : UTC
  • status ( PENDING, ACTIVE, INACTIVE, ARCHIVED )

@misostack
Copy link
Author

misostack commented Jan 25, 2021

Orders:

  • orderId ( YYMMDD-UUID )
  • createdAt (datetime, auto generated). Format : UTC
  • updatedAt (datetime, auto generated). Format : UTC
  • status ( DRAFT, PENDING, VALIDATED, DELIVERING, DELIVERED, POSTPONE, RETURNED, COMPLETED )
  • customerId ( foreign key )
  • DeliveryDate
  • Note
  • ShippingAddress
  • PaymentStatus ( UNPAID, PAID, CANCELLED )

Product:

  • ProductID
  • Name
  • Price

Order details:

  • ProductID
  • ProductName
  • Quanlity
  • Notes
  • OrderId ( Foreign key )

@misostack
Copy link
Author

misostack commented Jan 25, 2021

Invoices:

  • invoiceId (YYMMDD-UUID)
  • createdAt ( datetime, auto generated). Format : UTC
  • updatedAt ( datetime, auto generated). Format : UTC
  • status ( pending, accepted, cancelled )
  • orderId
  • customerId
  • note
  • payment Status ( unpaid, paid, cancelled )

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