# haneen-1027/cap architecture

> Architecture diagram of the GitHub repository haneen-1027/cap, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/haneen-1027/cap
- Repository: https://github.com/haneen-1027/cap

## Overview

##### Project type and purpose
- This is a full-stack web application for managing and delivering coding and quiz assessments.
- The front end is a React single-page application (SPA).
- The back end is a .NET Core REST API with layered architecture (Controllers → Services → Data/EF Core → SQL).
- There’s also integration with an external code-execution engine (Judge0) and JWT-based authentication.

##### File structure
- Top level:
- Backend/CapApi – .NET Core solution with Controllers, Services, Models, DTOs, EF Core DbContext, appsettings.json.
- Backend/CapApi.Tests – unit tests for services.
- Database – SQL schema/script.
- Frontend/client – React app (create-react-app) with pages, components, context, API handler.
- Architectural patterns:
- Backend uses layered MVC-style pattern (API controllers delegate to service classes which use EF Core for data access).
- DTOs separate external contracts from internal models.
- Frontend uses component-based architecture organized by user roles (Admin, Company, Contributor, Landing).
- Config & deployment clues:
- appsettings.json for DB and JWT settings.
- CapApi.http for manual testing.
- qodana.yaml suggests static analysis/CI integration.

##### Extract insights from README
- (Empty in this case—so rely on file tree and naming conventions.)

##### Main components & interactions
a. Frontend SPA (React)
- Modules: LandingPage, Admin dashboard, Company dashboard, Contributor dashboard
- Context & utilities: DarkMode, API handler, time utils
- Communicates via HTTPS/REST with the Back End.
b. Back End API (.NET Core)
- Controllers (AssessmentController, AuthController, etc.)
- Services layer (Assessment services, Question services, User services, Judge0Service, JwtKeyGenerator)
- Data layer: EF Core DbContext against SQL Server (Coding_Assessment_Database.sql)
- Models & DTOs: internal entities vs. transport objects
- Authentication: JWT issuance & validation
c. Database
- SQL database with tables matching Models (User, Assessment, Question, Submission, TestCase, etc.)
d. External service
- Judge0 code execution API for running submitted code and returning test results

- React UI → AuthController (login/signup) → JwtKeyGenerator → return token → stored in client
- React UI (with token) → any secured Controller → validate JWT → pass through Services → DbContext → SQL DB
- React UI → CodeController → Judge0Service → external Judge0 API → returns execution result → React UI
- Services → Models → Data → EF Core → SQL Database

##### Architectural patterns
- Layered architecture on the back end (Controller → Service → Data).
- Dependency injection of services and DbContext in Program.cs.
- DTOs and models separate concerns.
- On the front end, role-based routing/components via React Router (implied by pages folder).

