# samardzicluka/vikendice_demo architecture

> Architecture diagram of the GitHub repository samardzicluka/vikendice_demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/samardzicluka/vikendice_demo
- Repository: https://github.com/samardzicluka/vikendice_demo

## Overview

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: [`frontend/src/app/app.routes.ts`](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/app.routes.ts) (Routes), [`frontend/src/app/services/cottage.service.ts`](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/services/cottage.service.ts) (Domain services), [`backend/controllers/authController.ts`](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/controllers/authController.ts) (Controllers), [`backend/routes/api/auth.router.ts`](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/routes/api/auth.router.ts) (API routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["App shell<br/>Angular shell<br/>[app.component.ts]"]
  node_frontend_routes["Routes<br/>Router config<br/>[app.routes.ts]"]
  node_frontend_auth["Auth stack<br/>Auth service<br/>[auth.service.ts]"]
  node_frontend_public["Home area<br/>Public UI<br/>[home.component.ts]"]
  node_frontend_tourist["Tourist area<br/>Role UI"]
  node_frontend_owner["Owner area<br/>Role UI<br/>[owner.component.ts]"]
  node_frontend_admin["Admin area<br/>Admin UI<br/>[admin.component.ts]"]
  node_frontend_profile["Profile screens<br/>Shared UI"]
  node_frontend_services["Domain services<br/>API clients<br/>[cottage.service.ts]"]
end

subgraph group_backend["Backend"]
  node_backend_entry["Server entry<br/>Express bootstrap<br/>[server.ts]"]
  node_backend_app["API app<br/>Express app<br/>[app.ts]"]
  node_backend_routes["API routes<br/>HTTP routes<br/>[auth.router.ts]"]
  node_backend_controllers["Controllers<br/>Request handlers<br/>[authController.ts]"]
  node_backend_middleware["Auth middleware<br/>JWT middleware<br/>[authMiddleware.ts]"]
  node_backend_models[("Models<br/>[user.ts]")]
  node_backend_multer["File upload<br/>Multer config<br/>[multer.ts]"]
end

subgraph group_storage["Storage"]
  node_backend_db[("Mongo config<br/>DB config<br/>[db.ts]")]
  node_backend_uploads["Uploads<br/>Filesystem"]
end

node_frontend_app -->|"uses routes"| node_frontend_routes
node_frontend_routes -->|"public paths"| node_frontend_public
node_frontend_routes -->|"tourist paths"| node_frontend_tourist
node_frontend_routes -->|"owner paths"| node_frontend_owner
node_frontend_routes -->|"admin paths"| node_frontend_admin
node_frontend_routes -->|"shared paths"| node_frontend_profile
node_frontend_public -->|"login/register"| node_frontend_auth
node_frontend_tourist -->|"cottage/reservation data"| node_frontend_services
node_frontend_owner -->|"owner data"| node_frontend_services
node_frontend_admin -->|"admin data"| node_frontend_services
node_frontend_profile -->|"user data"| node_frontend_services
node_frontend_auth -->|"JWT API calls"| node_backend_routes
node_frontend_services -->|"REST calls"| node_backend_routes
node_backend_entry -->|"boots"| node_backend_app
node_backend_app -->|"mounts"| node_backend_routes
node_backend_routes -->|"dispatches to"| node_backend_controllers
node_backend_controllers -->|"protected by"| node_backend_middleware
node_backend_controllers -->|"reads/writes"| node_backend_models
node_backend_models -->|"stored in"| node_backend_db
node_backend_multer -->|"writes files"| node_backend_uploads
node_backend_controllers -->|"handles uploads"| node_backend_multer

click node_frontend_app "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/app.component.ts"
click node_frontend_routes "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/app.routes.ts"
click node_frontend_auth "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/services/auth.service.ts"
click node_frontend_public "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/home/home.component.ts"
click node_frontend_tourist "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/tourist/tourist.component.ts"
click node_frontend_owner "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/owner/owner.component.ts"
click node_frontend_admin "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/admin/admin.component.ts"
click node_frontend_profile "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/profile/profile.component.ts"
click node_frontend_services "https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/services/cottage.service.ts"
click node_backend_entry "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/server.ts"
click node_backend_app "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/app.ts"
click node_backend_routes "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/routes/api/auth.router.ts"
click node_backend_controllers "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/controllers/authController.ts"
click node_backend_middleware "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/middleware/authMiddleware.ts"
click node_backend_models "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/models/user.ts"
click node_backend_db "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/config/db/db.ts"
click node_backend_uploads "https://github.com/samardzicluka/vikendice_demo/tree/master/backend/uploads"
click node_backend_multer "https://github.com/samardzicluka/vikendice_demo/blob/master/backend/config/multer/multer.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_frontend_app,node_frontend_routes,node_frontend_auth,node_frontend_public,node_frontend_tourist,node_frontend_owner,node_frontend_admin,node_frontend_profile,node_frontend_services toneBlue
class node_backend_entry,node_backend_app,node_backend_routes,node_backend_controllers,node_backend_middleware,node_backend_models,node_backend_multer toneAmber
class node_backend_db,node_backend_uploads toneMint
```

## Components

### Frontend

Angular SPA with role-based areas and shared auth/data services

- [App shell](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/app.component.ts): Angular shell · Bootstraps the SPA and hosts routed feature areas · `frontend/src/app/app.component.ts`
- [Routes](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/app.routes.ts): Router config · Central route table for public, tourist, owner, admin, and profile flows · `frontend/src/app/app.routes.ts`
- [Auth stack](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/services/auth.service.ts): Auth service · Login/session handling, JWT attachment, and route protection · `frontend/src/app/services/auth.service.ts`
- [Home area](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/home/home.component.ts): Public UI · Unauthenticated landing, login, register, and dashboard entry points · `frontend/src/app/components/home/home.component.ts`
- [Tourist area](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/tourist/tourist.component.ts): Role UI · Browse cottages, view details, map/location, reservations, and reviews · `frontend/src/app/components/tourist/tourist.component.ts`
- [Owner area](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/owner/owner.component.ts): Role UI · Manage cottages, reservation activity, calendar workflow, and statistics · `frontend/src/app/components/owner/owner.component.ts`
- [Admin area](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/admin/admin.component.ts): Admin UI · Administrative dashboard for approvals, user management, and cottage moderation · `frontend/src/app/components/admin/admin.component.ts`
- [Profile screens](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/components/profile/profile.component.ts): Shared UI · User profile and password-change views shared across flows · `frontend/src/app/components/profile/profile.component.ts`
- [Domain services](https://github.com/samardzicluka/vikendice_demo/blob/master/frontend/src/app/services/cottage.service.ts): API clients · 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](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/server.ts): Express bootstrap · Starts the API and composes the application · `backend/server.ts`
- [API app](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/app.ts): Express app · Application composition and middleware wiring · `backend/app.ts`
- [API routes](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/routes/api/auth.router.ts): HTTP routes · Domain route modules for auth, cottage, reservation, and user endpoints · `backend/routes/api/auth.router.ts`
- [Controllers](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/controllers/authController.ts): Request handlers · Business logic for auth, cottages, reservations, and users · `backend/controllers/authController.ts`
- [Auth middleware](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/middleware/authMiddleware.ts): JWT middleware · Protects endpoints and enforces server-side authorization checks · `backend/middleware/authMiddleware.ts`
- [Models](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/models/user.ts): Mongo models · Core persistence models for users, cottages, reservations, and comments · `backend/models/user.ts`
- [File upload](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/config/multer/multer.ts): Multer config · Upload handling and file-type/size constraints · `backend/config/multer/multer.ts`

### Storage

MongoDB plus local upload filesystem

- [Mongo config](https://github.com/samardzicluka/vikendice_demo/blob/master/backend/config/db/db.ts): DB config · MongoDB connection and persistence setup · `backend/config/db/db.ts`
- [Uploads](https://github.com/samardzicluka/vikendice_demo/tree/master/backend/uploads): Filesystem · Local disk boundary for profile pictures and cottage images · `backend/uploads`

## Connections

- 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
