Skip to content

Repository files navigation

AccessTrackAPI

📌 Description

A secure access control system API for managing user authentication, authorization, and entry logging in buildings or institutions.

🔎 The problem this API solves

Many facilities still rely on manual methods or outdated systems for access control, which can cause:

  • ❌ No reliable tracking of who enters or exits
  • ❌ Difficulty managing permission levels
  • ❌ Security vulnerabilities

💡 The Solution I Developed:

A robust and scalable API that delivers:

  • ✅ Secure authentication using JWT Tokens with role hierarchy (Admin, User, Visitor)
  • ✅ Detailed entry/exit logging with timestamps
  • ✅ Complete CRUD operations for user and visitor management
  • ✅ Administrative dashboard for log viewing and reporting

🚀 Features

User Management

  • User registration and authentication
  • Role-based access control (Admin, User, Visitor)
  • Password hashing for secure storage
  • JWT token-based authentication

Access Control

  • Entry validation for users and visitors
  • Exit recording with timestamps
  • Comprehensive logging of all access events

Admin Functionality

  • Admin user creation and management
  • User/visitor management (CRUD operations)
  • Access log viewing and reporting

API Endpoints

🔑 Authentication & Security

This API uses JWT authentication. To access protected routes, obtain a token via the login endpoint and include it in the request headers:

 Authorization: Bearer YOUR_ACCESS_TOKEN

Authentication

  • POST /v1/Users/CreateUser - Register a new regular user
  • POST /v1/Users/login - Authenticate a user and get JWT token
  • POST /v1/Admin/LoginAdmin - Authenticate an admin and get JWT token

Admin Operations

  • POST /v1/Admin/CreateAdmin - Create a new admin (requires admin role)
  • POST /v1/Admin/CreateFirstAdmin - Initialize the first root admin
  • DELETE /v1/Admin/DeleteAdmin/{id} - Delete an admin (root admin only)
  • DELETE /v1/Admin/DeleteUser/{id} - Delete a user
  • PUT /v1/Admin/UpdateUser/{id} - Update user information
  • GET /v1/Admin/UserLogs/{userId?} - Get access logs (all or specific user)
  • GET /v1/Admin/VisitorLogs/{visitorId?} - Get visitor access logs

Visitor Management

  • POST /v1/visitors/CreateVisitor - Create a new visitor (admin only)
  • DELETE /v1/visitors/DeleteVisitor/{id} - Delete a visitor (admin only)

Access Control

  • POST /v1/Entry/validate-entry - Validate user/visitor entry

User Operations

  • GET /v1/Users/infos - Get user information and access logs

Demo:

swagger image

📦 Installation & Setup

Prerequisites

  1. Clone this repository
 git clone https://github.com/LeonardoEnnes/AccessTrackAPI.git
cd AccessTrackAPI
  1. Configure the enviroment variables:

     cp .env.example .env
    • Open the .env file and update the following values:
      • DB_CONNECTION_STRING: Your SQL Server connection string
      • JWT_KEY: A secure secret key for JWT token generation
  2. Build and run the application using Docker:

 docker-compose up --build
  1. The API should now be running at: http://localhost:5130/swagger

For Development (Without Docker):

  • Feel free to improve my code as you see fit.
  • If you have any questions regarding this project, Please feel free to email me.
  1. Restore Dependencies & Build
 dotnet restore
dotnet build
  1. Configure User Secrets
 dotnet user-secrets
dotnet user-secrets set"ConnectionStrings:DefaultConnection""your-string-connection"
dotnet user-secrets set"JwtKey""your-jwt-key"
  1. Apply Database Migrations
 dotnet ef database update
  1. Run the Application
 dotnet run

🛠️ Technologies Used

  • .NET (C#)
  • Entity Framework
  • SQL Server
  • Docker

📂 Project Structure

.
├── Dependencies ├── Properties
│ └── launchSettings.json ├── src ├── Controllers
│ ├── AccessControlController.cs │ ├── AdminController.cs │ ├── UsersController.cs │ └── VisitorController.cs ├── Data ├── Extensions
│ └── RoleClaimExtension.cs ├── Migrations ├── Models
│ ├── Admins.cs │ ├── EntryLogs.cs │ ├── Users.cs │ └── Visitor.cs ├── Services
│ └── TokenService.cs ├── ViewModels
│ ├── Accounts │ ├── DTOs │ └── ResultViewModel.cs ├── AccessTrackAPI.http ├── Configuration.cs └── Program.cs 

📜 License

This project is licensed under the MIT License.

📧 Contact

About

This Access Control API (Gatekeeping System) is a RESTful API designed to manage the entry and exit of individuals in buildings, condominiums, or commercial establishments.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages