How supritha-kamalanathan/self-tech works
Project Overview & Purpose
• This project is a comprehensive backend system designed to manage connections between homeless individuals, old age homes, and volunteers.
• It offers RESTful APIs (implemented in TypeScript using Node.js and TSOA) that facilitate operations such as authentication, contributions, encounters, and transfers.
• The system uses a PostgreSQL database and enforces business logic through models, controllers, and DTOs.
Main Components
a. API Layer:
• Entry Point (app.ts): Represents the entry to your application and holds the Express server initialization.
• Controllers: Located in src/controllers, these include authController, contributionController, encounterController, homelessPersonController, oldAgeHomeController, transferController, and volunteerController. Each controller maps to REST endpoints for their respective entities.
• Routing: The auto-generated routes via TSOA, managed in src/routes.ts, based on TSOA configuration (tsoa.json) and integrated Swagger documentation (swagger.json).
b. Data Handling & Business Logic:
• DTOs: In src/dtos, these provide data validation and ensure type safety for incoming requests and outgoing responses.
• Models & Database Access:
• Models in src/models contain database access helpers (e.g., ContributionDbAccessHelper, EncounterDbAccessHelper, etc.) that encapsulate SQL query execution.
• SQL files are organized in src/models/sql, detailing queries (e.g. addContribution.sql, addEncounter.sql) and the migration script in src/models/migrations.
• Common Utilities: src/common holds configuration files (configs.ts) and database initialization/connection logic (db.ts).
c. Documentation & Developer Tools:
• Swagger Documentation: Generated swagger.json is used with Swagger UI to present the API interface.
• TSOA & TypeScript configuration: Files like tsconfig.json and tsoa.json enforce coding guidelines and automatically generate routes and API documentation.
Relationships & Data Flow
• The server hands off requests to the appropriate Controller based on route definitions.
• Controllers then interact with the Models layer:
• They call the respective DbAccessHelpers in the models to perform SQL operations.
• Additionally, include the DTOs in the data flow between Controllers and Models to represent data validation and transformation.
Architectural Patterns & Design Principles
• Separation of Concerns: Each component (Controllers, Models, DTOs, and Configs) has a distinct responsibility.
• DTO Pattern: Emphasize how data received from API endpoints is validated and transformed before database operations.
• Dependency Management: Showcase how TSOA auto-generates routes and how Swagger UI integrates to provide documentation.
• Modularity: Demonstrate how each controller is dedicated to a specific domain (e.g., volunteer, homeless person) and how models abstract direct SQL interactions.
Detailed Component Breakdown
• External Client:
• Server & Routing:
• “app.ts (Express Server)” as the starting point.
• "Route Definitions (src/routes.ts)" indicating TSOA auto-generated routes.
• Controllers Layer:
• Business Logic & DTOs:
• Transformation process through DTOs before proceeding to database models.
• Data Access & Persistence:
• Individual DbAccessHelpers (e.g., ContributionDbAccessHelper, VolunteerDbAccessHelper) and indicate connection to the SQL files and migration scripts.
• Documentation & Tools:
• “Swagger UI (swagger.json)” linked to the API and TSOA’s outputs.
• Mention “TSOA Configuration (tsoa.json)” and “TypeScript Configuration (tsconfig.json)” near the routing and controllers parts for context.