# juanospina0409/prueba-tecnica-lite-thinkng architecture

> Architecture diagram of the GitHub repository juanospina0409/prueba-tecnica-lite-thinkng, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/juanospina0409/prueba-tecnica-lite-thinkng
- Repository: https://github.com/juanospina0409/prueba-tecnica-lite-thinkng

## Overview

#### 1. Purpose and deployable entry points
DataSoft Inventory is a multi-service enterprise inventory system: a Next.js UI, Django REST system of record, FastAPI utility service, and reusable Python domain package. Main runtime entries are `backend-django/manage.py`, `microservice-fastapi/main.py`, and the page-router frontend under `frontend-nextjs/src/pages/`. PostgreSQL infrastructure is orchestrated by `docker-compose.yml`.

#### 2. Domain boundary
The domain package isolates business concepts and role validation from HTTP and ORM concerns. It defines Pydantic-oriented `Empresa`, `Producto`, and `Usuario` entities plus authorization rules, intended for reuse by adapters rather than direct persistence.
- `domain-package/domain/entities.py`
- `domain-package/domain/rules.py`
- `domain-package/pyproject.toml`

#### 3. Django system of record
Django owns token authentication, custom users, company/product CRUD, role-based access, and PostgreSQL persistence. Project settings and route composition form the API boundary; the inventory app maps database models to serializers and REST views. The stated API surface is `/api/auth/*`, `/api/empresas/*`, and `/api/productos/*`.
- `backend-django/core/settings.py`
- `backend-django/core/urls.py`
- `backend-django/inventario/models.py`
- `backend-django/inventario/views.py`
- `backend-django/inventario/urls.py`

#### 4. Inventory API flow and authorization
Requests enter Django URL routing, then inventory views apply authentication/role policy, serialize request and model data, and persist to PostgreSQL. Administrators have CRUD authority; external users are read-only. The custom user model is architecturally important because it must be migrated before general database migration.
- `backend-django/inventario/views.py`
- `backend-django/inventario/serializers.py`
- `backend-django/inventario/migrations/0001_initial.py`
- `backend-django/core/settings.py`

#### 5. FastAPI auxiliary-service boundary
FastAPI is independently runnable and exposes report generation, email delivery, AI copy suggestions, and a SHA-256-backed audit ledger. It is a service boundary separate from Django persistence/auth: clients invoke it over HTTP, and it integrates outward with ReportLab, Brevo REST email, and Google Gemini. Its blockchain ledger is described as simplified rather than durable database-backed.
- `microservice-fastapi/main.py`
- `microservice-fastapi/Dockerfile`
- `microservice-fastapi/requirements.txt`

#### 6. Frontend interaction layer
The Next.js Pages Router provides login, company/product administration, inventory reporting, and AI copilot screens. Shared layout/navigation wraps these screens. Browser-side configuration selects Django and FastAPI base URLs, so the frontend calls both backend boundaries directly.
- `frontend-nextjs/src/pages/_app.js`
- `frontend-nextjs/src/pages/login.js`
- `frontend-nextjs/src/pages/inventario.js`
- `frontend-nextjs/src/pages/copiloto.js`
- `frontend-nextjs/src/components/Layout.js`

#### 7. Runtime infrastructure and configuration
PostgreSQL 16 with pgvector is the central durable store, launched through Docker Compose. A root environment file supplies database credentials and external API keys across Docker, Django, and FastAPI; production separates hosting concerns between Render services and Vercel frontend. Django and FastAPI each have container definitions, while local development runs them separately on ports 8000 and 8001, with Next.js on 3000.
- `docker-compose.yml`
- `.env.example`
- `backend-django/Dockerfile`
- `microservice-fastapi/Dockerfile`
- `frontend-nextjs/next.config.js`

Main entry points: [`microservice-fastapi/main.py`](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py) (FastAPI service), [`backend-django/inventario/views.py`](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/views.py) (Inventory views), [`backend-django/inventario/models.py`](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/models.py) (Inventory models), [`docker-compose.yml`](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/docker-compose.yml) (Docker Compose)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_next_pages["Next.js Pages Router<br/>web UI"]
  node_layout["Shared layout<br/>UI shell<br/>[Layout.js]"]
end

subgraph group_django["Django system of record"]
  node_django_routes["Django API routes<br/>REST boundary<br/>[urls.py]"]
  node_inventory_views["Inventory views<br/>REST views<br/>[views.py]"]
  node_serializers["Inventory serializers<br/>serialization<br/>[serializers.py]"]
  node_inventory_models["Inventory models<br/>ORM models<br/>[models.py]"]
  node_django_settings["Django settings<br/>runtime config<br/>[settings.py]"]
end

subgraph group_fastapi["FastAPI auxiliary service"]
  node_fastapi_service["FastAPI service<br/>HTTP service<br/>[main.py]"]
  node_audit_ledger["SHA-256 audit ledger<br/>in-memory ledger<br/>[main.py]"]
  node_external_integrations["Report, email, and AI providers<br/>external APIs<br/>[main.py]"]
end

subgraph group_platform["Platform"]
  node_postgres[("PostgreSQL 16 + pgvector<br/>durable datastore<br/>[docker-compose.yml]")]
  node_compose["Docker Compose<br/>local orchestration<br/>[docker-compose.yml]"]
  node_environment["Shared environment<br/>environment config<br/>[.env.example]"]
  node_django_container["Django container<br/>container image"]
  node_fastapi_container["FastAPI container<br/>container image"]
end

node_domain_entities{{"Domain entities<br/>Python domain package<br/>[entities.py]"}}
node_domain_rules["Authorization rules<br/>domain policy<br/>[rules.py]"]

