Skip to content

shylabo/typescript-clean-architecture-api

Repository files navigation

【WIP】typescript-clean-architecture-api

TypeScript-clean-architecture-api

TODO (So many todos are left...)

  • Implement presenter(ViewModel)
  • validation for input
  • test (both unit and e2e)
  • Introduce OpenAPI document(Swagger)
  • Introduce Redis for cache
  • Introduce ORM to handle queries etc...

About this project (Private Chat API with Clean Architecture)

The Private Chat API is a software development project aimed at providing users with a reliable and scalable platform for sending messages in a private chat room. Unlike traditional applications, this project focuses solely on providing the API backend without any frontend user interface.

The API has been developed using the Clean Architecture approach, ensuring a separation of concerns and maintainability. TypeScript, a statically-typed superset of JavaScript, has been chosen as the primary programming language for its strong typing and enhanced tooling support.

To ensure the application's scalability and portability, Docker has been utilized for containerization. This allows for easy deployment and management of the application across different environments, reducing dependency issues and streamlining the deployment process.

For storing basic user information, PostgreSQL has been employed as the database. PostgreSQL is known for its reliability, scalability, and extensive feature set, making it an excellent choice for storing critical user data.

To handle the storage of messages, MongoDB has been chosen. MongoDB is a NoSQL database known for its flexibility and scalability, making it particularly suitable for scenarios where message volume is expected to grow rapidly. By leveraging MongoDB's document-oriented nature, the application can efficiently handle the storage and retrieval of chat messages.

An interesting aspect of this project is the minimal use of libraries. While libraries can provide shortcuts and pre-built functionalities, this project aims to develop custom implementations wherever possible. By doing so, the development team gains a deeper understanding of the underlying concepts and retains full control over the application's behavior.

Architecture tree

src
β”œβ”€β”€ core
β”‚  β”œβ”€β”€ common
β”‚  β”‚  β”œβ”€β”€ ApiResponse.ts
β”‚  β”‚  β”œβ”€β”€ Entity.ts
β”‚  β”‚  β”œβ”€β”€ Exception.ts
β”‚  β”‚  β”œβ”€β”€ StatusCodes.ts
β”‚  β”‚  β”œβ”€β”€ Type.ts
β”‚  β”‚  └── Usecase.ts
β”‚  β”œβ”€β”€ domain
β”‚  β”‚  β”œβ”€β”€ message
β”‚  β”‚  β”‚  β”œβ”€β”€ entity
β”‚  β”‚  β”‚  β”‚  β”œβ”€β”€ Message.ts
β”‚  β”‚  β”‚  β”‚  └── type
β”‚  β”‚  β”‚  β”‚     └── CreateMessageEntityPayload.ts
β”‚  β”‚  β”‚  β”œβ”€β”€ port
β”‚  β”‚  β”‚  β”‚  β”œβ”€β”€ persistence
β”‚  β”‚  β”‚  β”‚  β”‚  └── MessageRepository.ts
β”‚  β”‚  β”‚  β”‚  └── usecase
β”‚  β”‚  β”‚  β”‚     └── GetMessagePort.ts
β”‚  β”‚  β”‚  └── usecase
β”‚  β”‚  β”‚     β”œβ”€β”€ dto
β”‚  β”‚  β”‚     β”‚  └── MessageUseCaseDto.ts
β”‚  β”‚  β”‚     └── GetMessagesUseCase.ts
β”‚  β”‚  └── user
β”‚  β”‚     β”œβ”€β”€ entity
β”‚  β”‚     β”‚  β”œβ”€β”€ type
β”‚  β”‚     β”‚  β”‚  └── CreateUserEntityPayload.ts
β”‚  β”‚     β”‚  └── User.ts
β”‚  β”‚     β”œβ”€β”€ port
β”‚  β”‚     β”‚  β”œβ”€β”€ persistence
β”‚  β”‚     β”‚  β”‚  └── UserRepository.ts
β”‚  β”‚     β”‚  └── usecase
β”‚  β”‚     β”‚     β”œβ”€β”€ CreateUserPort.ts
β”‚  β”‚     β”‚     └── GetUserPort.ts
β”‚  β”‚     └── usecase
β”‚  β”‚        β”œβ”€β”€ CreateUserUsecase.ts
β”‚  β”‚        β”œβ”€β”€ dto
β”‚  β”‚        β”‚  └── UserUseCaseDto.ts
β”‚  β”‚        └── GetUserUseCase.ts
β”‚  └── service
β”‚     β”œβ”€β”€ message
β”‚     β”‚  └── GetMessagesInteractor.ts
β”‚     └── user
β”‚        β”œβ”€β”€ CreateUserInteractor.ts
β”‚        └── GetUserInteractor.ts
β”œβ”€β”€ infrastructure
β”‚  β”œβ”€β”€ config
β”‚  β”‚  β”œβ”€β”€ ApiServerConfig.ts
β”‚  β”‚  └── DatabaseConfig.ts
β”‚  β”œβ”€β”€ database
β”‚  β”‚  β”œβ”€β”€ mongodb
β”‚  β”‚  β”‚  └── DbClient.ts
β”‚  β”‚  β”œβ”€β”€ NosqlDatabaseClient.ts
β”‚  β”‚  β”œβ”€β”€ postgresql
β”‚  β”‚  β”‚  └── DbClient.ts
β”‚  β”‚  └── SqlDatabaseClient.ts
β”‚  β”œβ”€β”€ Logger.ts
β”‚  β”œβ”€β”€ routers
β”‚  β”‚  β”œβ”€β”€ MessageRouter.ts
β”‚  β”‚  β”œβ”€β”€ Router.ts
β”‚  β”‚  └── UserRouter.ts
β”‚  └── Server.ts
β”œβ”€β”€ interfaces
β”‚  β”œβ”€β”€ adapters
β”‚  β”‚  β”œβ”€β”€ CreateMessageAdapter.ts
β”‚  β”‚  β”œβ”€β”€ CreateUserAdapter.ts
β”‚  β”‚  └── GetUserAdapter.ts
β”‚  β”œβ”€β”€ controllers
β”‚  β”‚  β”œβ”€β”€ MessageController.ts
β”‚  β”‚  └── UserController.ts
β”‚  └── gateways
β”‚     β”œβ”€β”€ database
β”‚     β”‚  └── DbClient.ts
β”‚     β”œβ”€β”€ mappers
β”‚     β”‚  β”œβ”€β”€ MessageMapper.ts
β”‚     β”‚  └── UserMapper.ts
β”‚     β”œβ”€β”€ MessageRepository.ts
β”‚     └── UserRepository.ts
└── Main.ts

About

πŸ— Attempt of building maintainable and scalable api employing CleanArchitecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published