How liipeee/expense-tracker works
Project type and purpose
• This is a backend REST API (“Expense Tracker”) built with Node.js/TypeScript, following Clean Architecture and Domain-Driven Design (DDD).
• It exposes CRUD endpoints for accounts, categories, contacts, addresses, and transactions, persists to PostgreSQL via Prisma, and uses JWT/Bcrypt for auth.
File structure
• src/presentation: HTTP controllers and DTOs (outermost “Interface” layer).
• src/main: Express adapters, routing, middleware, and factory functions (composition root).
• src/data-layer: Low-level use cases wired to repository ports and error handling (adapter layer).
• src/domain:
• Entities (core business objects)
• Use-case interfaces (application business rules)
• Repository interfaces (ports)
• Framework abstractions (JWT, Bcrypt)
• src/infrastructure:
• Prisma schema and migrations (database)
• Repository implementations (adapters/“driven” components)
• test: Unit tests for data-layer use cases.
Key insights from the README
• Emphasis on Clean Architecture layers: Domain → Application (Use Cases) → Infrastructure → Interface.
• Technologies: Node.js, TypeScript, Express, Prisma ORM, PostgreSQL, JWT, Bcrypt.
Main components
a. Client / HTTP
• HTTP clients (Postman, Frontend)
b. API Layer (Express Server)
• Express Adapter
• Routes & Middlewares
c. Presentation
• Controllers (handle request/response, map to DTOs)
d. Application / Use Cases
• Data-layer Use-Case classes (createAccount, getTransactions, etc.)
• Domain-use-case interfaces
e. Domain Core
• Entities (Account, Transaction, Contact, Category, Address)
• Value Objects & DTOs
• Repository Interfaces (IAcountRepository, ITransactionRepository, etc.)
• Framework Abstractions (JWT, Bcrypt)
f. Infrastructure
• Prisma Client (generated from schema.prisma)
• Repository Implementations (map domain entities ↔ database records)
g. Database
• PostgreSQL (migrations under prisma/migrations)
h. External Services
• JWT service, Bcrypt hashing
Relationships & data flow
• Client → Express Server
• Express Server → Presentation Controllers
• Controllers → Application Use Cases
• Use Cases → Domain Entities & Repository Interfaces
• Repository Interfaces → Infrastructure Repository Implementations
• Repository Implementations → Prisma Client → PostgreSQL
• Errors bubble up via custom error types (ApiError, NotFoundError, etc.)
• JWT/Bcrypt adapters called from Use Cases for auth/encryption
Architectural patterns & principles
• Onion/Clean Architecture: Core Domain at center, interfaces outwards.
• Dependency Inversion: Domain modules define repository interfaces; infrastructure implements them.
• Factory Pattern: Factories in src/main/factories wire controllers to use cases and adapters.
• DTO & Mapper: Presentation layer uses mappers to translate between domain and HTTP DTOs.
• Error Handling: Unified ApiError hierarchy in data-layer.
Detailed elements
• Component names (e.g., CreateTransactionController, CreateTransactionUseCase, TransactionRepository)
• Interfaces vs. implementations (label “ITransactionRepository” vs. “PrismaTransactionRepository”)
• Custom error flow (ApiError classes)