##### Additional notes
- Don’t clutter with every single React component—group them by role (Admin UI, Company UI, Contributor UI, Landing UI).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser/SPA)"
        direction TB
        ReactSPA["React SPA"]:::frontend
        subgraph "UI Modules"
            direction TB
            LandingUI["Landing Page Module"]:::frontend
            AdminUI["Admin Dashboard Module"]:::frontend
            CompanyUI["Company Dashboard Module"]:::frontend
            ContributorUI["Contributor Dashboard Module"]:::frontend
        end
        subgraph "Utilities & Context"
            direction TB
            APIHandler["API Handler"]:::frontend
            DarkModeCtx["Dark Mode Context"]:::frontend
            TimeUtil["Time Utility"]:::frontend
        end
    end

    %% Server Layer
    subgraph "Server (.NET Core API)"
        direction TB
        subgraph "Controllers" 
            direction TB
            AuthController["AuthController"]:::controllers
            AssessmentController["AssessmentController"]:::controllers
            CodeController["CodeController"]:::controllers
            QuestionController["QuestionController"]:::controllers
            SubmissionsController["SubmissionsController"]:::controllers
            UserController["UserController"]:::controllers
        end

        subgraph "Services"
            direction TB
            AssessmentSvc["Assessment Services"]:::services
            QuestionSvc["Question Services"]:::services
            UserSvc["User Services"]:::services
            Judge0Svc["Judge0 Integration Service"]:::services
            JwtKeyGen["JWT Key Generator Service"]:::services
        end

        subgraph "Data Access"
            direction TB
            DbContext["EF Core DbContext"]:::data
        end

        subgraph "Models & DTOs"
            direction TB
            DomainModels["Domain Models"]:::models
            DTOs["Data Transfer Objects"]:::models
        end

        subgraph "Configuration"
            direction TB
            ProgramCS["Program.cs"]:::config
            AppSettings["appsettings.json"]:::config
            LaunchSettings["launchSettings.json"]:::config
            HTTPTest["CapApi.http"]:::config
        end
    end

    %% External Dependencies
    SQLDB["SQL Database"]:::db
    Judge0Ext["Judge0 Code Execution API"]:::external

    %% Flows
    ReactSPA -->|"HTTPS/REST login/signup"| AuthController
    AuthController -->|calls JwtKeyGenerator| JwtKeyGen
    JwtKeyGen -->|returns JWT token| AuthController
    AuthController -->|returns token| ReactSPA

    ReactSPA -->|"HTTPS/REST with Bearer JWT"| AssessmentController
    ReactSPA -->|"HTTPS/REST with Bearer JWT"| QuestionController
    ReactSPA -->|"HTTPS/REST with Bearer JWT"| SubmissionsController
    ReactSPA -->|"HTTPS/REST with Bearer JWT"| UserController

    AssessmentController -->|uses| AssessmentSvc
    QuestionController -->|uses| QuestionSvc
    UserController -->|uses| UserSvc
    SubmissionsController -->|uses| AssessmentSvc
    SubmissionsController -->|uses| QuestionSvc

    AssessmentSvc -->|uses| DbContext
    QuestionSvc -->|uses| DbContext
    UserSvc -->|uses| DbContext
    JwtKeyGen -->|uses| DbContext

    DbContext -->|EF Core queries| SQLDB
    DTOs -->|map data| Controllers
    DomainModels -->|map data| Services

    ReactSPA -->|"Submit code"| CodeController
    CodeController -->|uses| Judge0Svc
    Judge0Svc -->|calls| Judge0Ext
    Judge0Ext -->|returns result| Judge0Svc
    Judge0Svc -->|returns execution result| CodeController
    CodeController -->|returns result| ReactSPA

    %% Click Events
    click ReactSPA "https://github.com/haneen-1027/cap/tree/main/Frontend/client"
    click LandingUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/pages/LandingPage/LandingPage.jsx"
    click AdminUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/pages/Admin/Admin.jsx"
    click AdminUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/components/AdminComponents/AdmDashboard.jsx"
    click CompanyUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/pages/Company/Company.jsx"
    click CompanyUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/components/CompanyComponents/CompDashboard.jsx"
    click ContributorUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/pages/Contributer/Contributer.jsx"
    click ContributorUI "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/components/ContributerComponents/ContDashboard.jsx"
    click APIHandler "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/APIs/ApisHandaler.jsx"
    click DarkModeCtx "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/Context/DarkMode.js"
    click TimeUtil "https://github.com/haneen-1027/cap/blob/main/Frontend/client/src/Utils/CalculateTimeInMinutes.js"
    click AuthController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/AuthController.cs"
    click AssessmentController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/AssessmentController.cs"
    click CodeController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/CodeController.cs"
    click QuestionController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/QuestionController.cs"
    click SubmissionsController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/SubmissionsController.cs"
    click UserController "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Controllers/UserController.cs"
    click AssessmentSvc "https://github.com/haneen-1027/cap/tree/main/Backend/CapApi/Services/Assessment"
    click QuestionSvc "https://github.com/haneen-1027/cap/tree/main/Backend/CapApi/Services/Question"
    click UserSvc "https://github.com/haneen-1027/cap/tree/main/Backend/CapApi/Services/User"
    click Judge0Svc "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Services/Judge0/Judge0Service.cs"
    click JwtKeyGen "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Services/Jwt/JwtKeyGenerator.cs"
    click DbContext "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Data/CapDbContext.cs"
    click DomainModels "https://github.com/haneen-1027/cap/tree/main/Backend/CapApi/Models"
    click DTOs "https://github.com/haneen-1027/cap/tree/main/Backend/CapApi/Dtos"
    click ProgramCS "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Program.cs"
    click AppSettings "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/appsettings.json"
    click LaunchSettings "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/Properties/launchSettings.json"
    click HTTPTest "https://github.com/haneen-1027/cap/blob/main/Backend/CapApi/CapApi.http"
    click SQLDB "https://github.com/haneen-1027/cap/blob/main/Database/Coding_Assessment_Database.sql"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef controllers fill:#90EE90,stroke:#333,stroke-width:1px
    classDef services fill:#FFA500,stroke:#333,stroke-width:1px
    classDef data fill:#F0E68C,stroke:#333,stroke-width:1px
    classDef models fill:#FFE4B5,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef db fill:#FFD700,stroke:#333,stroke-width:1px
    classDef external fill:#E6E6FA,stroke:#333,stroke-width:1px
```
