Skip to main content

Backend Code Architecture

Architecture Diagram

PCM (Architecture)

Components

Frontend (Next.js)

Next.js is a React framework that provides several benefits for building frontend applications, especially those requiring server-side rendering, static generation, and other modern React features:

  • Server-side Rendering (SSR): Next.js supports SSR, improving SEO and initial page load performance by generating HTML on the server before sending it to the client.
  • Static Site Generation (SSG): It also supports SSG, allowing you to pre-render pages at build time, which is ideal for content-driven websites.
  • TypeScript Support: Next.js offers excellent TypeScript support, enabling type safety and a better development experience.
  • API Routes: Next.js allows you to create API endpoints within your application using the app/**/*/route.ts file, simplifying backend functionality integration with the front end.
  • Routing: Next.js uses a file-based routing system within the app directory, making client-side navigation straightforward and intuitive.

Backend (Spring Boot)

Spring Boot is a powerful Java framework for building backend applications, providing robust features and tools:

  • Dependency Management: Simplifies dependency management through starter projects and auto-configuration.
  • RESTful APIs: Well-suited for building RESTful APIs, enabling easy endpoint definition and HTTP request management.
  • Security: Offers comprehensive security features like authentication and authorization through Spring Security.
  • Data Access: Integrates smoothly with databases like PostgreSQL via Spring Data, facilitating CRUD operations.
  • Microservices: Supports microservices architecture for building and deploying independent, scalable services.
  • Containerization: Easily deployable to containers like Docker, supporting DevOps practices and automation.

Database (PostgreSQL)

PostgreSQL is a powerful open-source relational database management system:

  • Relational Database: Follows the relational model, supporting SQL for querying and managing data.
  • Data Integrity: Provides robust data integrity features such as constraints, transactions, and foreign key relationships.
  • Extensibility: Supports custom extensions and user-defined functions, enhancing database functionality as needed.
  • Performance: Offers excellent performance and scalability for handling large datasets and complex queries efficiently.
  • Community Support: Being open-source, PostgreSQL benefits from a large and active community for support and development.

Authentication (AWS Cognito)

AWS Cognito is a fully managed authentication service by Amazon Web Services:

  • User Management: Simplifies user authentication and management with features like sign-up, sign-in, and user profile management.
  • Security: Provides built-in features like multi-factor authentication (MFA) and data encryption, ensuring secure user data handling.
  • Scalability: Designed to handle millions of users, scales seamlessly with growing user bases.
  • Customization: Allows customization of authentication flows and UI to match application branding and user experience requirements.
  • Integration: Easily integrates with AWS services and third-party applications via provided SDKs and APIs.

OpenFGA (Open Feature Guard Access)

OpenFGA is an advanced, flexible, and scalable open-source authorization service designed for managing complex access control scenarios:

  • Fine-Grained Authorization: Provides detailed access control, allowing permissions to be defined at a granular level, suitable for complex authorization requirements.
  • Policy-Based Access Control: Uses policies to define and manage access rules, making it easier to implement and update authorization logic across applications.
  • Scalability: Designed to handle large-scale environments, ensuring high performance and reliability even with a large number of access control checks and policies.
  • Extensibility: Supports custom extensions and integrations, allowing it to be adapted to specific use cases and integrated seamlessly with other systems and services.
  • Community Support: As an open-source project, OpenFGA benefits from a vibrant and active community, providing support, contributions, and continuous development.
  • Auditability and Compliance: Facilitates compliance with security standards and regulations by providing comprehensive logging and auditing capabilities for access control decisions.

3CX (External Service)

3CX is a software-based PBX system providing VoIP communications:

  • Call Handling: Allows handling of incoming and outgoing calls over IP networks.
  • Features: Includes call routing, voicemail, call recording, conferencing, and enhancing communication capabilities.
  • Integration: Provides APIs and SDKs for integration with other applications, enabling custom workflows and automation.
  • Scalability: Suits businesses of all sizes, scalable to meet varying communication needs.
  • Management: Offers a web-based management console for configuring PBX settings, users, and permissions.

Directory Structure

We are going to use Spring Boot for backend development, The directory structure for the project is likely to be the following:

Spring Boot Project Directory Structure

spring-boot-project/

