# martromeros/r.d.a-server architecture

> Architecture diagram of the GitHub repository martromeros/r.d.a-server, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/martromeros/r.d.a-server
- Repository: https://github.com/martromeros/r.d.a-server

## Overview

##### Project type and purpose
- This is a monolithic, backend-only REST API server written in TypeScript using Express.
- It uses Prisma as an ORM to manage a relational database, and it includes authentication endpoints plus an email-sending service.

##### File structure
- Top‐level:
- docker-compose.yml – for bringing up related services (e.g., database)
- prisma/ – holds your schema and migration history
- src/ – all application code
- package.json, tsconfig.json – build and dependency definitions
- Within src/:
- server.ts & app.ts – Express app and HTTP server setup
- routes/ – defines route → controller mappings
- controllers/ – handle HTTP requests/responses
- services/ – business logic, external integrations (e.g., mail)
- models/ – TypeScript interfaces and Prisma model wrappers

##### Extract README insights
- “npm run dev” spins up ts-node in watch mode
- “npm run build” + “npm start” produce and run compiled JS
- Prisma is initialized and migrations are applied via “npx prisma init”

##### Main components
a. Clients (e.g., frontends or API consumers)
b. HTTP Server (Express)
c. Routing Layer (src/routes)
d. Controllers (src/controllers/auth.controller.ts, actividad.controller.ts)
e. Service Layer (src/services/authServices.ts, mailServices.ts)
f. ORM Layer (Prisma Client via src/models and schema.prisma)
g. Database (PostgreSQL, MySQL, etc. managed by docker‐compose)
h. External Email Service (SMTP, SendGrid, etc.)

##### Relationships and data flows
1. Client → HTTP Server (Express)
2. Server → Router (matches URL & HTTP method)
3. Router → Controller
4. Controller → Service (business logic)
5. Service → Prisma Client → Database (CRUD)
6. Service → External Email Service → Mail Provider
7. Service returns result → Controller → HTTP Response → Client

##### Architectural patterns & design principles
- Layered (Presentation → Controller → Service → Data)
- Single Responsibility per module: controllers only handle web concerns; services only contain business logic
- Prisma provides a clear data‐access abstraction
- Environment isolation via docker‐compose (database container)

##### Essential details to capture
- The entry point (app.ts → server.ts)
- How routes map to controllers
- How controllers delegate to services
- The singular role of Prisma in data access
- The existence of an external mail subsystem
- The database container managed by docker‐compose

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Layers
    classDef http fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef business fill:#90EE90,stroke:#000,stroke-width:1px
    classDef data fill:#FFA500,stroke:#000,stroke-width:1px
    classDef external fill:#DDA0DD,stroke:#000,stroke-width:1px

    %% Client
    Client["API Client"] 

    %% Web Layer
    subgraph "HTTP/Web Layer"
        direction TB
        App["app.ts"]:::http
        Server["server.ts"]:::http
        Router["Auth Routes\n(src/routes/auth.routes.ts)"]:::http
        AuthController["AuthController\n(src/controllers/auth.controller.ts)"]:::http
        ActController["ActividadController\n(src/controllers/actividad.controller.ts)"]:::http
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        direction TB
        AuthService["AuthService\n(src/services/authServices.ts)"]:::business
        MailService["MailService\n(src/services/mailServices.ts)"]:::business
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PrismaSchema["Prisma Schema\n(prisma/schema.prisma)"]:::data
        PrismaMigrations["Prisma Migrations\n(prisma/migrations/*)"]:::data
        ModelActividad["Actividad Model\n(src/models/actividad.ts)"]:::data
        ModelUser["User Model\n(src/models/user.ts)"]:::data
        Interfaces["Interfaces\n(src/models/interfaces.ts)"]:::data
        PrismaClient["Prisma Client"]:::data
    end

    %% Database Container
    Database["Database\n(PostgreSQL)"]:::data

    %% External Systems
    ExternalEmail["External Email Provider"]:::external

    %% Connections
    Client -->|"HTTP Request"| App
    App -->|"initialize"| Server
    Server -->|"route request"| Router
    Router -->|"/auth"| AuthController
    Router -->|"/actividad"| ActController

    AuthController -->|"delegates to"| AuthService
    ActController -->|"delegates to"| AuthService

    AuthService -->|"CRUD via"| PrismaClient
    MailService -->|"send email to"| ExternalEmail

    PrismaClient -->|"reads/writes"| Database

    %% Example mail flow
    AuthService -->|"calls"| MailService

    %% Click Events
    click App "https://github.com/martromeros/r.d.a-server/blob/master/src/app.ts"
    click Server "https://github.com/martromeros/r.d.a-server/blob/master/src/server.ts"
    click Router "https://github.com/martromeros/r.d.a-server/blob/master/src/routes/auth.routes.ts"
    click AuthController "https://github.com/martromeros/r.d.a-server/blob/master/src/controllers/auth.controller.ts"
    click ActController "https://github.com/martromeros/r.d.a-server/blob/master/src/controllers/actividad.controller.ts"
    click AuthService "https://github.com/martromeros/r.d.a-server/blob/master/src/services/authServices.ts"
    click MailService "https://github.com/martromeros/r.d.a-server/blob/master/src/services/mailServices.ts"
    click PrismaSchema "https://github.com/martromeros/r.d.a-server/blob/master/prisma/schema.prisma"
    click PrismaMigrations "https://github.com/martromeros/r.d.a-server/tree/master/prisma/migrations/*"
    click ModelActividad "https://github.com/martromeros/r.d.a-server/blob/master/src/models/actividad.ts"
    click ModelUser "https://github.com/martromeros/r.d.a-server/blob/master/src/models/user.ts"
    click Interfaces "https://github.com/martromeros/r.d.a-server/blob/master/src/models/interfaces.ts"
    click Database "https://github.com/martromeros/r.d.a-server/blob/master/docker-compose.yml"

    %% Styling
    class Client http
    class Server,App,Router,AuthController,ActController http
    class AuthService,MailService business
    class PrismaSchema,PrismaMigrations,ModelActividad,ModelUser,Interfaces,PrismaClient data
    class Database data
    class ExternalEmail external
```
