Skip to content

anibalventura/user-management-api

Repository files navigation

🔐 User Management API

A robust user management and authentication API built with Spring Boot, featuring JWT authentication, user registration, and comprehensive API documentation.

✨ Features

  • 🔐 User registration and authentication
  • 🛡️ JWT-based authentication
  • 👥 User management with pagination
  • 💾 Persistence with JPA
  • 📚 Swagger UI for API documentation
  • 🔒 Secure endpoints with Spring Security
  • 📝 Example responses in Swagger UI

🛠️ Technologies

  • Java [21]
  • Spring Boot [3.2.5]
  • Spring Security
  • JWT
  • Swagger
  • Gradle
  • PostgreSQL

📊 Diagrams

API Architecture

API Diagram

Database Schema

The database is created automatically when running the project for the first time, but you can also run the DB Script before starting.

DB Diagram

⚙️ Configuration

  1. Clone the repository:

    git clone https://github.com/anibalventura/user-management-api.git
    cd user-management-api
    1. Configure application properties:

      Update the src/main/resources/application.properties file with your database and JWT configurations.

      # Database Configuration
      spring.application.name=user-management-api
      spring.datasource.url=jdbc:postgresql://localhost:5432/usermanagementdb
      spring.datasource.username=postgres
      spring.datasource.password=postgres
      spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
      spring.jpa.hibernate.ddl-auto=update
      
      # JWT Configuration
      jwt.secret="u8Jz7Fh2J3kL9mN4pQ6rT8vW0xY2zA5B7D1E3G5H7J9K1L3N5P7R9T1V3X5Z7"
      jwt.expiration=86400000
  2. Build the project:

    ./gradlew build

🚀 Running the Application

  1. Run the application:

    ./gradlew bootRun
  2. Access the Swagger UI:

    Open your browser and navigate to http://localhost:8080/swagger-ui.html to view the API documentation and test the endpoints. Also, you can import the Postman Collection.

🌐 Endpoints

  • Authentication:

    • POST /api/auth/register - Register a new user
    • POST /api/auth/login - Login a user and return a JWT token
  • User Management:

    • GET /api/users - Get all users with pagination

📋 Example Requests

  • Register a new user:

    POST /api/auth/register
    {
        "name": "Anibal Ventura",
        "email": "contact@anibalventura.com",
        "password": "password123!",
        "phones": [
            {
                "number": "9724459",
                "cityCode": "1",
                "countryCode": "809"
            }
        ]
    }
  • Login a user:

    POST /api/auth/login
    {
        "email": "contact@anibalventura.com",
        "password": "password123!"
    }

🔒 Security

  • The application uses JWT for securing endpoints.
  • The SecurityConfig class configures the security settings, allowing public access to authentication and Swagger endpoints, while securing other endpoints.

🤝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

How to Contribute

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📄 License

This project is open source and available under the MIT LICENSE.


Star this repository if you found it helpful!

ko-fi

About

Simple API for register and login and user with JWT authentication and Swagger docs

Topics

Resources

License

Stars

Watchers

Forks

Languages