How joaovictormartins05/gympass-node-api works
Project Type and Purpose
• This is a back-end REST API (“full-stack” only on the server side) written in TypeScript.
• It follows a clean/hexagonal architecture with clearly separated layers (HTTP adapters, use-case interactors, repository interfaces/adapters).
• It persists data in PostgreSQL via Prisma ORM and provides user-registration and authentication (plus gyms and check-ins management).
File Structure
• Top-level config: .env.example, docker-compose.yml, prisma/schema.prisma, migrations → indicates a database service in Docker.
• src/http: HTTP layer (controllers + routes).
• src/use-cases: business logic (authenticate, register).
• src/repositories: repository interfaces plus two adapters (in-memory for tests, Prisma for production).
• src/lib/prisma.ts: Prisma client instantiation.
• src/app.ts & src/server.ts: application setup and HTTP server bootstrap.
Main Components
a. HTTP Client (e.g., browser, mobile, Postman)
b. HTTP Server / API Gateway (Express/Fastify instance in src/server.ts)
c. Routing Layer (src/http/routes.ts)
d. Controllers (src/http/controllers/*.ts)
e. Use-Case Interactors (src/use-cases/*.ts)
f. Repository Interfaces (src/repositories/users-repository.ts)
g. Repository Adapters
– In-Memory Adapter (for local tests)
– Prisma Adapter (src/repositories/prisma/*.ts)
h. Prisma Client (src/lib/prisma.ts)
i. PostgreSQL Database (defined via docker-compose and prisma schema)
j. Environment / Config Layer (.env, src/env)
k. Test Harness (authenticate.spec.ts, register.spec.ts) – optional, can be a side component
Relationships and Data Flow
1) Client → sends HTTP request → HTTP Server
2) Server → routes.ts → Controller
3) Controller → calls appropriate Use-Case Interactor
4) Interactor → invokes Repository Interface
5) Repository Interface → at runtime bound to Prisma Adapter → uses Prisma Client → SQL to PostgreSQL
6) Database → returns rows → Prisma Client → Adapter → Interactor → Controller → HTTP response → Client
7) For tests, the same path but Repository Interface bound to In-Memory Adapter
Highlighted Architectural Patterns
• Hexagonal / Clean Architecture (layers with dependency inversion).
• Repository Pattern (abstract persistence behind an interface).
• Adapter Pattern (in-memory vs Prisma).
• Layered Request Flow (Controller → Use Case → Repository → DB).
Essential Details to Capture
– clear component names matching folder names
– two repository adapters (in-memory for test path, Prisma for production)
– Prisma schema and migrations block under the DB
– the flow of authentication tokens or credentials (authenticate.ts)
– environment loading (src/env) injecting DB connection string into Prisma Client