How samardzicluka/vikendice_demo works
1. Overall shape
- This is a classic 3-part application: an Angular 18 single-page frontend, an Express/Node.js backend, and a MongoDB database.
- The browser talks only to the backend API; the backend owns authentication, business rules, and persistence.
2. Frontend boundary
- The Angular app is organized by role and workflow, not by generic UI widgets.
- Main screen areas are: public/home, tourist, owner, admin, plus shared profile and change-password screens.
- Routing is centralized in app.routes.ts, with route protection handled by guards.
3. Frontend auth layer
- Authentication state is enforced through:
- auth.service for login/session handling,
- auth.interceptor to attach JWTs to API requests,
- auth.guard and admin.guard to protect role-specific routes.
- The README indicates the session token is stored in localStorage and treated as expiring after about 1 hour of inactivity.
4. Public user flow
- The public/home area supports browsing the platform without login.
- It includes login/register entry points and a dashboard-like landing area that surfaces platform statistics and cottage discovery features.
- This is the main unauthenticated path into the system.
5. Tourist subsystem
- Tourist features are grouped under components/tourist.
- The main user flow is: browse cottages, open a cottage detail page, inspect map/location data, make a reservation, and later view/cancel reservations.
- Reviews/ratings are part of the tourist journey and affect cottage reputation and blocking logic.
6. Owner subsystem
- Owner features are grouped under components/owner.
- Owners can manage their cottages, inspect reservation activity, and view analytics.
- The owner area includes a calendar-based reservation workflow and statistics views, which the README says use FullCalendar and Chart.js.
7. Admin subsystem
- Admin access is separate from the regular user login flow (/admin/login vs /home/login).
- Admin responsibilities include approving/rejecting registrations, managing users, inspecting cottages, and temporarily blocking cottages that repeatedly receive poor ratings.
- This is a distinct administrative boundary from tourist/owner operations.
8. Frontend data access pattern
- Angular components do not talk to MongoDB directly; they use services in frontend/src/app/services.
- The service layer is split by domain: auth, cottage, reservation, and user.
- These services define the client-side data flow from UI events to REST API calls and back into component state.
9. Backend API structure
- The backend is an Express app with a clean separation into:
- routes/api for HTTP endpoints,
- controllers for request handling and business logic,
- middleware for cross-cutting concerns like auth.
- The route modules are domain-aligned: auth, cottage, reservation, and user.
- server.ts and app.ts are the startup and app composition points.
10. Backend domain model
- MongoDB persistence is organized around four core models:
- user
- cottage
- reservation
- comment
- These likely map closely to the app’s core entities and are the backbone of all flows: registration/login, listing cottages, booking, and reviews.
11. Authentication and authorization on the backend
- authMiddleware.ts is the key server-side gatekeeper.
- JWT-based auth is used to protect endpoints, and role-based checks are implied by the separate tourist/owner/admin capabilities.
- Passwords are hashed with bcrypt, so credential verification happens entirely on the backend.
12. File and media handling
- File uploads are handled with Multer through backend/config/multer.
- The uploads/ folder is a persistent filesystem boundary for profile pictures and cottage images.
- The README also indicates a default profile image is expected there, so the backend depends on local disk storage in addition to MongoDB.
13. Cross-cutting business rules
- Some important domain rules are enforced server-side:
- cottage blocking can expire automatically,
- reservations can be cancelled only within allowed time constraints,
- reviews require completed stays,
- profile images must meet size/type constraints,
- credit card and password formats are validated.
- These rules matter architecturally because they live in backend controllers/middleware rather than the UI.
14. End-to-end data flow
- Typical request path is: Angular component → Angular service → interceptor adds JWT → Express route → controller → MongoDB model → response back to UI.
- File uploads add an extra branch through Multer into the local uploads/ directory.
- The main architectural boundaries are therefore:
- browser/UI vs API,
- API vs MongoDB,
- API vs filesystem for uploaded media.
15. Operational assumptions
- The backend expects a local MongoDB instance and a .env file with a port and JWT secret.
- The frontend expects the backend on port 8080 during development.
- This is a monolithic full-stack app with a local-development deployment model, not a distributed service architecture.
Main entry points: app.routes.ts Routes · cottage.service.ts Domain services · authController.ts Controllers · auth.router.ts API routes
Components 18
Frontend
Angular SPA with role-based areas and shared auth/data services
- App shell · Bootstraps the SPA and hosts routed feature areas
frontend/src/app/app.component.ts - Routes · Central route table for public, tourist, owner, admin, and profile flows
frontend/src/app/app.routes.ts - Auth stack · Login/session handling, JWT attachment, and route protection
frontend/src/app/services/auth.service.ts - Home area · Unauthenticated landing, login, register, and dashboard entry points
frontend/src/app/components/home/home.component.ts - Tourist area · Browse cottages, view details, map/location, reservations, and reviews
frontend/src/app/components/tourist/tourist.component.ts - Owner area · Manage cottages, reservation activity, calendar workflow, and statistics
frontend/src/app/components/owner/owner.component.ts - Admin area · Administrative dashboard for approvals, user management, and cottage moderation
frontend/src/app/components/admin/admin.component.ts - Profile screens · User profile and password-change views shared across flows
frontend/src/app/components/profile/profile.component.ts - Domain services · Client-side data access for auth, cottages, reservations, and users
frontend/src/app/services/cottage.service.ts
Backend
Express API with controllers, middleware, and MongoDB models
- Server entry · Starts the API and composes the application
backend/server.ts - API app · Application composition and middleware wiring
backend/app.ts - API routes · Domain route modules for auth, cottage, reservation, and user endpoints
backend/routes/api/auth.router.ts - Controllers · Business logic for auth, cottages, reservations, and users
backend/controllers/authController.ts - Auth middleware · Protects endpoints and enforces server-side authorization checks
backend/middleware/authMiddleware.ts - Models · Core persistence models for users, cottages, reservations, and comments
backend/models/user.ts - File upload · Upload handling and file-type/size constraints
backend/config/multer/multer.ts
Storage
MongoDB plus local upload filesystem
- Mongo config · MongoDB connection and persistence setup
backend/config/db/db.ts - Uploads · Local disk boundary for profile pictures and cottage images
backend/uploads
Connections 21
- App shell → Routes: uses routes · App shell renders route-based screens
- Routes → Home area: public paths · Unauthenticated landing and entry flow
- Routes → Tourist area: tourist paths · Protected tourist workflow
- Routes → Owner area: owner paths · Protected owner workflow
- Routes → Admin area: admin paths · Separate admin login and dashboard flow
- Routes → Profile screens: shared paths · Profile and password-change screens
- Home area → Auth stack: login/register · Public screens initiate authentication
- Tourist area → Domain services: cottage/reservation data · Tourist UI fetches and mutates domain data through services
- Owner area → Domain services: owner data · Owner UI uses API clients for cottages and analytics
- Admin area → Domain services: admin data · Admin UI uses shared API clients for moderation flows
- Profile screens → Domain services: user data · Profile and password updates go through service layer
- Auth stack → API routes: JWT API calls · Auth service and interceptor drive authenticated requests
- Domain services → API routes: REST calls · Angular services call domain API endpoints
- Server entry → API app: boots · Server entry starts the Express app
- API app → API routes: mounts · App composes the route modules
- API routes → Controllers: dispatches to · Routes hand off request handling to controllers
- Controllers → Auth middleware: protected by · Controllers rely on auth middleware for guarded actions
- Controllers → Models: reads/writes · Business logic persists through Mongo models
- Models → Mongo config: stored in · Models persist through the MongoDB connection
- File upload → Uploads: writes files · Upload pipeline stores images on local disk
- Controllers → File upload: handles uploads · Cottage and profile media flow through Multer