# lightbulb-academy/ims-api architecture

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

- Interactive diagram: https://gitdiagram.com/lightbulb-academy/ims-api
- Repository: https://github.com/lightbulb-academy/ims-api

## Overview

##### Project Type and Purpose
- This is a server-side application built with NestJS. It serves as a backend API, most likely exposing REST endpoints for managing users, organizations, roles, and items, along with an authentication module.
- The application uses Prisma as an ORM for database interactions, indicated by the prisma/ folder and migration files.

##### File Structure
- That the top level contains configuration files (.eslintrc.js, nest-cli.json, tsconfig.json, etc.), which signal development tooling and build configurations.
- The main application code resides in the src directory. Inside this, separate folders (auth, items, organizations, roles, users) indicate a strong adherence to modular design.
- Each module usually contains a controller, service, DTOs, and entity definitions. For example, the users module has files for users.controller.ts, users.service.ts, and corresponding DTOs and entity definitions.
- The existence of a src/prisma folder with prisma.module.ts and prisma.service.ts shows that Prisma is integrated as a dedicated module for database operations.
- Testing is handled under the test directory with both unit and e2e tests.

## Diagram (Mermaid)

```mermaid
graph TD
    Client["Client (API Consumer)"]:::client
    AppModule["App Module"]:::module

    subgraph "API Gateway / Controllers"
        UsersController["Users Controller"]:::controller
        OrgsController["Organizations Controller"]:::controller
        RolesController["Roles Controller"]:::controller
        ItemsController["Items Controller"]:::controller
        AuthController["Auth Controller"]:::controller
    end

    subgraph "Service Layer"
        UsersService["Users Service"]:::service
        OrgsService["Organizations Service"]:::service
        RolesService["Roles Service"]:::service
        ItemsService["Items Service"]:::service
        AuthService["Auth Service"]:::service
    end

    subgraph "Database Access Layer"
        PrismaModule["Prisma Module"]:::module
        PrismaService["Prisma Service"]:::service
        Database["Database"]:::db
        Schema["Database Schema & Migrations"]:::db
    end

    AuthGuard["Authentication Guard"]:::middleware

    %% Connections from Client to Controllers
    Client -->|"HTTP_Request"| UsersController
    Client -->|"HTTP_Request"| OrgsController
    Client -->|"HTTP_Request"| RolesController
    Client -->|"HTTP_Request"| ItemsController
    Client -->|"HTTP_Request"| AuthController

    %% App Module includes components
    AppModule -->|"includes"| UsersController
    AppModule -->|"includes"| OrgsController
    AppModule -->|"includes"| RolesController
    AppModule -->|"includes"| ItemsController
    AppModule -->|"includes"| AuthController
    AppModule -->|"includes"| PrismaModule

    %% Controllers call their respective Services
    UsersController -->|"calls"| UsersService
    OrgsController -->|"calls"| OrgsService
    RolesController -->|"calls"| RolesService
    ItemsController -->|"calls"| ItemsService
    AuthController -->|"calls"| AuthService

    %% Services interact with the Prisma Service
    UsersService -->|"DB_Query"| PrismaService
    OrgsService -->|"DB_Query"| PrismaService
    RolesService -->|"DB_Query"| PrismaService
    ItemsService -->|"DB_Query"| PrismaService
    AuthService -->|"DB_Query"| PrismaService

    %% Prisma Module provides the Prisma Service
    PrismaModule -->|"provides"| PrismaService

    %% Prisma Service interacts with the Database
    PrismaService -->|"queries"| Database
    Database -->|"defined_by"| Schema

    %% Security: Authentication Guard secures controllers (excluding Auth Controller)
    AuthGuard -.->|"secures"| UsersController
    AuthGuard -.->|"secures"| OrgsController
    AuthGuard -.->|"secures"| RolesController
    AuthGuard -.->|"secures"| ItemsController

    %% Click Events
    click UsersController "https://github.com/lightbulb-academy/ims-api/blob/main/src/users/users.controller.ts"
    click OrgsController "https://github.com/lightbulb-academy/ims-api/blob/main/src/organizations/organizations.controller.ts"
    click RolesController "https://github.com/lightbulb-academy/ims-api/blob/main/src/roles/roles.controller.ts"
    click ItemsController "https://github.com/lightbulb-academy/ims-api/blob/main/src/items/items.controller.ts"
    click AuthController "https://github.com/lightbulb-academy/ims-api/blob/main/src/auth/auth.controller.ts"

    click UsersService "https://github.com/lightbulb-academy/ims-api/blob/main/src/users/users.service.ts"
    click OrgsService "https://github.com/lightbulb-academy/ims-api/blob/main/src/organizations/organizations.service.ts"
    click RolesService "https://github.com/lightbulb-academy/ims-api/blob/main/src/roles/roles.service.ts"
    click ItemsService "https://github.com/lightbulb-academy/ims-api/blob/main/src/items/items.service.ts"
    click AuthService "https://github.com/lightbulb-academy/ims-api/blob/main/src/auth/auth.service.ts"

    click PrismaService "https://github.com/lightbulb-academy/ims-api/blob/main/src/prisma/prisma.service.ts"
    click PrismaModule "https://github.com/lightbulb-academy/ims-api/blob/main/src/prisma/prisma.module.ts"
    click Schema "https://github.com/lightbulb-academy/ims-api/blob/main/prisma/schema.prisma"
    click AuthGuard "https://github.com/lightbulb-academy/ims-api/blob/main/src/guards/auth/auth.guard.ts"
    click AppModule "https://github.com/lightbulb-academy/ims-api/blob/main/src/app.module.ts"

    %% Styles
    classDef client fill:#bbf,stroke:#333,stroke-width:2px;
    classDef controller fill:#f7d794,stroke:#333,stroke-width:2px;
    classDef service fill:#b4e7a5,stroke:#333,stroke-width:2px;
    classDef db fill:#f1a7a0,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5;
    classDef module fill:#d4a5a5,stroke:#333,stroke-width:2px;
    classDef middleware fill:#a5d4ff,stroke:#333,stroke-width:2px;
```