├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── sireto/
│ │ │ └── parkingcontrolroom/
│ │ │ ├── auth/
│ │ │ │ ├── AuthController.java
│ │ │ │ ├── AuthService.java
│ │ │ │ ├── AuthRepository.java
│ │ │ │ ├── dtos/
│ │ │ │ │ └── AuthDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── AuthException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ └── Auth.java
│ │ │ │ │ └── enums/
│ │ │ │ ├── utils/
│ │ │ │ │ └── AuthMapper.java
│ │ │ ├── authz/
│ │ │ │ ├── AuthzService.java
│ │ │ │ ├── dtos/
│ │ │ │ │ └── AuthzDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── AuthzException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ └── Authz.java
│ │ │ │ ├── utils/
│ │ │ │ │ └── AuthzMapper.java
│ │ │ ├── announcements/
│ │ │ │ ├── AnnouncementsController.java
│ │ │ │ ├── AnnouncementService.java
│ │ │ │ ├── AnnouncementRepository.java
│ │ │ │ ├── dtos/
│ │ │ │ │ └── AnnouncementDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── AnnouncementNotFoundException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ └── Announcement.java
│ │ │ │ ├── utils/
│ │ │ │ │ └── AnnouncementMapper.java
│ │ │ ├── casus/
│ │ │ │ ├── CasusController.java
│ │ │ │ ├── CasusService.java
│ │ │ │ ├── CasusRepository.java
│ │ │ │ ├── dtos/
│ │ │ │ │ │ ├── FollowupDTO.java
│ │ │ │ │ │ ├── ParkingDTO.java
│ │ │ │ │ │ ├── ParkingItemDTO.java
│ │ │ │ │ │ ├── ContactDTO.java
│ │ │ │ │ │ ├── ParkingPicturesDTO.java
│ │ │ │ │ │ ├── ProtocolDTO.java
│ │ │ │ │ │ ├── ProblemDTO.java
│ │ │ │ │ │ ├── ActionDTO.java
│ │ │ │ │ │ ├── CaseAttachmentDTO.java
│ │ │ │ │ │ ├── AnswerDTO.java
│ │ │ │ │ │ ├── CaseEventsDTO.java
│ │ │ │ │ │ └── CaususDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── CasusNotFoundException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ ├── Followup.java
│ │ │ │ │ │ ├── Parking.java
│ │ │ │ │ │ ├── ParkingItem.java
│ │ │ │ │ │ ├── Contact.java
│ │ │ │ │ │ ├── ParkingPictures.java
│ │ │ │ │ │ ├── Protocol.java
│ │ │ │ │ │ ├── Problem.java
│ │ │ │ │ │ ├── Action.java
│ │ │ │ │ │ ├── CaseAttachment.java
│ │ │ │ │ │ ├── Answer.java
│ │ │ │ │ │ ├── CaseEvents.java
│ │ │ │ │ │ └── Casus.java
│ │ │ │ ├── utils/
│ │ │ │ │ └── CasusMapper.java
│ │ │ ├── events/
│ │ │ │ ├── EventsController.java
│ │ │ │ ├── EventService.java
│ │ │ │ ├── EventRepository.java
│ │ │ │ ├── dtos/
│ │ │ │ │ └── EventDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── EventNotFoundException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ └── Event.java
│ │ │ │ ├── utils/
│ │ │ │ │ └── EventMapper.java
│ │ │ ├── user/
│ │ │ │ ├── UserController.java
│ │ │ │ ├── UserService.java
│ │ │ │ ├── UserRepository.java
│ │ │ │ ├── dtos/
│ │ │ │ │ └── UserDTO.java
│ │ │ │ ├── exceptions/
│ │ │ │ │ └── UserNotFoundException.java
│ │ │ │ ├── models/
│ │ │ │ │ ├── db/
│ │ │ │ │ │ └── User.java
│ │ │ │ ├── utils/
│ │ │ │ │ └── UserMapper.java
│ │ │ ├── configs/ # Configuration files
│ │ │ │ └── WebConfig.java
│ │ │ ├── filters/ # HTTP Filters
│ │ │ │ └── JWTFilter.java
│ │ │ ├── interceptors/ # HTTP Interceptors
│ │ │ │ └── LoggingInterceptor.java
│ │ │ └── Application.java
│ │ │
│ │ └── resources/
│ │ ├── application.properties # Application properties
│ │ └── application.yml # Application YAML configuration
│ │
│ └── test/
│ ├── java/
│ │ └── com/
│ │ └── sireto/
│ │ └── parkingcontrolroom/
│ │ ├── auth/
│ │ │ ├── AuthControllerTest.java
│ │ │ ├── AuthServiceTest.java
│ │ │ └── AuthRepositoryTest.java
│ │ ├── announcements/
│ │ │ ├── AnnouncementsControllerTest.java
│ │ │ ├── AnnouncementServiceTest.java
│ │ │ └── AnnouncementRepositoryTest.java
│ │ ├── casus/
│ │ │ ├── CasusControllerTest.java
│ │ │ ├── CasusServiceTest.java
│ │ │ └── CasusRepositoryTest.java
│ │ ├── events/
│ │ │ ├── EventsControllerTest.java
│ │ │ ├── EventServiceTest.java
│ │ │ └── EventRepositoryTest.java
│ │ ├── user/
│ │ │ ├── UserControllerTest.java
│ │ │ ├── UserServiceTest.java
│ │ │ └── UserRepositoryTest.java
│ │ ├── authz/
│ │ │ ├── AuthzServiceTest.java
│ │ └── ApplicationTest.java # Application tests
│ │
│ └── resources/
│ ├── application.properties # Test application properties
│ └── application-test.yml # Test YAML configuration

├── .gitignore # Git ignore file
├── build.gradle # Gradle build file
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar # Gradle wrapper JAR
│ └── gradle-wrapper.properties # Gradle wrapper properties
├── gradlew # Gradle wrapper script (Unix)
├── gradlew.bat # Gradle wrapper script (Windows)
├── .dockerignore # Files to ignore for Docker build context
├── Dockerfile # Dockerfile to build image
└── README.md # Project README