# carljsl/appweb-ipdecti architecture

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

- Interactive diagram: https://gitdiagram.com/carljsl/appweb-ipdecti
- Repository: https://github.com/carljsl/appweb-ipdecti

## Overview

##### Analyzing the File Structure
- **Top-Level Directories and Files:**
- `src/`: Contains the source code, organized into modules such as `auth`, `course`, `enrollment`, and `user`.
- `prisma/`: Holds database migration files and the Prisma schema.
- `test/`: Contains end-to-end tests.
- Configuration files like `.env.template`, `.eslintrc.js`, `.prettierrc`, `nest-cli.json`, `tsconfig.json`.

- **Architectural Patterns:**
- **Modular Architecture:** Each feature (auth, course, enrollment, user) is encapsulated in its own module, following NestJS’s modular design principles.
- **MVC Pattern:** Controllers handle incoming requests, Services contain business logic, and Entities represent the database models.
- **Authentication and Authorization:** Implemented using guards and decorators (`auth.guard.ts`, `roles.guard.ts`, `current-user.decorator.ts`, etc.).

- **Configuration and Deployment:**
- Prisma migrations (`prisma/migrations/`) manage database schema changes.
- Scripts in `package.json` handle building and running the application in different modes.

##### Examining the README for Additional Insights
The README indicates:
- **Framework and Technologies:** Uses NestJS, Node.js, and Prisma.
- **Setup Instructions:** Installation via `npm`, environment setup with `.env.template`, database migrations with Prisma, and commands to run the application in development, watch, and production modes.
- **Continuous Integration:** References to CircleCI for automated builds.

**a. Main Components:**
- **API Gateway:**
- **Controllers:** `auth.controller.ts`, `course.controller.ts`, `enrollment.controller.ts`, `users.controller.ts`

- **Services:**
- **Auth Service:** Handles authentication logic.
- **Course Service:** Manages course-related operations.
- **Enrollment Service:** Manages user enrollments.
- **User Service:** Handles user management.

- **Database Layer:**
- **Prisma ORM:** Interfaces with the database.
- **Entities:** `course.entity.ts`, `enrollment.entity.ts`, etc.

- **Authentication & Authorization:**
- **Guards:** `auth.guard.ts`, `roles.guard.ts`
- **Decorators:** `current-user.decorator.ts`, `roles.decorator.ts`

**b. Relationships and Interactions:**
- **Controllers** receive HTTP requests and delegate to **Services**.
- **Services** perform business logic and interact with **Prisma** for database operations.
- **Auth Guards** protect routes by verifying JWT tokens and user roles.
- **Prisma** manages migrations and schema definitions.

**c. Architectural Patterns and Design Principles:**
- **Modular Design:** Each feature is encapsulated in its own module, promoting separation of concerns.
- **Dependency Injection:** Utilized by NestJS to manage service dependencies.
- **Single Responsibility Principle:** Each service and controller has a clear, distinct responsibility.

**d. Relevant Technologies and Frameworks:**
- **NestJS:** Framework for building scalable server-side applications.
- **Prisma:** ORM for database interactions.
- **TypeScript:** Programming language for type safety.
- **Testing:** End-to-end tests with Jest.

##### Elements
- **Clear Labels:**

- Flow from Controllers to Services to Prisma.
- Authentication flow from Guards to Controllers.

##### Emphasizing Detail and Essential Architectural Elements
That all key components and their interactions are captured without oversimplifying. Separate the project into as many distinct components as necessary to reflect the modular structure, authentication mechanisms, and database interactions accurately.

##### Modules
- **Auth Module:** Includes Auth Controller, Auth Service, Guards, and Decorators.
- **Course Module:** Includes Course Controller and Course Service.
- **Enrollment Module:** Includes Enrollment Controller and Enrollment Service.
- **User Module:** Includes Users Controller and Users Service.

##### Database Layer
- **Prisma ORM:** Connected to all services that require data access.

##### Authentication Flow
- **Auth Guards** intercept requests to secure endpoints.
- **JWT Tokens** are issued and validated for authenticated access.

