# necipfzlakay/location-logger-api architecture

> Architecture diagram of the GitHub repository necipfzlakay/location-logger-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/necipfzlakay/location-logger-api
- Repository: https://github.com/necipfzlakay/location-logger-api

## Overview

##### Project type and purpose
- This is a backend API built with NestJS.
- It implements a “point-in-polygon” algorithm to tell you whether a given geographic coordinate falls within predefined areas.
- It exposes HTTP endpoints for “areas”, “locations” and “users”.

##### File structure
- Top-level files: Dockerfile, docker-compose.yml, .env, tsconfig, package.json, locust/locustfile.py, README.md.
- src/ contains a standard NestJS module layout:
- app.controller.ts, app.service.ts, app.module.ts, main.ts
- areas/, locations/, users/ each with controller.ts, service.ts, module.ts, DTOs, and entity definitions.
- common/ holds static GeoJSON files (taksim.json, umraniye.json).
- test/ folder holds end-to-end tests.

##### README for additional insights
- Uses Docker Compose to spin up:
- logger-api (NestJS @ port 3333)
- Postgres DB + Adminer (@ port 8080)
- Locust load-tester (@ port 8089)
- Local dev via pnpm.

##### Main components and interactions
a. External Client
- Makes HTTP requests (e.g., via Postman or any HTTP client) to the Logger API.
b. Logger API (NestJS container)
- Controllers (HTTP layer) receive requests.
- Services implement business logic (point-in-polygon, CRUD).
- TypeORM Entities map to DB tables (areas, users, locations).
- common/*.json provide polygon definitions.
c. Database (Postgres container)
- Stores user profiles, location logs, and area records (optional).
- Accessed by the NestJS service via TypeORM.
d. Adminer (Postgres GUI)
- Optional management console.
e. Locust (Load-testing container)
- Simulates load against the Logger API endpoints.

##### Relationships and data flow
- Client → HTTP → NestJS Controller → NestJS Service
→ (if checking location) load geojson → run point-in-polygon
→ persist or read from Postgres via TypeORM Repository → return HTTP Response.
- NestJS Service ↔ Postgres
- Locust → HTTP → NestJS Controller
- Adminer → DB

##### Architectural patterns and design principles
- Modular design (areas, locations, users are separate Nest modules).
- Layered architecture (Controller → Service → Repository/Entity).
- Dependency injection (NestJS DI container).
- Infrastructure as code (Dockerfile + docker-compose.yml).
- Test automation (e2e tests + Locust for performance).

##### Technologies and frameworks
- NestJS (Node.js framework)
- TypeScript
- TypeORM
- Postgres (relational DB) + Adminer
- Docker & Docker Compose
- Locust (Python load testing)
- pnpm (package manager)
- Jest (e2e tests)

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% External Client
  Client["External Client"]:::external

  %% Docker Compose Boundary
  subgraph "Docker Compose"
    direction TB

    %% Logger API Container
    subgraph "Logger API (NestJS @3333)"
      direction TB

      mtt["main.ts"]:::file
      apm["app.module.ts"]:::file
      apc["app.controller.ts"]:::http
      aps["app.service.ts"]:::logic

      subgraph "Modules"
        direction TB

        subgraph "Areas Module"
          direction TB
          a_mod["areas.module.ts"]:::file
          a_ctl["areas.controller.ts"]:::http
          a_srv["areas.service.ts"]:::logic
          a_dto["create-area.dto.ts"]:::file
          a_ent["area.entity.ts"]:::db
        end

        subgraph "Locations Module"
          direction TB
          l_mod["locations.module.ts"]:::file
          l_ctl["locations.controller.ts"]:::http
          l_srv["locations.service.ts"]:::logic
          l_dto["getLocation.dto.ts"]:::file
        end

        subgraph "Users Module"
          direction TB
          u_mod["users.module.ts"]:::file
          u_ctl["users.controller.ts"]:::http
          u_srv["users.service.ts"]:::logic
          u_dto["create-user.dto.ts"]:::file
          u_ent["user.entity.ts"]:::db
        end
      end

      subgraph "Static GeoJSON Data"
        direction TB
        t_json["taksim.json"]:::file
        u_json["umraniye.json"]:::file
      end
    end

    %% Database and Tools
    db["Postgres DB"]:::db
    adm["AdminerGUI (8080)"]:::external
    loc["LocustLoadTester (8089)"]:::external
  end

  %% Data Flows
  Client -->|"HTTP Request"| apc
  apc -->|"calls Service"| aps
  aps -->|"loads GeoJSON"| t_json
  aps -->|"loads GeoJSON"| u_json
  aps -->|"TypeORM ORM"| db
  loc -->|"HTTP Load"| apc
  adm -->|"TCP"| db

  %% Click Events
  click mtt "https://github.com/necipfzlakay/location-logger-api/blob/main/src/main.ts"
  click apm "https://github.com/necipfzlakay/location-logger-api/blob/main/src/app.module.ts"
  click apc "https://github.com/necipfzlakay/location-logger-api/blob/main/src/app.controller.ts"
  click aps "https://github.com/necipfzlakay/location-logger-api/blob/main/src/app.service.ts"
  click a_mod "https://github.com/necipfzlakay/location-logger-api/blob/main/src/areas/areas.module.ts"
  click a_ctl "https://github.com/necipfzlakay/location-logger-api/blob/main/src/areas/areas.controller.ts"
  click a_srv "https://github.com/necipfzlakay/location-logger-api/blob/main/src/areas/areas.service.ts"
  click a_dto "https://github.com/necipfzlakay/location-logger-api/blob/main/src/areas/dto/create-area.dto.ts"
  click a_ent "https://github.com/necipfzlakay/location-logger-api/blob/main/src/areas/entities/area.entity.ts"
  click l_mod "https://github.com/necipfzlakay/location-logger-api/blob/main/src/locations/locations.module.ts"
  click l_ctl "https://github.com/necipfzlakay/location-logger-api/blob/main/src/locations/locations.controller.ts"
  click l_srv "https://github.com/necipfzlakay/location-logger-api/blob/main/src/locations/locations.service.ts"
  click l_dto "https://github.com/necipfzlakay/location-logger-api/blob/main/src/locations/dto/getLocation.dto.ts"
  click u_mod "https://github.com/necipfzlakay/location-logger-api/blob/main/src/users/users.module.ts"
  click u_ctl "https://github.com/necipfzlakay/location-logger-api/blob/main/src/users/users.controller.ts"
  click u_srv "https://github.com/necipfzlakay/location-logger-api/blob/main/src/users/users.service.ts"
  click u_dto "https://github.com/necipfzlakay/location-logger-api/blob/main/src/users/dto/create-user.dto.ts"
  click u_ent "https://github.com/necipfzlakay/location-logger-api/blob/main/src/users/entities/user.entity.ts"
  click t_json "https://github.com/necipfzlakay/location-logger-api/blob/main/src/common/taksim.json"
  click u_json "https://github.com/necipfzlakay/location-logger-api/blob/main/src/common/umraniye.json"
  click db "https://github.com/necipfzlakay/location-logger-api/blob/main/docker-compose.yml"
  click adm "https://github.com/necipfzlakay/location-logger-api/blob/main/docker-compose.yml"
  click loc "https://github.com/necipfzlakay/location-logger-api/blob/main/locust/locustfile.py"

  %% Styles
  classDef external fill:#d3d3d3,stroke:#888,stroke-width:1px;
  classDef http fill:#d8b3ff,stroke:#a85fcf,stroke-width:1px;
  classDef logic fill:#b3ffb3,stroke:#3fa83f,stroke-width:1px;
  classDef db fill:#b3d9ff,stroke:#3f88a8,stroke-width:1px;
  classDef file fill:#ffffff,stroke:#666,stroke-width:1px;
```
