How kirillius7/urlservice works
Project Type and Purpose
• This is a full-stack URL Shortener application.
• Backend: ASP.NET MVC (C#) with Entity Framework (Code-First) and Identity for auth.
• Frontend: React SPA built with Vite, using hooks and Fetch API to consume the backend.
• Purpose: allow users to register/login, shorten long URLs, view/manage their own (or all, for admins) short links, and redirect via the shortened paths.
Main Components
a. Frontend (React/Vite)
• Entry: src/main.jsx → App.jsx
• Components:
• Login.jsx / Registration.jsx (auth forms)
• UrlsTable.jsx (list of URLs)
• UrlInfo.jsx (details view)
• Create URL form (noted in service/api.js)
• Service Layer: src/service/api.js (all HTTP calls to the backend)
• Assets & CSS: under src/assets and component-level CSS.
b. Backend (ASP.NET MVC)
• Program.cs & launchSettings.json (app startup, Kestrel/IIS settings)
• Controllers:
• AccountController.cs (login, registration, token or cookie flows)
• UrlsController.cs (API endpoints: Create, Read, Delete URLs, Redirect short URL)
• HomeController.cs (MVC views for non-SPA parts if any)
• Models & Data:
• AppUser.cs (Identity user model)
• ShortUrl.cs (URL entity)
• CreateUrlDto.cs (DTO for creating URLs)
• AppDbContext.cs (EF Core DbContext)
• Migrations folder (code-first snapshots & migration classes)
• Service Layer: IUrlService.cs + UrlServiceClass.cs (business logic: check duplicates, create short codes, fetch details)
• Views: MVC Razor views under Views/Home and Views/Shared (fallback or pre-React pages)
• Static Assets: wwwroot (Bootstrap, jQuery validation, site.js/css)
c. Database
• SQL Server (or configured provider) storing AspNetIdentity tables and ShortUrls table.
d. Tests
• UrlService.Tests project with unit tests for service logic or controllers.
Component Interactions & Data Flow
• User interacts with React UI in browser → actions call service/api.js → HTTP requests to the ASP.NET MVC API endpoints (UrlsController, AccountController).
• Controllers delegate to UrlServiceClass (IUrlService) → business rules, mapping between DTOs and EF entities.
• UrlServiceClass uses AppDbContext to read/write to the database.
• EF Core Migrations ensure schema (InitialCreate + IdentityTables).
• For redirect: incoming GET /u/{shortCode} hits UrlsController.Redirect → service finds original URL → returns HTTP 302.
• Auth flows: Login/Register endpoints set cookies or tokens; API endpoints validate roles (Admin vs. User) before allowing Create/Delete.
Architectural Patterns & Principles
• MVC (Controllers / Views / Models) on backend
• Service Layer abstraction (IUrlService) separates business logic from controllers
• Repository-style use of EF Core via AppDbContext
• Code-First Migrations for schema versioning
• Component-based architecture in React with Hooks (useState/useEffect)
• API-First approach—backend purely offers JSON endpoints consumed by SPA
• Role-based access control enforced server-side
• Single Page Application served either by static assets in wwwroot or via separate Vite dev server.
Detail & Clarity
• Essential components: React App, api.js, all Controllers, Service interfaces, DbContext, Entities, Migrations, Database.
• Call out configuration files (appsettings.json) and static assets (wwwroot/lib/*.css/.js) if relevant to deployment.