##### External Services
- **Potential integrations** (if any, based on future expansions).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    
    %% Subgraphs and modules
    subgraph "Auth Module"
        AuthController["Auth Controller"]:::controller
        AuthService["Auth Service"]:::service
        AuthModule["Auth Module"]:::module
    end
    
    subgraph "Course Module"
        CourseController["Course Controller"]:::controller
        CourseService["Course Service"]:::service
        CourseModule["Course Module"]:::module
    end
    
    subgraph "Enrollment Module"
        EnrollmentController["Enrollment Controller"]:::controller
        EnrollmentService["Enrollment Service"]:::service
        EnrollmentModule["Enrollment Module"]:::module
    end
    
    subgraph "User Module"
        UsersController["Users Controller"]:::controller
        UsersService["Users Service"]:::service
        UserModule["User Module"]:::module
    end
    
    subgraph "Prisma"
        PrismaModule["Prisma Module"]:::module
        PrismaService["Prisma Service"]:::service
        PrismaORM["Prisma ORM"]:::database
        PrismaMigrations["Prisma Migrations"]:::database
        PrismaSchema["Prisma ORM Schema"]:::database
    end
    
    subgraph "Authentication"
        AuthGuard["Auth Guard"]:::guard
        RolesGuard["Roles Guard"]:::guard
        CurrentUserDecorator["Current User Decorator"]:::decorator
        RolesDecorator["Roles Decorator"]:::decorator
    end
    
    %% Connections
    AuthController -->|uses| AuthService
    AuthService -->|accesses| PrismaService
    PrismaService -->|interfaces| PrismaORM
    
    CourseController -->|uses| CourseService
    CourseService -->|accesses| PrismaService
    PrismaService -->|interfaces| PrismaORM
    
    EnrollmentController -->|uses| EnrollmentService
    EnrollmentService -->|accesses| PrismaService
    PrismaService -->|interfaces| PrismaORM
    
    UsersController -->|uses| UsersService
    UsersService -->|accesses| PrismaService
    PrismaService -->|interfaces| PrismaORM
    
    AuthController -->|protected by| AuthGuard
    AuthController -->|protected by| RolesGuard
    AuthController -->|utilizes| CurrentUserDecorator
    AuthController -->|utilizes| RolesDecorator
    
    %% Click Events
    click AuthModule "https://github.com/carljsl/appweb-ipdecti/tree/main/src/auth/"
    click AuthController "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/auth.controller.ts"
    click AuthService "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/auth.service.ts"
    click CourseModule "https://github.com/carljsl/appweb-ipdecti/tree/main/src/course/"
    click CourseController "https://github.com/carljsl/appweb-ipdecti/blob/main/src/course/course.controller.ts"
    click CourseService "https://github.com/carljsl/appweb-ipdecti/blob/main/src/course/course.service.ts"
    click EnrollmentModule "https://github.com/carljsl/appweb-ipdecti/tree/main/src/enrollment/"
    click EnrollmentController "https://github.com/carljsl/appweb-ipdecti/blob/main/src/enrollment/enrollment.controller.ts"
    click EnrollmentService "https://github.com/carljsl/appweb-ipdecti/blob/main/src/enrollment/enrollment.service.ts"
    click UserModule "https://github.com/carljsl/appweb-ipdecti/tree/main/src/user/"
    click UsersController "https://github.com/carljsl/appweb-ipdecti/blob/main/src/user/users.controller.ts"
    click UsersService "https://github.com/carljsl/appweb-ipdecti/blob/main/src/user/users.service.ts"
    click PrismaORM "https://github.com/carljsl/appweb-ipdecti/blob/main/prisma/schema.prisma"
    click PrismaMigrations "https://github.com/carljsl/appweb-ipdecti/tree/main/prisma/migrations/"
    click PrismaService "https://github.com/carljsl/appweb-ipdecti/blob/main/src/prisma/prisma.service.ts"
    click PrismaModule "https://github.com/carljsl/appweb-ipdecti/blob/main/src/prisma/prisma.module.ts"
    click AuthGuard "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/guards/auth.guard.ts"
    click RolesGuard "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/guards/roles.guard.ts"
    click CurrentUserDecorator "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/decorators/current-user.decorator.ts"
    click RolesDecorator "https://github.com/carljsl/appweb-ipdecti/blob/main/src/auth/decorators/roles.decorator.ts"
    
    %% Styles
    classDef module fill:#a6cee3,stroke:#333,stroke-width:1px
    classDef controller fill:#1f78b4,stroke:#333,stroke-width:1px, color:#fff
    classDef service fill:#b2df8a,stroke:#333,stroke-width:1px
    classDef database fill:#fdbf6f,stroke:#333,stroke-width:1px
    classDef guard fill:#fb9a99,stroke:#333,stroke-width:1px
    classDef decorator fill:#cab2d6,stroke:#333,stroke-width:1px
    class AuthModule,CourseModule,EnrollmentModule,UserModule,PrismaModule module
    class AuthController,CourseController,EnrollmentController,UsersController controller
    class AuthService,CourseService,EnrollmentService,UsersService,PrismaService service
    class PrismaORM,PrismaMigrations,PrismaSchema database
    class AuthGuard,RolesGuard guard
    class CurrentUserDecorator,RolesDecorator decorator
```
