Skip to main content

System Architecture

Detailed technical architecture of the NS Software Solutions website.

High-Level Architecture

Technology Stack

LayerTechnologyVersionPurpose
FrontendReact18.3.1UI framework
LanguageTypeScript5.8.3Type safety
BuildVite5.4.19Build tool, HMR
StylingTailwind CSS3.4.17Utility-first CSS
UI Kitshadcn/uiLatestComponent library
AnimationsFramer Motion12.23.24Motion effects
RoutingReact Router6.30.1Client-side routing
StateReact Query5.83.0Server state
FormsReact Hook Form7.61.1Form handling
ValidationZod3.25.76Schema validation
IconsLucide React0.462.0Icon library
SEOReact Helmet2.0.5Meta tags
DatabasePostgreSQL15+RDBMS
Backend-as-a-ServiceSupabaseLatestAuth, API, Storage, Realtime
AuthenticationSupabase AuthLatestEmail/password, JWT, PKCE
File StorageSupabase StorageLatestCDN-backed object storage
HostingNetlifyLatestEdge CDN, SPA hosting
AnalyticsGoogle Analytics 4LatestUser behavior tracking

Application Architecture

Route Map

Public Routes (No Authentication Required)

PathComponentPurpose
/HomeLanding page with hero, features, testimonials
/projectsProjectsFilterable project catalog
/projects/:slugProjectDetailsIndividual project detail page
/servicesServicesService offerings with FAQ
/aboutAboutUsCompany information and mission
/contactContactContact form
/blogsBlogIndexBlog post listing
/blogs/project-ideas-for-cse-studentsBlogPost1SEO-optimized blog post
/blogs/how-to-ace-your-vivaBlogPost2SEO-optimized blog post
/blogs/why-documentation-mattersBlogPost3SEO-optimized blog post
/final-year-projects/:cityCityProjectsCity landing pages (SEO)
/loginLoginAuthentication page
/reset-passwordResetPasswordPassword recovery

Protected Routes - User (onlyUser)

PathComponentPurpose
/user/dashboardDashboardUser overview and stats
/user/my-projectsMyProjectsUser's purchased projects
/user/profileUserProfileProfile management
/user/request-projectRequestProjectCustom project requests

Protected Routes - Admin (onlyAdmin)

PathComponentPurpose
/adminAdminDashboardAdmin overview and stats
/admin/projectsAdminProjectsProject CRUD management
/admin/purchasesPurchaseManagementPurchase tracking and file delivery
/admin/user-managerUserManagerUser management and activity
/admin/requestsRequestsManagementAll request types (4 tabs)

Component Tree

