Skip to main content

Overview

The T1 Component Library API is a RESTful API built with Express.js that provides endpoints for user authentication and component interaction tracking. The API enables you to register users, authenticate them with JWT tokens, and track how users interact with UI components in your library.

Base URL

All API requests should be made to:
http://localhost:3001/api
In production, replace localhost:3001 with your deployed server URL.

Technology Stack

The API is built using modern, reliable technologies:

Core Technologies

  • Node.js (18.x+) - JavaScript runtime
  • Express.js (4.18.2) - Minimalist web framework
  • TypeScript (5.3.3) - Type-safe JavaScript

Database

  • MongoDB Atlas - NoSQL cloud database
  • Mongoose (8.0.3) - MongoDB ODM for data modeling

Authentication & Security

  • JWT (jsonwebtoken) (9.0.2) - Token-based authentication
  • bcryptjs (2.4.3) - Password hashing

Additional Tools

  • CORS - Cross-origin resource sharing
  • Morgan - HTTP request logger
  • express-validator - Request validation

API Architecture

The API follows a clean, layered architecture:
├── Routes Layer      → Endpoint definitions and routing
├── Middleware Layer  → Authentication, validation, error handling
├── Controller Layer  → Request handling and response formatting
├── Service Layer     → Business logic and data operations
└── Model Layer       → Database schemas and data validation

Key Features

  • RESTful Design - Standard HTTP methods (GET, POST) and status codes
  • JWT Authentication - Secure, stateless authentication
  • Request Validation - Input validation using express-validator
  • Error Handling - Centralized error handling with meaningful messages
  • Public & Protected Endpoints - Mixed access levels for different use cases

API Endpoint Categories

Authentication

Register users and obtain JWT tokens for protected endpoints

Component Tracking

Track component interactions and retrieve usage statistics

Data Export

Export tracking data for analysis (requires authentication)

Health Check

Monitor API and database health status

Response Format

All API responses follow a consistent JSON structure:

Success Response

{
  "success": true,
  "message": "Operation completed successfully",
  "data": {
    // Response data here
  }
}

Error Response

{
  "success": false,
  "message": "Error description",
  "error": "Technical details (development only)"
}

HTTP Status Codes

The API uses standard HTTP status codes:
CodeDescription
200Success - Request completed successfully
201Created - Resource created successfully
400Bad Request - Invalid data or validation error
401Unauthorized - Missing or invalid authentication
404Not Found - Resource doesn’t exist
500Internal Server Error - Server-side error
503Service Unavailable - Database connection issue

Quick Start Example

Here’s a quick example of registering a user and making an authenticated request:
# 1. Register a new user
curl -X POST http://localhost:3001/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "John Doe",
    "email": "[email protected]",
    "password": "securepass123"
  }'

# Response includes a JWT token
# {
#   "success": true,
#   "data": {
#     "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
#   }
# }

# 2. Use the token for authenticated requests
curl http://localhost:3001/api/components/export \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Next Steps

1

Learn Authentication

Read the Authentication guide to understand how to obtain and use JWT tokens.
2

Explore Endpoints

Browse the endpoint documentation to see available operations and request/response formats.
3

Start Building

Integrate the API into your application using the examples provided.

Build docs developers (and LLMs) love