# supritha-kamalanathan/self-tech architecture

> Architecture diagram of the GitHub repository supritha-kamalanathan/self-tech, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/supritha-kamalanathan/self-tech
- Repository: https://github.com/supritha-kamalanathan/self-tech

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Layer
    A["API Consumer / Postman"]:::external
    B["App Entry (app.ts)"]:::entry
    C["Routing (src/routes.ts)"]:::api

    A -->|"HTTP_Request"| B
    B -->|"Initializes"| C

    %% Controllers Layer
    subgraph "Controllers Layer"
        D1["Auth Controller"]:::controller
        D2["Contribution Controller"]:::controller
        D3["Encounter Controller"]:::controller
        D4["HomelessPerson Controller"]:::controller
        D5["OldAgeHome Controller"]:::controller
        D6["Transfer Controller"]:::controller
        D7["Volunteer Controller"]:::controller
    end

    C -->|"Routes_to"| D1
    C -->|"Routes_to"| D2
    C -->|"Routes_to"| D3
    C -->|"Routes_to"| D4
    C -->|"Routes_to"| D5
    C -->|"Routes_to"| D6
    C -->|"Routes_to"| D7

    %% Business Logic Layer - DTOs
    E["Data Transfer Objects (DTOs)"]:::dto
    D1 -->|"Validates"| E
    D2 -->|"Validates"| E
    D3 -->|"Validates"| E
    D4 -->|"Validates"| E
    D5 -->|"Validates"| E
    D6 -->|"Validates"| E
    D7 -->|"Validates"| E

    %% Data Access Layer
    subgraph "Data Access Layer"
        F1["ContributionDbAccessHelper"]:::model
        F2["EncounterDbAccessHelper"]:::model
        F3["HomelessPersonDbAccessHelper"]:::model
        F4["OldAgeHomeDbAccessHelper"]:::model
        F5["TransferDbAccessHelper"]:::model
        F6["VolunteerDbAccessHelper"]:::model
    end

    E -->|"Calls"| F1
    E -->|"Calls"| F2
    E -->|"Calls"| F3
    E -->|"Calls"| F4
    E -->|"Calls"| F5
    E -->|"Calls"| F6

    G["SQL Query Files (src/models/sql)"]:::sql
    H["Database Migrations (src/models/migrations)"]:::sql

    F1 -->|"Executes_SQL"| G
    F2 -->|"Executes_SQL"| G
    F3 -->|"Executes_SQL"| G
    F4 -->|"Executes_SQL"| G
    F5 -->|"Executes_SQL"| G
    F6 -->|"Executes_SQL"| G

    G -->|"Applies_Migrations"| H

    I["PostgreSQL Database"]:::db
    H --> I
    G --> I

    J["Common Utilities & Configuration (src/common)"]:::config
    J --> I

    %% Documentation & Tools
    subgraph "Documentation & Tools"
        K["Swagger Documentation (swagger.json)"]:::doc
        L["TSOA Configuration (tsoa.json)"]:::config
        M["TypeScript Configuration (tsconfig.json)"]:::config
    end

    C -->|"Integrates_with"| L
    C -->|"Documents_via"| K
    K -->|"Supports"| M

    %% Click Events
    click B "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/app.ts"
    click C "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/routes.ts"
    click D1 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/authController.ts"
    click D2 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/contributionController.ts"
    click D3 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/encounterController.ts"
    click D4 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/homelessPersonController.ts"
    click D5 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/oldAgeHomeController.ts"
    click D6 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/transferController.ts"
    click D7 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/controllers/volunteerController.ts"
    click E "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/dtos/types.ts"
    click F1 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/ContributionDbAccessHelper.ts"
    click F2 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/EncounterDbAccessHelper.ts"
    click F3 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/HomelessPersonDbAccessHelper.ts"
    click F4 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/OldAgeHomeDbAccessHelper.ts"
    click F5 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/TransferDbAccessHelper.ts"
    click F6 "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/models/volunteerDbAccessHelper.ts"
    click G "https://github.com/supritha-kamalanathan/self-tech/tree/master/src/models/sql"
    click H "https://github.com/supritha-kamalanathan/self-tech/tree/master/src/models/migrations"
    click J "https://github.com/supritha-kamalanathan/self-tech/tree/master/src/common"
    click K "https://github.com/supritha-kamalanathan/self-tech/blob/master/src/swagger.json"
    click L "https://github.com/supritha-kamalanathan/self-tech/blob/master/tsoa.json"
    click M "https://github.com/supritha-kamalanathan/self-tech/blob/master/tsconfig.json"

    %% Styles
    classDef external fill:#FFCCCC,stroke:#CC0000,stroke-width:2px;
    classDef entry fill:#CCE5FF,stroke:#0047AB,stroke-width:2px;
    classDef api fill:#E6FFE6,stroke:#008000,stroke-width:2px;
    classDef controller fill:#FFFFCC,stroke:#FFD700,stroke-width:2px;
    classDef dto fill:#FFEECC,stroke:#FF8C00,stroke-width:2px;
    classDef model fill:#D1C4E9,stroke:#673AB7,stroke-width:2px;
    classDef sql fill:#FFE0E0,stroke:#FF0000,stroke-width:2px;
    classDef db fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef doc fill:#E0F7FA,stroke:#0097A7,stroke-width:2px;
    classDef config fill:#F0F4C3,stroke:#9E9D24,stroke-width:2px;
```