node_next_pages -->|"wraps screens"| node_layout
node_next_pages -->|"calls REST API"| node_django_routes
node_next_pages -->|"calls utility API"| node_fastapi_service
node_django_routes -->|"routes requests"| node_inventory_views
node_inventory_views -->|"serializes payloads"| node_serializers
node_inventory_views -->|"reads and writes"| node_inventory_models
node_inventory_views -.->|"enforces roles"| node_domain_rules
node_serializers -->|"maps API data"| node_inventory_models
node_inventory_models -->|"persists"| node_postgres
node_django_settings -->|"selects custom user model"| node_inventory_models
node_domain_rules -->|"validates roles for"| node_domain_entities
node_fastapi_service -->|"records audits"| node_audit_ledger
node_fastapi_service -->|"generates and delivers"| node_external_integrations
node_compose -->|"starts"| node_postgres
node_compose -->|"orchestrates"| node_django_container
node_compose -->|"orchestrates"| node_fastapi_container
node_django_container -->|"runs"| node_django_routes
node_fastapi_container -->|"runs"| node_fastapi_service
node_environment -.->|"configures credentials"| node_postgres
node_environment -.->|"supplies settings"| node_django_settings
node_environment -.->|"supplies API keys"| node_fastapi_service

click node_layout "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/frontend-nextjs/src/components/Layout.js"
click node_django_routes "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/core/urls.py"
click node_inventory_views "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/views.py"
click node_serializers "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/serializers.py"
click node_inventory_models "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/models.py"
click node_django_settings "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/core/settings.py"
click node_domain_entities "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/domain-package/domain/entities.py"
click node_domain_rules "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/domain-package/domain/rules.py"
click node_fastapi_service "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py"
click node_audit_ledger "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py"
click node_external_integrations "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py"
click node_postgres "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/docker-compose.yml"
click node_compose "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/docker-compose.yml"
click node_environment "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/.env.example"
click node_django_container "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/Dockerfile"
click node_fastapi_container "https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_next_pages,node_layout toneBlue
class node_django_routes,node_inventory_views,node_serializers,node_inventory_models,node_django_settings toneAmber
class node_fastapi_service,node_audit_ledger,node_external_integrations toneMint
class node_postgres,node_compose,node_environment,node_django_container,node_fastapi_container toneRose
class node_domain_entities,node_domain_rules toneNeutral
```

## Components

### Frontend

- **Next.js Pages Router**: web UI · Login, inventory administration, reporting, and copilot screens.
- [Shared layout](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/frontend-nextjs/src/components/Layout.js): UI shell · `frontend-nextjs/src/components/Layout.js`

### Django system of record

- [Django API routes](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/core/urls.py): REST boundary · Composes auth, company, and product API routes. · `backend-django/core/urls.py`
- [Inventory views](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/views.py): REST views · Applies authentication and role policy for inventory operations. · `backend-django/inventario/views.py`
- [Inventory serializers](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/serializers.py): serialization · `backend-django/inventario/serializers.py`
- [Inventory models](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/inventario/models.py): ORM models · Company, product, and custom user persistence mapping. · `backend-django/inventario/models.py`
- [Django settings](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/core/settings.py): runtime config · Configures authentication and the custom user model. · `backend-django/core/settings.py`

### FastAPI auxiliary service

- [FastAPI service](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py): HTTP service · Provides reports, email delivery, AI suggestions, and audit ledger. · `microservice-fastapi/main.py`
- [SHA-256 audit ledger](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py): in-memory ledger · Simplified ledger without durable database backing. · `microservice-fastapi/main.py`
- [Report, email, and AI providers](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/main.py): external APIs · ReportLab, Brevo, and Google Gemini integrations. · `microservice-fastapi/main.py`

### Platform

- [PostgreSQL 16 + pgvector](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/docker-compose.yml): durable datastore · Central database for Django system-of-record data. · `docker-compose.yml`
- [Docker Compose](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/docker-compose.yml): local orchestration · Launches PostgreSQL and containerized services. · `docker-compose.yml`
- [Shared environment](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/.env.example): environment config · Supplies database credentials and external API keys. · `.env.example`
- [Django container](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/backend-django/Dockerfile): container image · `backend-django/Dockerfile`
- [FastAPI container](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/microservice-fastapi/Dockerfile): container image · `microservice-fastapi/Dockerfile`

### Other components

- [Domain entities](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/domain-package/domain/entities.py): Python domain package · Reusable Pydantic-oriented Empresa, Producto, and Usuario concepts. · `domain-package/domain/entities.py`
- [Authorization rules](https://github.com/juanospina0409/prueba-tecnica-lite-thinkng/blob/main/domain-package/domain/rules.py): domain policy · `domain-package/domain/rules.py`

## Connections

- Next.js Pages Router → Shared layout: wraps screens
- Next.js Pages Router → Django API routes: calls REST API
- Next.js Pages Router → FastAPI service: calls utility API
- Django API routes → Inventory views: routes requests
- Inventory views → Inventory serializers: serializes payloads
- Inventory views → Inventory models: reads and writes
- Inventory views → Authorization rules: enforces roles
- Inventory serializers → Inventory models: maps API data
- Inventory models → PostgreSQL 16 + pgvector: persists
- Django settings → Inventory models: selects custom user model
- Authorization rules → Domain entities: validates roles for
- FastAPI service → SHA-256 audit ledger: records audits
- FastAPI service → Report, email, and AI providers: generates and delivers
- Docker Compose → PostgreSQL 16 + pgvector: starts
- Docker Compose → Django container: orchestrates
- Docker Compose → FastAPI container: orchestrates
- Django container → Django API routes: runs
- FastAPI container → FastAPI service: runs
- Shared environment → PostgreSQL 16 + pgvector: configures credentials
- Shared environment → Django settings: supplies settings
- Shared environment → FastAPI service: supplies API keys