App (Root with ErrorBoundary)
├── QueryClientProvider (React Query cache)
├── AuthProvider (Context for auth state)
├── HelmetProvider (for meta tags)
└── AppRoutes
├── Navbar (persistent)
├── Routes
│ ├── Public pages (lazy-loaded)
│ ├── UserLayout (outlet for /user/*)
│ │ └── Protected user pages
│ └── AdminLayout (outlet for /admin/*)
│ └── Protected admin pages
└── Footer (hidden on /admin/*)

Authentication Flow

Security Features

PKCE Flow (Proof Key for Code Exchange)

  • Auth code exchange with code challenge/verifier
  • Prevents authorization code interception
  • Industry-standard for SPAs

Token Storage

  • Access tokens: sessionStorage (cleared on tab close)
  • Refresh tokens: sessionStorage (secure, short-lived)
  • HttpOnly cookies: NOT used for SPA security

Auto-Logout

  • 30-minute idle timeout
  • Automatic logout on inactivity
  • User warned 2 minutes before logout

State Management Architecture

React Query (Server State)

React Query Cache
├── Projects Query
│ ├── All projects (published, active)
│ ├── Individual project detail
│ └── Filtered results
├── User Queries
│ ├── Current user profile
│ ├── User purchases
│ ├── User requests
│ └── User sessions
└── Admin Queries
├── All projects (admin view)
├── All users
├── All purchases
└── All requests

Stale Time Strategy:

  • Projects: 5 minutes (static, rarely changes)
  • User data: 1 minute (frequently accessed)
  • Admin data: 30 seconds (frequently updated)
  • Requests: Real-time on admin panel

Auth Context (Local State)

{
user: {
id: uuid,
email: string,
name: string,
role: 'user' | 'admin'
},
isLoading: boolean,
isAuthenticated: boolean,
signUp: function,
signIn: function,
signOut: function,
resetPassword: function
}

API Architecture

PostgREST Auto-Generated API

Base URL: https://<project-ref>.supabase.co/rest/v1

Key Endpoints (Auto-Generated):

ResourceEndpoints
/profilesGET, POST, PATCH, DELETE
/projectsGET, POST, PATCH, DELETE
/purchasesGET, POST, PATCH, DELETE
/purchase_filesGET, POST, PATCH, DELETE
/project_requestsGET, POST, PATCH, DELETE
/service_requestsGET, POST, PATCH, DELETE
/contact_messagesGET, POST, PATCH, DELETE
/custom_requestsGET, POST, PATCH, DELETE
/notificationsGET, POST, PATCH, DELETE
/admin_actionsGET

Example Request:

// Get projects (public)
const { data } = await supabase
.from('projects')
.select('*')
.eq('status', 'active')
.eq('visibility', 'published');

// Create purchase (admin)
const { data } = await supabase
.from('purchases')
.insert({
user_id, project_id, amount, status: 'pending'
});

Authentication Headers

All requests to protected resources include:

Authorization: Bearer <JWT_ACCESS_TOKEN>

Supabase client automatically:

  • Adds JWT to all requests
  • Refreshes token on 401 response
  • Retries request with new token

Row Level Security (RLS)

Policy Examples

profiles table:

-- Users can read/update own profile
CREATE POLICY "Users read own profile" ON profiles
FOR SELECT USING (auth.uid() = user_id);

-- Admins read all profiles
CREATE POLICY "Admins read all profiles" ON profiles
FOR SELECT USING (
EXISTS (SELECT 1 FROM profiles WHERE user_id = auth.uid() AND role = 'admin')
);

projects table:

-- Anonymous users see published + active
CREATE POLICY "Anonymous view published" ON projects
FOR SELECT USING (status = 'active' AND visibility = 'published');

-- Admins see all
CREATE POLICY "Admins see all projects" ON projects
USING (
EXISTS (SELECT 1 FROM profiles WHERE user_id = auth.uid() AND role = 'admin')
);

purchases table:

-- Users read own purchases
CREATE POLICY "Users read own purchases" ON purchases
FOR SELECT USING (user_id = auth.uid());

-- Admins manage all
CREATE POLICY "Admins manage purchases" ON purchases
USING (
EXISTS (SELECT 1 FROM profiles WHERE user_id = auth.uid() AND role = 'admin')
);

Performance Optimizations

Code Splitting

All routes lazy-loaded via React.lazy():

const ProjectDetails = React.lazy(() => import('./pages/ProjectDetails'));
const UserDashboard = React.lazy(() => import('./pages/user/Dashboard'));

Image Optimization

  • Screenshots stored on Supabase Storage (CDN-backed)
  • Lazy loading via loading="lazy"
  • WebP support with JPEG fallback
  • Automatic resize on upload

Caching Strategy

ResourceCache DurationStrategy
HTMLNo cacheAlways fresh
JS/CSS365 daysContent hash in filename
Images30 daysCDN cache
API Responses1-5 minReact Query stale time

Database Indexes

30+ indexes optimized for queries:

  • Profile lookups by user_id, role, is_online
  • Project filters by status, featured, slug
  • Purchase tracking by user_id, status, created_at
  • Request searches by status, created_at

Monitoring & Analytics

Google Analytics 4

Tracked Events:

  • Page views (all routes)
  • User interactions (button clicks, form submissions)
  • Conversion events (purchase created, request submitted)
  • Custom events (project viewed, filter applied)

Error Tracking

  • ErrorBoundary catches React errors
  • Console logging in development
  • Structured error format sent to admin

Performance Metrics

  • Core Web Vitals: LCP, FID/INP, CLS
  • Lighthouse score targets: 85+
  • Time to First Byte (TTFB): < 200ms

Deployment Pipeline

Netlify Configuration:

  • Build command: npm run build
  • Publish directory: dist
  • Environment variables: Set in dashboard
  • Auto-deploy: On push to main branch
  • Redirects: SPA routing via _redirects file